Package Part 1
-
Upload
pabburahati -
Category
Documents
-
view
216 -
download
0
Transcript of Package Part 1
-
7/30/2019 Package Part 1
1/23
Programming Language(JAVA)
Unit 6.9 In-built Packages
Presentation1
-
7/30/2019 Package Part 1
2/23
Revision
1. Define Inheritance.
2. List the types of Inheritance allowed in
java.
3. Explain method overriding.
-
7/30/2019 Package Part 1
3/23
Objectives
At the end of this presentation, you will be ableto
Define package and its types
List the advantages of packages
List some of the in-built packages in Java
-
7/30/2019 Package Part 1
4/23
Reusability of Classes
Java allows reusability of classes.
Classes created for one program can be
reused for another.
It saves the development time.
It is possible to use classes across
packages even if the classes share thesame name.
You will be able to distinguish the classeswith the help of the package name
-
7/30/2019 Package Part 1
5/23
Packages
Is a collection of classes that can be shared
by Java programs.
Are classified into
in-built packages
user-defined packages.
-
7/30/2019 Package Part 1
6/23
Packages
In-built packages User defined packages
Packages
-
7/30/2019 Package Part 1
7/23
Packages
In-built packages - system packages.
User-defined packages - Created by the
users for their requirements.
-
7/30/2019 Package Part 1
8/23
Advantages - Packages
Allows reusability across programs.
Allow classes to organize into units.
Used to identify the classes.
Same class name can be used in different
packages.
-
7/30/2019 Package Part 1
9/23
Java Packages
The classes are grouped together based on
their functionality.
Some of the important packages of Java are: lang
util
Io
awt net
applet.
-
7/30/2019 Package Part 1
10/23
Important Java Packages
-
7/30/2019 Package Part 1
11/23
Important Java Packages - Description
PackageName
Description
lang Provides language support classes.
util Provides language utility classessuch as vectors, hash tables random
numbers and date.
io Provides input and output supportclasses.
Cont
-
7/30/2019 Package Part 1
12/23
Important Java Packages - Description
PackageName
Description
awt Provides set of classes such asbuttons, lists, menus, windows forimplementing graphical interface
net Provides classes for networking.Enables communication between thelocal computers and internet servers
applet Provides classes for creating andimplementing applets
-
7/30/2019 Package Part 1
13/23
Classes Within Packages
A file name in java has the same name as the
class in which main method is defined.
All the files for the classes within a packagehave to be saved in a directory with the same
name as that of the package.
-
7/30/2019 Package Part 1
14/23
Structure of io Package
Package
Class
-
7/30/2019 Package Part 1
15/23
The importStatement
To access the classes from a package, the
importstatement is used.
There are two ways to import packages.
Import all the classes of the package using *.
Import single class using the class name.
-
7/30/2019 Package Part 1
16/23
Importing all classes
To import all the classes of a package * is
used.Example
import java.io.*;
Syntaximport java.packagename.*;
-
7/30/2019 Package Part 1
17/23
Importing specific class
To import a specific class, the class name
Example
import java.io.BufferedReader;
Syntax
import java.packagename.classname;
-
7/30/2019 Package Part 1
18/23
Hands-On!
ProgramInputSample.java accepts inputusing input stream.
-
7/30/2019 Package Part 1
19/23
Activity 6.9.1
Step 1: OpenInputSample1.java from Student data
file.
Step 2: Type import java.io.*; in Code line 1.
Step 3: Save and Compile the program.
Step 4: Run and observe the output.
-
7/30/2019 Package Part 1
20/23
Summary
In this presentation, you learnt the following
Package is a collection of classes that can
be shared by Java programs.
Packages provides reusability, they allowclasses to be organized into units. They are
used to identify the classes. Packages enable classes to have same
name across them.
-
7/30/2019 Package Part 1
21/23
Summary
In this presentation, you also learnt the following
The classes are grouped together based on their
functionality.
Some of the important java packages are lang,
util, io, awt, net and applet. importstatement is used to access the classes
from the packages.
-
7/30/2019 Package Part 1
22/23
Assignment
1. List the advantages of package.
2. What are the two types of packages?
3. List some of the in-built java packages.
-
7/30/2019 Package Part 1
23/23
Lab Exercise
1. Write a program to accept a string by
importing the io package.