2 Final Library Classes in Java 2024 25
2 Final Library Classes in Java 2024 25
JAVA
2024-25
JAVA PACKAGES
java.lang (default package, contains classes
related to String manipulations)
java.io (i/p &o/p Operations)
java.awt(classes to implement GUI)
java.util(contains utility structures)
java.applets(classes for implementing
applets)
java.net(classes for supporting network
operations)
java.math(classes for mathematical
operations)
DATA TYPES
Primitive(int,float,char,double,boolean,short
,long,byte)
Non primitive/composite data
types/Reference Data types
Ex: String, class, arrays,objects,interfaces etc.
int a=10; //primitive
int a[]=new int[10]; composite/Reference
WRAPPER CLASSES
Wrapper classes are a part of java.lang
package.
They contain primitive data values in terms
of objects
Need of using Wrapper classes
1. To store primitive values in the objects
2. To convert string data to primitive types
and vice versa
WRAPPER CLASSES IN JAVA
CONVERSION FROM STRING TO PRIMITIVE
float n;
String str=“Java”;
int n=Integer.parseInt(str);
Output:
NumberFormatException as str has characters other
than digits.
String str1=“894”;
n=Float.parseFloat(str);→ Output: 894.0
String s=“1234”;
n=Double.valueOf(s);
valueOf()-> function converts String to primitive data
type, i.e , s gets converted to 1234.0 on which
mathematical operations can be performed.
CONVERSION FROM PRIMITIVE TO STRING
int n=24;
String s=Integer.toString(n);
We cannot perform any mathematical
operation with s which is in String form now.
Similarly Double.toString(n) ---
CHARACTER FUNCTIONS
boolean c=Character.isLetter(‘@’);
boolean d=Character.isDigit(‘9’);
boolean ld=Character.isLetterOrDigit(‘ ’);
boolean w=Character.isWhitespace(‘ ’);
boolean u=Character.isUpperCase(‘A’);
boolean l=Character.isLowerCase(‘t’);
char ch=Character.toUpperCase(‘g’);
char ch=Character.toLowerCase(‘G’);
String str=“Dhanunjay P Shankar”;
Length:19-no.of characters
Index= 0- (length-1)
for loop
for(i=0;i<l;i++)
{
ch=str.charAt(i);// //each character of the
String
}
AUTO BOXING AND UNBOXING
Autoboxing: Converting a primitive value
into an object of the corresponding wrapper
class is called auto boxing. For example,
converting int to Integer class object. The
Java compiler applies auto boxing when a
primitive value is:
Passed as a parameter to a method
that expects an object of the corresponding
wrapper class.
Assigned to a variable of the
corresponding wrapper class.
UN BOXING
Un boxing: Converting an object of a wrapper
type to its corresponding primitive value is
called unboxing. For example conversion
of Integer to int. The Java compiler applies
unboxing when an object of a wrapper class is:
Passed as a parameter to a method that expects
a value of the corresponding primitive type.
Assigned to a variable of the
corresponding primitive type.
Ex: Integer val=new Integer(10);(auto boxing)
int y=val;(unboxing)
int y=b;