0% found this document useful (0 votes)
7 views

Library Classes

Uploaded by

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

Library Classes

Uploaded by

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

Library Classes

Wrapper Classes are library classes in Java which are used to convert a primitive data type into an
object and vice versa

They are present in the ‘java.lang’ package which is a preloaded package in every Java class

java.lang = contains classes for basic programming like – wrapper classes, String, Math functions,etc.

java.util = holds basic utility classes such as Scanner and Printer

java.io = has classes for input and output of data

java.awt = has classes to implement or manage Graphical User Interface

java.net = has classes for networks

java.applets = has classes for using applets

* wrapper classes are needed to convert primitive data types into objects and objects are needed to
pass arguments as references to methods, whenever required

* wrapper classes provide various methods that help in converting various data types to the required
data types

Autoboxing –

Automatic conversion of primitive data types to objects of their corresponding wrapper classes is
known as autoboxing

Done automatically by the compiler

e.g. –

int a = 12 ;

Integer b = a ; //autoboxing

int a = 12 ;

Integer b = new Integer(a) ; // not autoboxing but manual boxing

b = a ; //autoboxing
Unboxing –

Automatic conversion of an object of a wrapper class to its corresponding primitive data type

Done by the compiler

e.g. –

Integer a = 23 ;

int b = a ; //unboxing

Integer a = 23 ;

int b = a.intValue() ;// unboxing ?? *doubt* probably not unboxing but manual boxing

Parsing – refers to analysing a String and extracting relevant data from it as per the requirement

Methods to parse a String into a primitive data type -

i. String to integer –

Integer.parseInt()

Integer.valueOf()

String s = “25” ;

int i = Integer.parseInt(s) ;

or

int i = Integer.valueOf(s) ;

ii. String to long –

Long.parseLong()

Long.valueOf()

String s = “123456789” ;

long l = Long.parseLong(s) ;

or

long l = Long.valueOf(s) ;

iii. String to float –

Float.parseFloat()

Float.valueOf()

String s = “12.45” ;

float f = Float.parseFloat(s) ;
or

float f = Float.valueOf(s) ;

iv. String to double –

Double.parseDouble()

Double.valueOf()

String s = “14.123” ;

double d = Double.parseDouble(s) ;

or

double d = Double.valueOf(s) ;

Character Functions –

i. Character.isLetter() iii. Character.isLetterOrDigit() v. Character.isLowerCase()

ii. Character.isDigit() iv. Character.isWhiteSpace() vi. Character.isUpperCase()

vii. Character.toLowerCase()

viii. Character.toUpperCase()

don’t forget to mention argument within the parenthesis in examination


** argument = char ch **

You might also like