+91 81900 98289

Java Packages

A package is a folder path for classes, written with dots: com.asmorix.batch. The first line of the file is package com.asmorix.batch; and the file must live in the matching folders.

import lets you use a class by its short name. Classes in the same package can see each other without an import. java.lang, which contains String and System, is imported for you.

Example

ArrayList is in java.util. add stores one name, and get(0) reads it back.

import java.util.ArrayList; public class Pack { public static void main(String[] args) { ArrayList<String> names = new ArrayList<>(); names.add("Meera"); System.out.println(names.get(0)); } }
Without the import you would write java.util.ArrayList every time. The import does not copy code into your file. It only shortens the name.