SlideShare a Scribd company logo
SESSION 4 : BUILT-IN
CLASSES IN JAVA
Mahmoud Ali | ACM Shoubra
Contents





Arrays Class
Math Class
Wrapper Classes
 Integer
 Long
 Double
 Float

 Char


BigInteger Class
Introduction
Built-in Classes




Java provide some useful classes in the java.lang
package .
These classes provide us with some methods and
fields that help us save time and effort in writing
code and repeating it more and more…
Class and Instance Methods


Instance Method : a method defined for an object.



Class Method : a method defined for a class.

*an introduction to object oriented programming in java ,5 th Edition , C . Thomas WU
Arrays Class
Arrays Class




Class Arrays helps you avoid reinventing the wheel
by providing static methods for common array
manipulations
Methods Include
 sort(array)

: Arranges array elements into increasing

order.
 binarySearch(array , element) : Determines whether an
array contains a specific value and, if so, returns where the
value is located.
 equal(array)

: Compares arrays.
 fill(array , element) : Places Values into an array.
 toString() : Converts array to String.
Arrays Class (cont.)






We can copy arrays using copyof method of the
class Arrays Or using class System’s static
arraycopy method.
To use Arrays Class we import it by
import java.util.Arrays ;
To Access Class methods we use the (.) operator.
 Ex: Arrays.sort(array);
Math Class
Math Class








Using only the arithmetic operators to express numerical
computations is very limiting. Many computations
require the use of mathematical functions.
For example , Expressing The Following Formula

The Math class in the java.lang package contains class
methods for commonly used mathematical functions.
To use Math Class we import it by :


import java.lang.Math;
Math Class (cont.)


Math Class Methods include
 abs(a)

: Returns the absolute value of a.
 ceil(a) : Returns the smallest whole number greater than a.
 floor(a) : Returns the largest whole number less than a.
 max(a , b) : Returns the larger of a and b.
 min(a , b) : Returns the smaller of a and b.
 pow(a , b) : Returns the number a raised to power b.
 random() : Generates a random number less than or
equal to 0.0 and less than 1.0 .
 sqrt(a) : returns the square root of a.
Math Class (cont.)
toDegrees() : Converts the given angle in radians to
degrees.
 toRadians() : Reverse of toDegrees.
 Trigonometric Functions


sin(a)
 cos(a)
 tan(a)
 All trigonometric functions are computed in radians.




Arc Trigonometric Functions
asin(a)
 acos(a)
 atan(a)



Let’s Code the Formula :
Wrapper Classes
Wrapper Classes






Each of Java's eight primitive data types has a
class dedicated to it.
These are known as wrapper classes, because they
"wrap" the primitive data type into an object of
that class.
there is an Integer class that holds an int variable.
Wrapper Classes(cont.)


Wrapper Classes have Objects Defined as Follows :


Integer




Long




Double x = new Double (value);

Float




Long x = new Long(value);

Double




Integer x = new Integer(value);

Float x = new Float(value);

Char


Character x = new Character(value);
Wrapper Classes(cont.)


Wrapper Classes have a lot of methods in common :


toString() Method :


For Example :





String s = Integer.toString(5);
String s = Character.toString(‘a’);

parse Method : Converts String to an Int , float, double ,..
Int x = Integer.parseInt(“1234”);
 double x = Double.parseDouble(“12.1545”);




Minimum and Maximum Values of a Primitive type
Int min = Integer.MIN_VALUE; //min =-2147483648
 Int max = Integer.MAX_VALUE; // max = 2147483647
 float maxv = Float.MAX_VALUE; //maxv = 3.4028235E38

Wrapper Classes(cont.)
 Converting

between primitive data types :

 doubleValue()

returns the value of this type as an double.
 floatValue() returns the value of this type as a float.
 intValue() returns the value of this type as an int.
 longValue() returns the value of this type as a long.


For Example
 int x = 15;
 float y = x.floatValue();
Wrapper Classes(cont.)
 Converting

