Você está na página 1de 23

Programming Language(JAVA)

Unit 6.9 In-built Packages

Presentation 1

Revision

1. Define Inheritance.
2. List the types of Inheritance allowed in java.

3. Explain method overriding.

Objectives

At the end of this presentation, you will be able to Define package and its types List the advantages of packages

List some of the in-built packages in Java

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 the same name. You will be able to distinguish the classes with the help of the package name

Packages
Is a collection of classes that can be shared by Java programs.
Are classified into

in-built packages
user-defined packages.

Packages

Packages

In-built packages

User defined packages

Packages
In-built packages - system packages.
User-defined packages - Created by the

users for their requirements.

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.

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.

Important Java Packages

Important Java Packages - Description


Package Description Name lang Provides language support classes. util Provides language utility classes such as vectors, hash tables random numbers and date. Provides input and output support classes.

io

Cont

Important Java Packages - Description


Package Description Name Provides set of classes such as awt buttons, lists, menus, windows for implementing graphical interface Provides classes for networking. net Enables communication between the local computers and internet servers Provides classes for creating and applet implementing applets

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 package have to be saved in a directory with the same name as that of the package.

Structure of io Package
Package Class

The import Statement


To access the classes from a package, the

import statement is used.


There are two ways to import packages.

Import all the classes of the package using *. Import single class using the class name.

Importing all classes


To import all the classes of a package * is used.
Example

import java.io.*;
Syntax

import java.packagename.*;

Importing specific class


To import a specific class, the class name
Example

import java.io.BufferedReader;
Syntax

import java.packagename.classname;

Hands-On!
Program InputSample.java accepts input using input stream.

Activity 6.9.1
Step 1: Open InputSample1.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.

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 allow classes to be organized into units. They are used to identify the classes. Packages enable classes to have same name across them.

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.

import statement is used to access the classes


from the packages.

Assignment

1. List the advantages of package.


2. What are the two types of packages? 3. List some of the in-built java packages.

Lab Exercise
1. Write a program to accept a string by importing the io package.

Você também pode gostar