Opening Hours :7AM to 9PM
Package is a container which is collection of classes, interfaces and sub packages, subpackage is collection of classes , interfaces and sub packages. The main advantage with package is common reusability that means the predefined properties of classes and interfaces of package can be used in any java program without rewriting of code. In java language packages are classified into two types.
1.Predefined packages.
2.User defined packages.
These are the packages already designed by sun micro system and supplied as a part of java API and these properties commonly used by every java developer in the world. As per as core java is consent following are mostly used predefined packages.
Which is collection of predefined classes and interfaces used to handle various operations like multi threading , exception handling ,converting string values into primitive data types, string handling etc…
import java.lang.className/interfaceName;Used to import a specific property of a package.
import java.lang.*;
In the above syntax import is a keyword used to import the predefined properties of java API into current java program. Java is a main package and lang is a sub package.
Which is a collection of predefined classes and interfaces used to design a GUI applications (graphical user interface).
import java.awt.*;
Which is collection of predefined classes and interfaces used to handle the event(performing action)in GUI application.
import java.awt.event.*;
Which is collection of predefined classes and interfaces used to perform various operations on file like writing into a file reading data from the file etc…
Import java.io.*;
Which is collection of predefined classes and interfaces used to develop basic networking based applications like LAN based application and client server applications.
import java.net.*;
Which contains only one predefined class used to develop distributed applications at core java level.
Which is collection of predefined classes and interfaces used to perform various operations like Handling of data structure. Handling of date and calendar classes. Etc..
import java.util.*;
Which is collection of predefined classes and interfaces used to perform various conversions like data conversion ,currency conversation etc...
import java.text.*;Note:
Click here to show all predefined package(Platform, Standard Edition 7) Click here to show all predefined package(Platform, Standard Edition 8) Click here to show all predefined package(Platform, Standard Edition 11)
If any package is designed by the user(developher) and if it is used by one or more specific java developers known as user defined package.
While developing real time application it is highly recommended to keep all the programs in a package structure.
In java language user defined packages can be created with the help of package keyword.
package pack1.pack2....;In the above syntax pack1 is the main package , pack2,.. are the sub packages.
package packagename;In ecllipse:
Right click on src new packageNote: Package statement should exist as first statement of package program.
javac -d . programname.javaNote: In ecllipse 6th step is optional
package pack1.pack2,...; public class ClassName { //methods and fields } class ClassName { //methods and fields }Note: Package program can be compile con’t be executed because of no main method.
package sateesh; public class Rain { public void myRain() { System.out.println("Welcome Rain"); } }
import sateesh.Rain; public class Main { public static void main(String args[]) { Rain v=new Rain(); v.myRain(); } }