Library Classes NOTES
Library Classes NOTES
Library Classes NOTES
Library Classes
Java Development Kit (JDK) includes all types of software tools which are essentially
needed while writing programs.
The major component of JDK is Java Class Library (JCL) that contains various packages.
Each package of JCL is a collection of classes containing different built-in functions.
There are numerous packages available in JCL. Some important packages which are
frequently used in java programming are:
2. Primitive data types are defined by the 2. Composite data types are defined by the
system developers. users.
Wrapper class
The wrapper class is a class that contains a primitive data type. It is a part of java library
package java.lang.
Whenever an object to a wrapper class is created, a field in memory is allocated to
contain a primitive data.
‘Integer’ is a wrapper class that contains primitive data type ‘int’ and the following
functions:
⚫ Integer.parseInt(): To convert a string into integer data type.
⚫ Integer.toString() : To convert an integer data type into string.
Character Char
Byte Byte
Short Short
Integer Int
Long Long
Float Float
Double Double
Boolean boolean
Sumit Paul Notes
Methods of Wrapper Classes:
(A) Conversion from String to Primitive types
You can use wrapper classes to convert string to primitive data types by using the
functions in the following ways:
⚫ String to Integer type data:
Syntax:
(a) integer variable = Integer.parseInt(String);
(b) integer variable = Integer.valueOf(String);
e.g., int n; String s = "24";
n =integer.parseInt(s);
or
n =Integer.valueOf(s);
Thus the variable n results in 24 (without quotes).
Step 2 : Create a Scanner object to accept the character from the keyboard.
Scanner in=new Scanner (System.in)
1 Character.isLetter()
Determines whether the specified char value is a letter.
Character.isDigit()
2
Determines whether the specified char value is a digit.
Character.isWhitespace()
3
Determines whether the specified char value is white space.
Character.isUpperCase()
4
Determines whether the specified char value is uppercase.
Character.isLowerCase()
5
Determines whether the specified char value is lowercase.
Character.toUpperCase()
6
Returns the uppercase form of the specified char value.
Sumit Paul Notes
Character.toLowerCase()
7
Returns the lowercase form of the specified char value.
Character.toString()
8 Returns a String object representing the specified character value that is, a one-
character string.
Autoboxing
Autoboxing refers to the conversion of a primitive value into an object of the corresponding
wrapper class is called autoboxing.
The integer type data 25 is converted into an object val of Integer wrapper class.
Unboxing
Converting an object of a wrapper class (Integer) to its corresponding primitive (int) value is
called unboxing.
{
Int x=25, y;
Integer val = new Integer(x);
Y=val;
System.out.println(“Value after autoboxing\t” +val);
System.out.println(“value after unboxing\t” +y);
}
}