In this topic, you will learn about, Package In Java.
Package: it allows to contains a collection of class. it works the same as a header file. java offers a 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 declaration.in java system defined package store in java and javax directory.if we want to access these package and its functions must be specified package name with the directory.
Some important system defined package are:
- Io (input-output)= data input 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 Package in Java:
- In java language package create by using package keyword where package keyword starting of the program.
Syntax: package <package name>;
- Package: it specifies one or more class-class without using the main function where one class of public type must be created.
- Package file must be saved with a public class name.
Example Of Package in Java:
Public class A
Public void show()
System.out.print(’’ class A’’);
Public void show ()
System.out.print(’’class B ’’);
iv> If you want to access java package use import keyword.
Eg :- java
Import java .mypack.*;
Public static void main(string arg)
A obj 1.new A();
B.obj 2 =new B();
Obj 2=new show ();
Comment below if you have queries related to the above topic, Package In Java.