0% found this document useful (0 votes)
64 views20 pages

Chaper 6 Library Classes

For class 10th icse

Uploaded by

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

Chaper 6 Library Classes

For class 10th icse

Uploaded by

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

Chapter 6

Library Classes
Library Classes
 As you know , java totally depends on
classes and objects. Did you know that java
also provides various predefined classes to
do the task quickly?
 Yes, it true.
 You don't need to write a code for several

tasks. These predefined classes provided by


java are known as library classes. These
classes are available to use in the form of
packages. A package is a collection of
similar type of classes and subclasses.
Some of the commonly used
packages are as follows:
Java Packages Purpose

Java.lang Used for string manipulation

Java.io Used for input/output operation

Java.util Used for input through scanner


class

Java.math Used for mathematical


operations
Data Types
(A data type specifies what type of data a variable will
store)

 Primitive data types: These are predefined /inbuildt


data type.
(int, float, char, Boolean, byte, short, long and double-
8 data types)
 Non- primitive data types:- Sometimes ,primitive

data types are not fulfilling the requirement of the


user.
 So java allows you to use composite data type. it is

the collection of primitive data types. composite data


types is also known as non primitive data types.
 These are mainly three types : class, array and

interface.
Wrapper classes
 Wrapper classes are the in-bulit classes that
contain primitive data types. These classes are
used to convert primitive data types into objects
and vice-versa with the hep of their
methods.Evry wrapper class ha various methods
too thuse,providing a way to use the primitive
data types (short, double, boolean, etc)as
objects. Every primitive data type is attached to
its wrapper class.
 For example float data type is attached with Float

data type.
Need for using a wrapper class
 To allow primitive data types to convert
form one data type to another.
 To store primitive data types as objects.
Methods to convert Primitive Data types to string.
 Integer.toString(int): The toString () method of the
Integer class is used to convert an integer value
into string. It takes an integer value as parameter
and returns after converting it into string. Syntax
of the toString() method is :
 String variable = Integer. toString (int);

For example:
int a = 12;
String s = Integer.toString (a);
System.out.println(“Result: “ s);
Output:
Result: 12
(Note: After converting an integer value into
string value, no calculation can be done on
Long.toString(long)
 Long.toString(long): The toString () method of
the Long class is used to convert long value into
string. It takes long value as parameter and
returns after converting it into string. Syntax of
the toString() method is :
 String variable = Long. toString (long);

For example:
long ln= 9418786910;
String s1 = Long.toString (ln);
System.out.println(“Result: “ s1);
Output:
Result: 9418786910
Double.toString(long)
 Double.toString(double): The toString () method
of the Double class is used to convert double
value into string. It takes double value as
parameter and returns after converting it into
string. Syntax of the toString() method is :
 String variable = Double. toString (double);

For example:
double dn= 34.5;
String s1 = Double.toString (dn);
System.out.println(“Result: “ s1);
Output:
Result: 34.5
Same for the Float
 String variable = Float. toString (float);
Methods to convert String to
integer data types
int variable =Integer.parseInt (String);
Example:
String s = “120”
Int n;
N = Integer.parseInt (s);
System.out.println (Result: “ +n);
Output:
Result : 120
Methods to convert String to long data types

long variable =Long.parseInt (String);


Example:
String s = “12025878”
Long ln;
ln = Long.parseIlong (s);
System.out.println (Result: “ +ln);

Output:
Result : 12025878
Different Methods of character
Wrapper Class
 The Character class wraps a value of the
primitive type char in an object. When a single
digit, letter or any symbols is enclosed single
quotes is known as character data type. For
example , ‘a’ , ‘3’ , ‘/’ etc.
 Using the scanner class , you can take the

charcter data type as input in the following ways:


Scanner sc = new Scanner () ;
Char ch1 = sc.next () . charAt(0);
Methods of Character Class
 Character.isLetter(): This method is used to
check weather the parameter passed is a
character or not. It return a boolean value.
Syntax of the isLetter() is:
boolean variable =
Charcter.isLetter(char);

For example:
boolean b = Charcter.isLetter(‘A’);
Output: true // as ‘A’ is a Charcter
boolean b = Charcter.isLetter(‘1’);
Output: false // as ‘1’ is not a charcter
Methods of Character Class
 Character.isDigit(): This method is used to
check weather the parameter passed is a
digit or not. It return a boolean value.
Syntax of the isLetter() is:
boolean variable = Charcter.isDigit(char);

For example:
boolean b = Character.isLetter(‘7’);
Output: true // as ‘7’ is a digit
boolean b = Character.isLetter(‘A’);
Output: false // as ‘A’ is not a digit
Methods of Character Class
Character.isLetterORDigit(): This method is
used to check weather the parameter passed
is a charcter/digit or not. It return a boolean
value.
Syntax of the isLetter() is:
boolean variable = Charcter.isLetter
OrDigit(char);

For example:
boolean b = Charcter.isLetterOrDigit(‘A’);
Output: true // as ‘A’ is a charcter
boolean b = Charcter.isLetter(‘8’);
Output: true // as ‘A’ is a character
boolean b = Charcter.isLetter(‘:’);
Methods of Character Class
Character.isWhitespace(): This method is
used to check weather the parameter
passed is a space or not. It return a
boolean value.
Syntax of the isLetter() is:
boolean variable =
Charcter.isWhitespace(char);

For example:
boolean b = Charcter.isWhitespace(‘ ’);
Output: true // as ‘ ’ is a Whitespace
boolean b = Charcter.isLetter(‘A’);
Output: false // as ‘A’ is not a Whitespace
Methods of Character Class
Character.isUppercase(): This method is
used to check weather the parameter
passed is an uppercase charcter or not. It
return a boolean value.
Syntax of the isLetter() is:
boolean variable =
Charcter.isUppercase(char);

For example:
boolean b = Character.isUpperCase(‘ A’);
Output: true // as ‘ A ’ is a Uppercase
boolean b = Character.isUpperCase(‘a’);
Output: false // as ‘a’ is not a Uppercase
Same for the Lowercase
Methods of Character Class
 Character.toUppercase(): This method is
used to convert the parameter passed to
an uppercase letter . It returns a boolean
value.
 Syntax of the isLetter() is:
 char variable =

Character,toUppercase(char);
 For example:
 char b = Character.toUpperCase(‘ A’);
 Output: A
 char b = Character.toUpperCase(‘ a’);
 Output: A
 Same for the Lowercase
Autoboxing and Unboxing
 Autoboxing : Autoboxing conversion from
primitive datatype to its corresponding
object class is called autoboxing. In other
words, if a primitive data type value is
automatically converted into its wrappers
class type, then it is called autoboxing.
For example:
Float F = 25.26;
 Unboxing: Automatic conversion from

object of wrapper class to its primitive data


type is called Unboxing.
For Example:
Float F;
Float f = F;
Example:
class boxing
{
public static void main ()
{
double a, b;
a= 23.045
Double d = new Double (a);//Autoboxing-Primitive
to object
b = d; // unboxing- object to Primitive
System.out.println (“Autoboxing : “ + d);
System.out.println (“Unboxing : “ + b);
}
}
Output: Autoboxing: 23.045

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy