Packages in Java2 min read

packages in Java

What is Package?

We can say a group of classes and interfaces in a single unit is a package. we use ‘import’ keyword to use them as it is ‘#include’ in c/c++.

Packages are of two types:-

  1. Predefined
  2. User-defined

PREDEFINED                                                                   

a) import java.lang.*;

It is a primary package used for implementing basic operation for developing java application.It is also known as default package Eg: String ,System ,Integer ,Double ,Boolean ,Thread ,etc.

b) import java.io.*;                //For File handling

It is input and output package.It is used for implementing input and output operation from harddisk ,console,etc
Eg: File ,Fileinputstream ,FIleInputStream ,FIleoutputStream ,BufferReader ,BufferWriter ,IOException ,etc.

c)import java.util.*;                 //For Collector

It is a utility package . It is used to utilise the memory ,system resources and other things. Eg: Scanner ,Callender ,Date ,Set ,List ,Stack ,Queue ,ArrayList ,LinkedList ,HashSet.

d) import java.awt.;                 //For Graphics


It is abstract window toolkit package.It is used for making a GUI(Graphical User Interface).
Eg: Frame, Panel ,Label ,Button ,TextField ,TextArea ,Menu ,MenuBar ,Color ,Font ,etc

e) import javax.swing.*             //For Graphics

Swing package has been implemented in java from JDK 5 . It is used for making GUI(Graphical User Interface) same as awt packages but this package is advance as compared to awt package due to:-

  • Swing package contains some extra controls as compared to awt package.
  • Swing package controls are light weighted controls as compared to awt package.
  • Swing package controls are fast processing.

Eg: JFrame ,JPanel ,JLabel ,JButton ,JTextField ,JTextArea ,JMenu ,JMenuBar ,JComboBox ,JCheckBox ,JRadioiButton ,Imagination ,etc.

f) import java.awt.event.* //For Event And Listeners

This package is used for implementing event and listeners on the GUI controls.
Eg: ActionEvent ,WindowEvent ,KeyEvent ,ActionListener ,WindowListener ,KeyListener ,etc

g) import java.sql.*;                      //For JDBC

It is an SQL package. It is used to implement JDBC(Java DataBase Connectivity). This package is used to connect java application with any DBMS such as ORACLE, MYSQL, MySQL server, MS ACCESSSQLITE, etc.
Eg: Connection ,DriverManager ,Satement ,PreparedStatement ,ResultSet ,SQLException ,etc.

USER DEFINED                                            

You can make your own package by using package keyword

And to use above package (import package_name)

Eg:

package mypack;  

public class Simple{  

 public static void main(String args[]){  

    System.out.println("Welcome to package");  

   }  } 
Bookmark(0)
Tags:

Add a Comment

Your email address will not be published. Required fields are marked *