0% found this document useful (0 votes)
3 views15 pages

7using library class

The document provides an overview of Java library classes, including their functions and input/output operations. It discusses exception handling using try-catch-finally constructs and introduces wrapper classes for primitive data types. Additionally, it explains the concept of packages in Java, including user-defined packages and their usage with import statements.

Uploaded by

Kuntal Ware
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views15 pages

7using library class

The document provides an overview of Java library classes, including their functions and input/output operations. It discusses exception handling using try-catch-finally constructs and introduces wrapper classes for primitive data types. Additionally, it explains the concept of packages in Java, including user-defined packages and their usage with import statements.

Uploaded by

Kuntal Ware
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Using

Library
Classes
Introduction
• A class created by user is known as User defined class.

• But, there are some classes available with Java System, which
provide an effective support to the programmers in developing
their logic. These classes are called as Library Classes.

• There are various library classes in Java and each class includes
various functions.
Some Library Classes

• Java.io : Contains input/output functions.

• Java.lang : Contains character/string functions.

• Java.math : To perform various mathematical calculations.

• Java.net : To provide communication in network.


Input/output Operations
• Java uses the functions read() to accept a character from the keyboard
and print() or println() to display the result on the screen.

• To input a character the function can be written as :

a = System.in.read();

Here,
System.in is an input stream belonging to the System class which in turn
is an object of input stream class available in java.io package.
• To print the result the print function can be written as :

System.out.print(a);
or

System.out.println(a);

Here, System. out() is an output stream belonging to the System class which
in turn is an object of print stream class available in java.io package.
Stream
• A stream is a group of data (characters/byte).

• Types :

 Character related Stream

 Byte related Stream


Types Of Streams
1) System. in

2) System. out

3) System.err

• System. in is an input stream relate with keyboard.

• System. out and System.err are output streams related with monitor/screen.

• All these streams are available in a separate package called java.io


Exception Handling In Java
• Sometimes, in Java programming, we come across such a
situation that it is difficult to say that our code has been
developed properly and is error free.

• Such unexpected situation may appear due to improper use


of input resources.

• These situation are termed as Exception and to overcome


such situation is known as Exception Handling.
Try-catch-finally-throws
• Try and catch keywords play an important role in exception
handling.

• Try keyword contains a block of statements to perform.

• Any exception occurring within try block is trapped. Hence, it is an


error trapper.

• Further a report is to be passed to the exception handler about the


error, which can be done by catch block.

• The finally block contains the statements which are executed any
way.
Syntax
try
{
set of statements
}
catch (exception e) {}
finally
{
statement to execute anyway
}

DEMO
Wrapper Classes
• These classes provide the facilities to contain primitive data
values in terms of objects.

• A wrapper class is a member of java.lang package.

• Inputs which is passed from keyboard, is accepted as a


character/string.

• Further, this form of data is needed to be converted to a


primitive type in order to perform any arithmetical
calculation.
Wrapper Classes Data types

 Character char

 Byte byte

 Short short

 Integer int

 Long long

 Float float

 Double double
Packages In Java
• A package is a group of classes, which can be imported to a
program so that user may exercise the implicit facility available in it.

• A package in Java program is included by using import statement.

• E.g.
import java.io.*; => It allows all the classes of this package to be
included.

import java.util.*; => It allows all the classes of this package to be


included.
User defined Packages
• Till now, we have seen built-in packages.

• A package may be defined by the users in various logic program. These


are known as user defined packages.

• A package in Java program is included by using import statement.

• E.g.
import java.io.*; => It allows all the classes of this package to be included.

import java.util.*; => It allows all the classes of this package to be


included.
Example
Package area;
class rectangle
{

}
class square
{

}
class circle
{

You might also like