Package and Built-in Package in Java | Syntax of Package | How to Create a New Package in Java.

Package and Built-in Package in Java | Syntax of Package
Package in Java 

Package

Package in java defines the name space in which the classes are stored. In Java a directory is created an its name in package name. If we omit the package then the default classes are put in the package that has no name.

The Syntax for declaring the package is package name_of_package.


For Example:-  In the program, If you declare a package as package My_package; then we must create the directory name My_package in the current working directory and the required classes must be stored in that directory.


Note:- The name of the Package and the name of the directory must be the same.This name is case sensitive.


Built-in Package are:-
  1. java.io
  2. java.lang
  3. java.awt
  4. java.net
  5. java.util
  6. java.applet

How to Create a Package in Eclipse is shown below:-


Step 1:- Open Eclipse

↳ If you Don't have a project then create a new project.
↳ Then Click on that project.


Step 2:- Java Resources 

↳ Go to Resources and Click on SRC.
↳ If you didn't create package in src then it will create in defaults package.


Step 3:- Create package.

↳ Right Click on src then New↠Package.



Step 4:- Package Name.

↳ Write a package name whichever you want to write.



Post a Comment

0 Comments