to another number system :

 toBinaryString(a)

: Converts a into binary string.
 toHexString(a) : Converts a into hexadecimal string.
 toOctalString(a) : Converts a into octal String.
 For Example :


String s = Integer.toBinaryString(10);
BigInteger Class
BigInteger Class






The java.math.BigInteger class provides operations
analogues to all of Java's primitive integer operators
and for all relevant methods from java.lang.Math.
BigInteger class help us to deal with very large
Integers.
To Declare A BigInteger We Use :


BigInteger num = BigInteger.valueof(long number);
BigInteger Class(cont.)


BigInteger Fields Include :
BigInteger.ONE : The BigInteger constant one.
 BigInteger.ZERO : The BigInteger constant zero.
 BigInteger.TEN : The BigInteger constant ten.




BigInteger Methods Include :
abs() : returns a BigInteger whose value is the absolute
value of this BigInteger.
 add(val) : returns a BigInteger whose value is (this + val).
 subtract(val) : returns a BigInteger whose value is (this - val).
 multiply(val) : returns a BigInteger whose value is (this*val).
 divide(val): returns a BigInteger whose value is (this / val)

BigInteger Class(cont.)
pow(int ex) : returns a BigInteger whose value is thisex .
 nextProbablePrime() : returns the first integer greater than
this BigInteger that is probably prime.
 isProbablePrime() : returns true if this BigInteger is probably
prime, false otherwise .
 intValue() : converts this BigInteger to an int.
 longValue() : converts this BigInteger to a Long.
 floatValue() : converts this BigInteger to a float.
 doubleValue() : converts this BigInteger to a double.
 toString() : returns the decimal String representation of this
BigInteger.
 negate() : returns a BigInteger whose value is (-this).

BigInteger Class(cont.)


