Page 454 - Cs_withBlue_J_C11_Flipbook
P. 454
• Better organisation: A java package contains the similar type of classes grouped together. It helps in organising any
project and quickly locating it when needed. It thus reduces complexity.
• No naming collision: Two classes having the same name under different packages can be defined. It eliminates
naming conflicts.
• Access protection: Some classes under a package can be accessed directly, while other classes are kept for internal
computation and are inaccessible.
15.1.2 Types of Packages
Packages in Java are classified into two types:
• Built-in packages: The already defined package in Java software like java.io, java.lang, etc., are known as built-in
packages.
• User-defined packages: The user-defined packages in Java are the packages that are created by the programmer.
Whenever we want to add a class to the package, we have to write <package class name> at the top of the program.
Built-in Packages
The Java Development Kit (JDK) is a software development environment that is used to develop Java applications and
applets. JDK has API (Application Programming Interface) that contains various built-in packages which are listed below.
Packages Description
java.lang Contains fundamental classes and interfaces of Java like String, StringBuffer, System, Math, etc.
java.util Contains utility classes like ArrayList, Scanner, Calendar, Date, StringTokenizer, etc.
java.net Provides classes for implementing networking applications like Authenticator, HTTP Cookie, etc.
java.applet Contains classes to handle applets. Applets are the special programs that run on a web browser.
java.io Contains classes that perform input/output operations like BufferedReader, BufferedWriter, File,
InputStream, PrintStream, etc.
java.awt Contains classes for implementing user interfaces, graphics or images like Button, Color, Event,
Font, Graphics, Image, etc.
java.sql Contains classes for accessing and processing a database like Connection, DriverManager,
Statement, etc.
User-defined Packages
User-defined packages are those packages that are developed by the programmer as per the requirement of the software.
They have similar properties as built-in packages in Java like they can be imported into other classes.
15.2 CREATION OF USER-DEFINED PACKAGES IN BLUEJ
To create a user-defined package in BlueJ, the given steps are to be followed:
Step 1: Choose the Edit option on the BlueJ window and from the drop-down list, click on New Package.
452452 Touchpad Computer Science-XI

