0% found this document useful (0 votes)
4 views

java packages3

The document provides an overview of Java packages, defining them as groups of similar classes, interfaces, and enumerations. It discusses user-defined packages created by programmers and built-in packages provided by the Java API, highlighting their advantages such as data encapsulation, controlled access, and avoidance of naming conflicts. Additionally, it includes examples of package usage and the importance of packages in writing maintainable code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

java packages3

The document provides an overview of Java packages, defining them as groups of similar classes, interfaces, and enumerations. It discusses user-defined packages created by programmers and built-in packages provided by the Java API, highlighting their advantages such as data encapsulation, controlled access, and avoidance of naming conflicts. Additionally, it includes examples of package usage and the importance of packages in writing maintainable code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

PACKAGES OF

JAVA
CONTENTS
 Introduction
 Types Of Packages

User defined package


System packages of java API
(pre-defined / in-built
packages)

 Advantages Of Packages
Introduction
Define :
A package can be defined as a group of
similar types of classes, sub-classes,
interfaces or enumerations, etc.

Why we need ?
Packages in java are used to avoid naming
conflict and to control the access of class,
interface, sub-classes, etc.

To write a better maintainable code.


Overview of
Think of packages as a folder in a file directory.

Package_name class_name

sub_packagename
java,lang,awt,javax
Two categories of
Built-in Packages
(packages from java Examples:
,
java,lang,java.util,java.

packages: the Java API) sql, etc..


Java
packages
User-defined
Examples:
Packages (create
University.Department.S
your own
taff
packages)
User-defined Packages
(create your own
packages)
User-defined Packages
The package which are created by java
programmer or user for their on use are called
User-Defined package.

This packages developed by users in order to


group related classes,interfaces and sub
packages.

It can be imported into other classes and used


the same as we use built-in packages.

SYNTAX:- Package package_name


a) Package statement must be first line of the program.

RULES:-
b) The way of compilation of these classes
would be different.
EX:- javac -d . classname.java
Example to create
packages:
Member accessibility:
within outside package outside
within class
package by sub.class package

private

default

protecte
d
public
Built-in / Pre-Defined
Packages
(packages from the Java
API)
Built-in Packages / Pre-Defined
The package which are already created
by java developer people are called pre-
defined packages.
Few built-in packages are below: This package mainly use to
develop GUI related
application.
IO stands for input/output Applet programs are web
this package is very useful EX: Linkedlist, Stack, related program created act
Ex: System, String, to perform i/o operations server but executed at client
vector, Hashset,
Object, Integer, etc.. on file. machine.
Treeset, etc..

java.lang java.io java.util java.applet


It’s the default package also
known as heart of the java bcz This package is used to
without using this package we implement data structure of
can’t write even a single EX: File, File writer, EX: Applet
java.
program. File reader etc…
It contain utility classes
also known as collection
frame work.
The built-in packages are again categorized into extension packages.
These extension packages start with javax.
This is for all the Java languages, which have lightweight component
classes.

Examples
javax.swing javax.servlet javax.sql etc......

Note: The default package imported with no declaration is java.lang


package.

Link of packages : All Packages (Java SE 13 & JDK 13 ) (oracle.com)


Example how to import
subpackages:
Execution
import java.util.Scanner; // import the Scanner :
class
Enter username:
class Main {
public static void main(String[] args) { xyz
Scanner myObj = new
Scanner(System.in); Username is: xyz
String userName;

// Enter username and press Enter


System.out.println("Enter username");
userName = myObj.nextLine();

System.out.println("Username is: " +


userName);
}
}
Advantages of Packages:

Implement Data Encapsulation

Uniquely Compare Classes

Provide Controlled Access

Avoid Naming Conflicts

Resuse Classes

Easy Search
THANK
S!

You might also like