Example(http://www.spoj.com/problems/FCTRL2/)
 You

are asked to calculate factorials of some small
positive integers where 1<=n<=100
Questions ?
References








Java How To Program ,early objects 9th edition ,
Deitel.
an introduction to object oriented programming in
java ,5th Edition , C . Thomas WU .
Java An Introduction to Problem Solving and
Programming , 6th Edition ,Walter Savitch
TutorialsPoint.com
Thanks

More Related Content

PPTX
INHERITANCE IN JAVA.pptx
NITHISG1
 
PPTX
Arrays in Java
Abhilash Nair
 
PPT
Java Streams
M Vishnuvardhan Reddy
 
PDF
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
PPTX
Method overloading
Lovely Professional University
 
PPTX
Matrix chain multiplication
Respa Peter
 
PPS
Packages and inbuilt classes of java
kamal kotecha
 
DOC
Time and space complexity
Ankit Katiyar
 
INHERITANCE IN JAVA.pptx
NITHISG1
 
Arrays in Java
Abhilash Nair
 
Java Streams
M Vishnuvardhan Reddy
 
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Method overloading
Lovely Professional University
 
Matrix chain multiplication
Respa Peter
 
Packages and inbuilt classes of java
kamal kotecha
 
Time and space complexity
Ankit Katiyar
 

What's hot (20)

PPTX
Java.util
Ramakrishna kapa
 
PPT
Java interfaces
Raja Sekhar
 
PPT
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
PDF
Servlet and servlet life cycle
Dhruvin Nakrani
 
PPTX
Exception Handling in Java
lalithambiga kamaraj
 
PPTX
Python Lambda Function
Md Soyaib
 
PPTX
Regular expressions in Python
Sujith Kumar
 
PDF
Exception handling
Pranali Chaudhari
 
PPT
Jsp ppt
Vikas Jagtap
 
PPTX
Data types in php
ilakkiya
 
PPTX
Content provider in_android
PRITI TELMORE
 
PDF
REST API and CRUD
Prem Sanil
 
DOC
Data structures question paper anna university
sangeethajames07
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
java interface and packages
VINOTH R
 
PPTX
Interface in java
PhD Research Scholar
 
PPS
Introduction to class in java
kamal kotecha
 
PPTX
This keyword in java
Hitesh Kumar
 
Java.util
Ramakrishna kapa
 
Java interfaces
Raja Sekhar
 
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
Servlet and servlet life cycle
Dhruvin Nakrani
 
Exception Handling in Java
lalithambiga kamaraj
 
Python Lambda Function
Md Soyaib
 
Regular expressions in Python
Sujith Kumar
 
Exception handling
Pranali Chaudhari
 
Jsp ppt
Vikas Jagtap
 
Data types in php
ilakkiya
 
Content provider in_android
PRITI TELMORE
 
REST API and CRUD
Prem Sanil
 
Data structures question paper anna university
sangeethajames07
 
Classes, objects in JAVA
Abhilash Nair
 
java interface and packages
VINOTH R
 
Interface in java
PhD Research Scholar
 
Introduction to class in java
kamal kotecha
 
This keyword in java
Hitesh Kumar
 
Ad

Viewers also liked (20)

PPTX
Java packages
BHUVIJAYAVELU
 
PPTX
Java package
CS_GDRCST
 
PPT
Packages in java
Abhishek Khune
 
PPT
java packages
aptechsravan
 
PPT
Java packages
Raja Sekhar
 
PPT
wrapper classes
Rajesh Roky
 
PPTX
Oops concepts
Kanan Gandhi
 
PPT
4. Classes and Methods
Nilesh Dalvi
 
PPT
ppt on scanner class
deepsxn
 
PPT
Input output streams
Parthipan Parthi
 
PPTX
Visibility control in java
Tech_MX
 
PPTX
2CPP08 - Overloading and Overriding
Michael Heron
 
PPS
Wrapper class
kamal kotecha
 
PDF
Pemrograman Python Dasar
Ridwan Fadjar
 
PPTX
Java bytecode and classes
yoavwix
 
PPTX
Vectors in Java
Abhilash Nair
 
PPTX
Javascript - Array - Creating Array
Samuel Santos
 
PPT
Javascript arrays
Hassan Dar
 
PPT
Java: Primitive Data Types
Tareq Hasan
 
Java packages
BHUVIJAYAVELU
 
Java package
CS_GDRCST
 
Packages in java
Abhishek Khune
 
java packages
aptechsravan
 
Java packages
Raja Sekhar
 
wrapper classes
Rajesh Roky
 
Oops concepts
Kanan Gandhi
 
4. Classes and Methods
Nilesh Dalvi
 
ppt on scanner class
deepsxn
 
Input output streams
Parthipan Parthi
 
Visibility control in java
Tech_MX
 
2CPP08 - Overloading and Overriding
Michael Heron
 
Wrapper class
kamal kotecha
 
Pemrograman Python Dasar
Ridwan Fadjar
 
Java bytecode and classes
yoavwix
 
Vectors in Java
Abhilash Nair
 
Javascript - Array - Creating Array
Samuel Santos
 
Javascript arrays
Hassan Dar
 
Java: Primitive Data Types
Tareq Hasan
 
Ad

Similar to Built in classes in java (20)

PDF
Built-in Classes in JAVA
Mahmoud Ali Ibrahim
 
PPTX
Lect9
Jamsher bhanbhro
 
PPTX
130717666736980000
Tanzeel Ahmad
 
PPTX
DAY_1.3.pptx
ishasharma835109
 
PDF
Lec 8 03_sept [compatibility mode]
Palak Sanghani
 
PDF
Wrapper classes
Ravi_Kant_Sahu
 
PPTX
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
VivekSharma34623
 
PPTX
Computer programming 2 Lesson 10
MLG College of Learning, Inc
 
PPTX
Java Unit 2(Part 1)
Dr. SURBHI SAROHA
 
PPTX
The Java Library Concept in Java Programming.pptx
sindhu782088
 
PPTX
Java tutorial part 3
Mumbai Academisc
 
PPTX
Chap5java5th
Asfand Hassan
 
PPTX
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) I...
GANESHBABUVelu
 
