Packages in java


In this tutorial, you will learn about Packages in java.

What is packages in Java and steps for creating a package:

Package: It allows to contains a collection of works same as a header file. java offers the facility to use various predefined package and it also specifies a user-defined package.

Package work as a container or directory in which we can store various class.package can be accessed by using import keyword where package must be import starting of the program or before the class java system defined package store in java and java directory.if we want to access these package and its functions must be specified package name with a directory.

Some important system defined package in Java are:

  • Io(input-output)=datainput stream,exception handling,file handling,etc.-java.
  • Util(utility)=scanner,vector.etc.- java
  • Lang(language)=math,threat,system.out,etc.- java
  • Applet(applet class)=in it,graphics,point,etc.- java
  • Swing=jbutton,Jlabel-javax
  • Awt(abstract windowing toolkit)=Button,text field,etc-java
  • Sqt(structured querry language)=connection,recand set,etc-javax

How to create a package in java:

Step 1:  In Java, language package creates by using package keyword where package keyword starting of the program.

Syntax: package <package name>;

Eg:-package mypack;

Step 2: Package: It specifies one or more class without using the main function where one class of public type must be created.

Step 3: Package file must be saved with a public class name.

Step 4: If you want to access java package use import keyword.

Comment below if you have queries related to the above topic, Packages in java.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.