Custom Search

Java: Package

A package is a collection of related classes.

It organizes your classes into a folder structure and makes it easy to locate and use them.

It is very useful as it helps improve re-usability of code.

Syntax:

package <package_name>;

-------------------------------------------

  • To avoid naming conflicts packages are given names of the domain name of the company in reverse Ex : com.guru99. com.microsoft, com.infosys etc.
  • When a package name is not specified , a class is into the default package (the current working directory) and the package itself is given no name. Hence you were able to execute assignments earlier.
  • While creating a package, care should be taken that the statement for creating package must be written before any other import statements

java.lang package

The java.lang package is imported by default for any class that you create in Java.

The java API is very extensive , contains classes which can perform almost all your programming tasks right from Data Structure Manipulation til Networking. More often than not, you will be using API files in your code.