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

What's hot

Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentation
VedaGayathri1
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
RahulAnanda1
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
Kavitha713564
 
String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)
Anwar Hasan Shuvo
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
teach4uin
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
Applets
AppletsApplets
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
Muthukumaran Subramanian
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with python
Arslan Arshad
 
Introduction to method overloading &amp; method overriding in java hdm
Introduction to method overloading &amp; method overriding  in java  hdmIntroduction to method overloading &amp; method overriding  in java  hdm
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
Web controls
Web controlsWeb controls
Web controls
Sarthak Varshney
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
Boopathi K
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaRaghu nath
 

What's hot (20)

Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentation
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Applets
AppletsApplets
Applets
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with python
 
Introduction to method overloading &amp; method overriding in java hdm
Introduction to method overloading &amp; method overriding  in java  hdmIntroduction to method overloading &amp; method overriding  in java  hdm
Introduction to method overloading &amp; method overriding in java hdm
 
Web controls
Web controlsWeb controls
Web controls
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 

Viewers also liked

Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
kamal kotecha
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
java packages
java packagesjava packages
java packages
aptechsravan
 
Java packages
Java packagesJava packages
Java packages
Raja Sekhar
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
Kanan Gandhi
 
4. Classes and Methods
4. Classes and Methods4. Classes and Methods
4. Classes and Methods
Nilesh Dalvi
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner classdeepsxn
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in javaTech_MX
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
Michael Heron
 
Pemrograman Python Dasar
Pemrograman Python DasarPemrograman Python Dasar
Pemrograman Python Dasar
Ridwan Fadjar
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classesyoavwix
 
Javascript - Array - Creating Array
Javascript - Array - Creating ArrayJavascript - Array - Creating Array
Javascript - Array - Creating Array
Samuel Santos
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
Hassan Dar
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan
 

Viewers also liked (20)

Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
 
Java packages
Java packagesJava packages
Java packages
 
Java package
Java packageJava package
Java package
 
Packages in java
Packages in javaPackages in java
Packages in java
 
java packages
java packagesjava packages
java packages
 
Java packages
Java packagesJava packages
Java packages
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
 
CSS
CSSCSS
CSS
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
4. Classes and Methods
4. Classes and Methods4. Classes and Methods
4. Classes and Methods
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner class
 
Input output streams
Input output streamsInput output streams
Input output streams
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
 
Pemrograman Python Dasar
Pemrograman Python DasarPemrograman Python Dasar
Pemrograman Python Dasar
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classes
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Javascript - Array - Creating Array
Javascript - Array - Creating ArrayJavascript - Array - Creating Array
Javascript - Array - Creating Array
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 

Similar to Built in classes in java

Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
MLG College of Learning, Inc
 
130717666736980000
130717666736980000130717666736980000
130717666736980000
Tanzeel Ahmad
 
Hive Functions Cheat Sheet
Hive Functions Cheat SheetHive Functions Cheat Sheet
Hive Functions Cheat Sheet
Hortonworks
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Palak Sanghani
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
simarsimmygrewal
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
Kavindu Sachinthe
 
C programming session 04
C programming session 04C programming session 04
C programming session 04Dushmanta Nath
 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
Dieudonne Nahigombeye
 
1.Array and linklst definition
1.Array and linklst definition1.Array and linklst definition
1.Array and linklst definition
balavigneshwari
 
Java căn bản - Chapter3
Java căn bản - Chapter3Java căn bản - Chapter3
Java căn bản - Chapter3Vince Vo
 
DAY_1.3.pptx
DAY_1.3.pptxDAY_1.3.pptx
DAY_1.3.pptx
ishasharma835109
 
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptxvectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
VivekSharma34623
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
SachinBhosale73
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Palak Sanghani
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its functionFrankie Jones
 

Similar to Built in classes in java (20)

Built-in Classes in JAVA
Built-in Classes in JAVABuilt-in Classes in JAVA
Built-in Classes in JAVA
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
 
130717666736980000
130717666736980000130717666736980000
130717666736980000
 
Hive Functions Cheat Sheet
Hive Functions Cheat SheetHive Functions Cheat Sheet
Hive Functions Cheat Sheet
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
 
Arrays
ArraysArrays
Arrays
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
 
1.Array and linklst definition
1.Array and linklst definition1.Array and linklst definition
1.Array and linklst definition
 
Java căn bản - Chapter3
Java căn bản - Chapter3Java căn bản - Chapter3
Java căn bản - Chapter3
 
DAY_1.3.pptx
DAY_1.3.pptxDAY_1.3.pptx
DAY_1.3.pptx
 
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptxvectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Collections
CollectionsCollections
Collections
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
Lec2
Lec2Lec2
Lec2
 

Recently uploaded

ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 

Recently uploaded (20)

ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 

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