Packages in Java

In this article, let us learn about packages in Java.

A package is nothing but a directory holding classes, interfaces and enums. All classes must be declared inside some package. If you do not specify the name of package, default package is used.

 

Packages in Java

Standard packages and classes in Java library

In below example, class Packages is inside oops package. Fully qualified name of the class is oops.Packages

//This class is in the package called as ooops
package oops;

//below statement will import all classes in java.io package
import java.io.*;

//below statement will import only BigInteger class in java.math package
import java.math.BigInteger;

public class Packages {

    public static void main(String [] args){
        BigInteger b = new BigInteger("8273892379");
        System.out.println("BigInteger -> " + b.toString());

        System.out.println("File separator -> " + File.pathSeparator);
    }
}

Here is the output of above code –
BigInteger -> 8273892379
File separator -> ;

You may also like...