3. Contains a group of classes, organized together under a single namespace. Ex – java.util, java.sql Essentially folder to store source and compiled classes – library / compilation unit How can you use Classes in other packages? Using fully qualified class name public class FullQualification { public static void main(String[] args) { java.util.ArrayListlist = new java.util.ArrayList(); } } Package
4. Use import keyword to use one class in a different package import java.util.ArrayList; public class SingleImport { public static void main(String[] args) { ArrayListlist = new java.util.ArrayList(); } } If you want all the classes in java.util then Import java.util.*; Import
5. Use a package statement, it must appear as the first non-comment in the file. package com.training.java You creating a new compilation unit or library In order to use the classes in this package you either use fully qualified class name or import statements Custom package
6. package com.training.java; public class MyClass { // ... } public class QualifiedMyClass { public static void main(String[] args) { com.training.java.MyClassm = new com.training.java.MyClass(); } } import com.training.java.MyClass; public class ImportedMyClass { public static void main(String[] args) { MyClassm = new MyClass(); } } Import in Action