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

Library Classes

Uploaded by

Akshat poddar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Library Classes

Uploaded by

Akshat poddar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LIBRARY CLASSES IN JAVA

DEPARTMENTOF ASSAMVALLEY
LIBRARY CLASSES IN JAVA
Java Class Library (JCL):
1
libraries that Java applications he Java Class is a set of dynamicaljv loadable
can call at run time. These classes arc grouped in different
Java packages.
Package: Package in Java is
a mechanism to encapsulatea group of classes, sub packagesand

Example: import java.util.%


Primitive and Composite Data
Type:
Primitive Data Type: Primitive
types are the most basic data types available within the Java language.
There are 8 primitive data types:
boolean , byte , char, short int , long , float and double . These types
serve as the building blocks of
data manipulation in Java.
Composite Data Type: Composite
data types are constructed with combination of primitive data type and
other non-composite data type arranged
in a structure.
Java allows to create new data type using
combination of the primitive data types, called composite or user-
defined data types. Class is an example of
composite data type and we can declare objects as variables of
the class type.
Difference between Primitive and Composite data type:

Primitive Data Type Composite Data Type


1. Primitive types are the most basic data 1. Data types created by programmers using
types available within the Java language. combination of the primitive data types.
2. The size is fixed. 2. The size depends on the number of
member variables and their types.
3. When an object (variable) of class type is
3. Only one memory location is allocated.
defined memory allocated will vary.
4. To create an object variable 'new' keyword
4. 'new' keyword is not used while created.
is used.
also
'new' keyword: •new' keyword creates a Java object and allocates memory for it on the heap. new is
used for array creation, as arrays are also objects.
Dot C.' ) operator: The dot operator, also known as separator or period used to separate a variable or
be accessed using class name.
method from a reference variable. Only static variables or methods can
data type into an object.
Wrapper Class: Wrapper classes in Java encapsulate the primitive
Need of Wrapper Classes:
objects. Objects are needed if we wish to modify the
1. They convert primitive data types into
primitive types are passed by value).
arguments passed into a method (because
handles only objects and hence wrapper classes help in this case
2. The classes in java.util package
also.
framework, such as ArrayListand Vector, store only objects
3. Data structures in the Collection
(reference types) and not primitive types. multithreading.
synchronization in
4. An object is needed to support

21 Page
METHODS OF
WRAPPER CLASSES:
Return
Method
Type Description
boolean Character ist otter()
boolean Checks whether thc character a Ictter or not.
Checks whether the character is a digit or not.
boolean Character.istettcrOrDtglt() This function returns true if the gjven argument is either a
Ictter or digit.
boolean Character.isWhiteSpace() This function returns true if the given argument is a white
space.

boolean b: Character.isWhiteSpace(' i);


It returns true.
boolean
It returns false.

boolean Character.isUpperCase() This function returns true if the given argument is a upper
case letter.
boolean Character.isLowerCase() This function returns true if the given argument is a lower
case letter.
CONVERTING UPPER CASE LETTERS TO LOWERCASE AND VICE VERSA
Character Character.toUpperCase(char c) This method takes a character as parameter and returns the
character in lower case.
Character Character-toLowerCase(char c) This method takes a character as parameter and returns the
character in upper case.
PARSING OR DECODING PRIMITIVE TYPE FROM STRING
int parselnt(String) Takes String and converts it to a primitive "int" type number.
long parseLong(String) Takes String and converts it to a primitive "long" type number.
float parseFloat(String) Takes String and converts it to a primitive "float" type number.
Double parseDouble(String) Takes String and converts it to a primitive "double" type number.

Example:
or lower) otherwise check whether it is a digit or
Program to accept a character and check the case (upper
special character.
Answer:
import Scanner-util.*
public class char_ check

char ch;
void main()throws IOException

Scanner obj = new Scanner(System.in);


check:");
to
System.out.print("Enter character
ch= obj.next().charAt(O);

31 Page
System.out.println(ch f" is a letter");

System.out.println(ch 4" ISa uppercase letter");

System.out println(ch f" is a lowercase Ictter");

else

System.out.println(ch 4" is a digit");


else
System.out.println(ch +" is a special character");

Parsing primitive type:


String Marks:" 180";
int A = Integer.parselnt(Marks); //parsed value of A as double 180
long B = Long.parseLong(Marks); //parsed value of B as long 180
float C = Float.parseFloat(Marks); //parsed value of C as float 180
double D = Double.parseDouble(Marks); //parsed value of D as double 180

CONVERTING UPPER CASE LETTERSTO LOWERCASEAND VICE VERSA:

char a= •m;
char b= 'M';
char upper= character.toUpperCase(a); // value of variable upper is now uppercase M
char lower= character.toLowerCase(b); // value of variable lower is now uppercase m
Character.isLetterOrDigit() example:

char cl = 'Z', c2 = c3= '/' ;


boolean booll = Character.isLetterOrDigit(c1);
System.out.println(cl + " is a letter/digit ? " + booll); // output : true
boolean b0012 = Character.isLetterOrDigit(c2);
System.out.println(c2 + " is a letter/digit ? " + b0012);// output : true
boolean b0013 = Character.isLetterOrDigit(c3);
System.out.println(c3 + " is a letter/digit ? " + b0013);// output : false

41 Page
AUTOBOXING AND
UNBOXtNG:
Autoboxing: Automatic
is known as conversion of primitive types to the object
autoboxing. Vor example — of their correspondingwrapperclasses
conversion of int to Integer, long to Long, double to Double etc.
Example:
Integer auto=9;
System.out.println(: The value of auto is:"+auto);
Output: 9
Unboxing: It is just the reverse process of autoboxing.Automaticallyconvertingan objectof a wrapper
class to its corresponding primitive type is known as unboxing. For example —conversion of Integerto int,
Long to long, Double to double etc.
Example:
Integer auto—newInteger(S);
int k=auto;
System.out.println(: The value of auto is:"+k)
Output: 5

51 P age

You might also like