PPT
Java căn bản - Chapter3
Vince Vo
 
PDF
Wrapper classes
simarsimmygrewal
 
PPT
Wrapper class (130240116056)
Akshay soni
 
PDF
Lecture3.pdf
SakhilejasonMsibi
 
PPTX
Numerical data.
Adewumi Ezekiel Adebayo
 
PPTX
Lecture 3 and 4.pptx
MAHAMASADIK
 
PDF
Lec 9 05_sept [compatibility mode]
Palak Sanghani
 
Built-in Classes in JAVA
Mahmoud Ali Ibrahim
 
130717666736980000
Tanzeel Ahmad
 
DAY_1.3.pptx
ishasharma835109
 
Lec 8 03_sept [compatibility mode]
Palak Sanghani
 
Wrapper classes
Ravi_Kant_Sahu
 
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
VivekSharma34623
 
Computer programming 2 Lesson 10
MLG College of Learning, Inc
 
Java Unit 2(Part 1)
Dr. SURBHI SAROHA
 
The Java Library Concept in Java Programming.pptx
sindhu782088
 
Java tutorial part 3
Mumbai Academisc
 
Chap5java5th
Asfand Hassan
 
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) I...
GANESHBABUVelu
 
Java căn bản - Chapter3
Vince Vo
 
Wrapper classes
simarsimmygrewal
 
Wrapper class (130240116056)
Akshay soni
 
Lecture3.pdf
SakhilejasonMsibi
 
Numerical data.
Adewumi Ezekiel Adebayo
 
Lecture 3 and 4.pptx
MAHAMASADIK
 
Lec 9 05_sept [compatibility mode]
Palak Sanghani
 

Recently uploaded (20)

PPTX
Understanding operators in c language.pptx
auteharshil95
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Understanding operators in c language.pptx
auteharshil95
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 

