Java Packages
Organize types and make dependencies clear.
முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.
இந்தப் பாடத்தில்…
- Explain the key idea behind Packages.
- Read and run a complete example, then predict what changes.
- Recognize the topic-specific mistake discussed below.
அடிப்படையைப் புரிந்துகொள்ளுங்கள்
A package is a namespace for related Java types. An import lets you use a type name without spelling its fully qualified name each time; it does not install a library. Multi-file package layouts are easiest to practice locally. The single-file browser example below demonstrates importing a standard-library class.
விரிவான விளக்கங்கள்
Java Packages என்னன்னு தெரியுமா?
Package என்பது related classes-ஐ group பண்றதுக்குள்ள folder மாதிரி. Name conflicts avoid பண்றதுக்கும், code-ஐ maintain பண்றதுக்கும் help ஆகும்.
Java இரண்டு வகை packages வையுங்கள்க்கும்:
- Built-in packages — Java API-ல இருக்கு
- User-defined packages — நாமே create பண்றது
Package Import பண்றது
import keyword use பண்ணி package-ஐ use பண்ணலாம்:
Common Built-in Java Packages
| Package | What it provides | Example classes |
|---|---|---|
java.lang | Core Java classes — imported automatically | String, Math, System, Integer |
java.util | Data structures, date/time, random numbers | ArrayList, HashMap, Scanner |
java.io | Reading and writing files / streams | File, FileWriter, BufferedReader |
java.nio.file | Modern file & path API (Java 7+) | Files, Path, Paths |
java.net | Networking — URLs, sockets, HTTP | URL, HttpURLConnection |
java.sql | Database connectivity (JDBC) | Connection, Statement, ResultSet |
// Step 1: Declare the package at TOP of file
package com.myapp.utils;
// Step 2: Define your class
public class StringHelper {
public static String shout(String s) {
return s.toUpperCase() + "!";
}
}
// Step 3: Use it elsewhere
import com.myapp.utils.StringHelper;
System.out.println(StringHelper.shout("hello")); // HELLO!Java-வில் package ஏன் பயன்படுத்துவோம்?
- Program fast-ஆக run ஆக
- Related classes-ஐ organize செய்ய மற்றும் name conflicts avoid செய்ய
- Memory save செய்ய
- Loops faster-ஆக run ஆக
Reveal answer / விடை
Related classes-ஐ organize செய்ய மற்றும் name conflicts avoid செய்ய
Packages related classes-ஐ organize செய்யும், name conflicts avoid செய்யும். `com.company.project.service` போன்ற naming convention follow செய்வது professional Java development-ன் standard.
முழுமையான உதாரணம்
This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws Exception {
ArrayList<String> topics = new ArrayList<>();
topics.add("Packages");
System.out.println(topics.get(0));
}
}Predict first. Then reveal the expected output / வெளியீடு
Packages
The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.
Change it. Run it. Understand it.
Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.
Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.
நீங்களே முயற்சி செய்யுங்கள்
Practice challenge
Remove the import and replace ArrayList with java.util.ArrayList everywhere in the example.
Reveal the answer and reasoning / விடை
The fully qualified name works without an import. For a local package demo, put package lessons; at the top of Main.java, compile with javac -d . Main.java, and run java lessons.Main.
தவிர்க்க வேண்டிய தவறு: An import is not a dependency download. A third-party library must already be available to the compiler and runtime.
பாடத்தின் சுருக்கம்
- Explain the example without reading the output first.
- Make the change requested in the practice task.
- Describe why the result changed—or why compilation failed.
Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.