Home / JAVA / library classes and library functions in Java

library classes and library functions in Java

What are library classes and library functions in Java

Library Classes:- These are the predefined classes provided by Java system present in packages. These classes contain related library functions like String Math, etc. All the library classes belong to some package.

Library Functions:- These are the inbuilt functions present in Java library classes, provided by Java system to help programmers to perform their task in an easier way.

Library Classes are to be included in java program using a package.

Package:-Packages are collection of classes or subclasses. We have different packages defined to import or include the classes required in the Java program.

Also See:   What is Java and why is java needed?

The different packages are:

1. io package:- It includes all the classes related to input/output.

2. lang package:- It include all the statements and functions common to all program.For eg we have,System.out.println ,main function etc used in all the program.Also lang package is the default package which is by default imported in all the java program.But we can also include this package explicitly.

3. util package:- It includes all the utility classes.For eg like date and time.

4. awt package:- It includes all the classes related to graphical design.

5. sql package:- It includes classes of the database connectivity.

6. applet package:- It includes all the classes related to Internet programming.

Also See:   Java Program to find Anagrams Words

7. net package:- It includes all the classes related to networking.

Import Statement:-

This statement is used to add or include the classes related to the package. Import statement should be the first statement of the program.

How to import a package:

Import java.lang.*;
Import java.io.*;

Program to take the input from the user to print the Name and Age of the Employee.

We use BufferedReader class which is in io package to take the input and read it and print the output on the screen.

import java.io.*;  // package imported for input output classes
class Employee
public static void main(String args[])throws IOException  // *
InputStreamReader ir=new InputStreamReader(System.in);  // function to take input from user.
BufferedReader br=new BufferedReader(ir); // class to read user input.
String name;
int age;
System.out.println("Enter the Name");
name=br.readLine();  // function defined in buffered class to take input from user as a string
System.out.println("Enter the Age");
age=Integer.parseInt(br.readLine());  // converting default string input to integer
System.out.println("Name is " + name);
System.out.println("Age is "+ age); 

*Exception occurred when we import the io package .So we use throws Exception to deal with the exception.So that it will not create error in executing the program.

Also See:   Java program to print happy numbers for a given range

Incoming terms: library classes and library functions

Check Also

Java program to implement polymorphism

Java program to implement polymorphism: Polymorphism is a technique in java with which you can ...

Leave a Reply

Your email address will not be published. Required fields are marked *