Built in classes in java

  • 1. SESSION 4 : BUILT-IN CLASSES IN JAVA Mahmoud Ali | ACM Shoubra
  • 2. Contents    Arrays Class Math Class Wrapper Classes  Integer  Long  Double  Float  Char  BigInteger Class
  • 4. Built-in Classes   Java provide some useful classes in the java.lang package . These classes provide us with some methods and fields that help us save time and effort in writing code and repeating it more and more…
  • 5. Class and Instance Methods  Instance Method : a method defined for an object.  Class Method : a method defined for a class. *an introduction to object oriented programming in java ,5 th Edition , C . Thomas WU
  • 7. Arrays Class   Class Arrays helps you avoid reinventing the wheel by providing static methods for common array manipulations Methods Include  sort(array) : Arranges array elements into increasing order.  binarySearch(array , element) : Determines whether an array contains a specific value and, if so, returns where the value is located.  equal(array) : Compares arrays.  fill(array , element) : Places Values into an array.  toString() : Converts array to String.
  • 8. Arrays Class (cont.)    We can copy arrays using copyof method of the class Arrays Or using class System’s static arraycopy method. To use Arrays Class we import it by import java.util.Arrays ; To Access Class methods we use the (.) operator.  Ex: Arrays.sort(array);
  • 10. Math Class     Using only the arithmetic operators to express numerical computations is very limiting. Many computations require the use of mathematical functions. For example , Expressing The Following Formula The Math class in the java.lang package contains class methods for commonly used mathematical functions. To use Math Class we import it by :  import java.lang.Math;
  • 11. Math Class (cont.)  Math Class Methods include  abs(a) : Returns the absolute value of a.  ceil(a) : Returns the smallest whole number greater than a.  floor(a) : Returns the largest whole number less than a.  max(a , b) : Returns the larger of a and b.  min(a , b) : Returns the smaller of a and b.  pow(a , b) : Returns the number a raised to power b.  random() : Generates a random number less than or equal to 0.0 and less than 1.0 .  sqrt(a) : returns the square root of a.
  • 12. Math Class (cont.) toDegrees() : Converts the given angle in radians to degrees.  toRadians() : Reverse of toDegrees.  Trigonometric Functions  sin(a)  cos(a)  tan(a)  All trigonometric functions are computed in radians.   Arc Trigonometric Functions asin(a)  acos(a)  atan(a) 
  • 13.  Let’s Code the Formula :
  • 15. Wrapper Classes    Each of Java's eight primitive data types has a class dedicated to it. These are known as wrapper classes, because they "wrap" the primitive data type into an object of that class. there is an Integer class that holds an int variable.
  • 16. Wrapper Classes(cont.)  Wrapper Classes have Objects Defined as Follows :  Integer   Long   Double x = new Double (value); Float   Long x = new Long(value); Double   Integer x = new Integer(value); Float x = new Float(value); Char  Character x = new Character(value);
  • 17. Wrapper Classes(cont.)  Wrapper Classes have a lot of methods in common :  toString() Method :  For Example :    String s = Integer.toString(5); String s = Character.toString(‘a’); parse Method : Converts String to an Int , float, double ,.. Int x = Integer.parseInt(“1234”);  double x = Double.parseDouble(“12.1545”);   Minimum and Maximum Values of a Primitive type Int min = Integer.MIN_VALUE; //min =-2147483648  Int max = Integer.MAX_VALUE; // max = 2147483647  float maxv = Float.MAX_VALUE; //maxv = 3.4028235E38 
  • 18. Wrapper Classes(cont.)  Converting between primitive data types :  doubleValue() returns the value of this type as an double.  floatValue() returns the value of this type as a float.  intValue() returns the value of this type as an int.  longValue() returns the value of this type as a long.  For Example  int x = 15;  float y = x.floatValue();
  • 19. Wrapper Classes(cont.)  Converting to another number system :  toBinaryString(a) : Converts a into binary string.  toHexString(a) : Converts a into hexadecimal string.  toOctalString(a) : Converts a into octal String.  For Example :  String s = Integer.toBinaryString(10);
  • 21. BigInteger Class    The java.math.BigInteger class provides operations analogues to all of Java's primitive integer operators and for all relevant methods from java.lang.Math. BigInteger class help us to deal with very large Integers. To Declare A BigInteger We Use :  BigInteger num = BigInteger.valueof(long number);
  • 22. BigInteger Class(cont.)  BigInteger Fields Include : BigInteger.ONE : The BigInteger constant one.  BigInteger.ZERO : The BigInteger constant zero.  BigInteger.TEN : The BigInteger constant ten.   BigInteger Methods Include : abs() : returns a BigInteger whose value is the absolute value of this BigInteger.  add(val) : returns a BigInteger whose value is (this + val).  subtract(val) : returns a BigInteger whose value is (this - val).  multiply(val) : returns a BigInteger whose value is (this*val).  divide(val): returns a BigInteger whose value is (this / val) 
  • 23. BigInteger Class(cont.) pow(int ex) : returns a BigInteger whose value is thisex .  nextProbablePrime() : returns the first integer greater than this BigInteger that is probably prime.  isProbablePrime() : returns true if this BigInteger is probably prime, false otherwise .  intValue() : converts this BigInteger to an int.  longValue() : converts this BigInteger to a Long.  floatValue() : converts this BigInteger to a float.  doubleValue() : converts this BigInteger to a double.  toString() : returns the decimal String representation of this BigInteger.  negate() : returns a BigInteger whose value is (-this). 
  • 24. BigInteger Class(cont.)  Example(http://www.spoj.com/problems/FCTRL2/)  You are asked to calculate factorials of some small positive integers where 1<=n<=100
  • 26. References     Java How To Program ,early objects 9th edition , Deitel. an introduction to object oriented programming in java ,5th Edition , C . Thomas WU . Java An Introduction to Problem Solving and Programming , 6th Edition ,Walter Savitch TutorialsPoint.com