SlideShare une entreprise Scribd logo
1  sur  7
www.p2cinfotech.com

+1-732-546-3607

Fundamental Classes
Overview of java.lang package Object
The package java.lang contains classes and interfaces that are essential to the Java
language. These include:
•

Object Class

•

Math Class

•

The wrapper classes

•

String

•

StringBuffer

•

StringTokenizer

java.lang (non-objectives)
 Cloneable : A class implements the Cloneable interface to indicate to the
clone method in class Object that it is legal for that method to make a field-forfield copy of instances of that class.

 SecurityManager : The security manager is an abstract class that allows
applications to implement a security policy.

 Exceptions : The class Exception and its subclasses are a form of Throwable
that indicates conditions that a reasonable application might want to catch.

 Errors : An Error is a subclass of Throwable that indicates serious problems
that a reasonable application should not try to catch. Most such errors are
abnormal conditions.

 ClassLoader : The class ClassLoader is an abstract class. Applications
implement subclasses of ClassLoader in order to extend the manner in which the
Java Virtual Machine dynamically loads classes.
www.p2cinfotech.com

+1-732-546-3607

java.lang.Object
Class Object is the root of the class hierarchy. Every class has Object as a
superclass. All objects, including arrays, implement the methods of this class.
 public boolean equals( Object object )
a) should be overrided
b) provides “deep” comparison
c) not the same as ==!
•
•

== checks to see if the two objects are actually the same object
equals() compares the relevant instance variables of the two
objects
 public String toString()
a)should be overrided
b) returns a textual representation of the object
c) useful for debugging

java.lang.Math :
The class Math contains methods for performing basic numeric operations
such as the elementary exponential, logarithm, square root, and trigonometric functions.





class is final
constructor is private
methods are static
public static final double E
•

as close as Java can get to e, the base of natural logarithms

 public static final double PI
•

as close as Java can get to pi, the ratio of the circumference of a circle to
its diameter
www.p2cinfotech.com

+1-732-546-3607

int, long, float, double
int, long, float, double

abs()
max(x1, x2)

int, long, float, double

min( x1, x2)

Returns absolute value
Returns the greater of x1
and x2
Returns the smaller of x1
and x2

 double ceil( double d )
• returns the smallest integer that is not less than d, and equal to a
mathematical integer
• double x = Math.ceil( 423.3267 ); x == 424.0;
 double floor( double d )
• returns the largest integer that is not greater than d, and equal to a
mathematical integer
• double x = Math.floor( 423.3267 ); x == 423.0;
 double random()
• returns a random number between 0.0 and 1.0
• java.util.Random has more functionality
 double sin( double d )
• returns the sine of d
 double cos( double d )
• returns the cosine of d
 double tan( double d )
• returns the tangent of d
 double sqrt( double d )
• returns the square root of d

java.lang Wrapper Classes
Wrapper class wraps (encloses) around a data type and gives it an object appearance.
Wherever, the data type is required as an object, this object can be used.
Wrapper classes include methods to unwrap the object and give back the
data type. It can be compared with a chocolate. The manufacturer wraps the chocolate
with some foil or paper to prevent from pollution. The user takes the chocolate, removes
and throws the wrapper and eats it.
www.p2cinfotech.com

Primitive Data Type
boolean
byte
char
short
int
long
float
double

+1-732-546-3607

Wrapper Class
Boolean
Byte
Character
Short
Integer
Long
Float
Double

 encapsulates a single, immutable value
 all wrapper classes can be constructed by passing the value to be wrapper to the
constructor
• double d = 453.2344;
• Double myDouble = new Double( d );
 can also pass Strings that represent the value to be wrapped (doesn’t work for
Character)
• Short myShort = new Short( “2453” );
• throws NumberFormatException
 the values can be extracted by calling XXXvalue() where XXX is the name of the
primitive type.
 wrapper classes useful for classes such as Vector, which only operates on
Objects

java.lang.String
The String class represents character strings. All string literals in Java programs, such
as "abc", are implemented as instances of this class.
Strings are constant; their values cannot be changed after they are
created. String buffers support mutable strings. Because String objects are immutable
they can be shared.
 uses 16-bit Unicode characters
 represents an immutable string
 Java programs have a pool of literals
• when a String literal is created, it is created in the pool
• if the value already exists, then the existing instance of String is
used
• both == and equals() work
www.p2cinfotech.com

Difference between equals() and ==
Example:1
String s1 = “test”;
String s2 = “test”;
s1 == s2; // returns true
s1.equals( s2 ); // returns true

Example:2
String s3 = “abc”;
String s4 = new String( s3 );
s3 == s4; // returns false
s3.equals( s4 ); // returns true

String methods:
•

char charAt( int index)

•

String concat( String addThis )

•

int compareTo( String otherString )

•

boolean endsWith( String suffix )

•

boolean equals( Object obj )

•

boolean equalsIgnoreCase( String s )

•

int indexOf( char c )

•

int lastIndexOf( char c )

•

int length()

•

String replace( char old, char new )

+1-732-546-3607
www.p2cinfotech.com

•

boolean startsWith( String prefix )

•

String substring( int startIndex )

•

String toLowerCase()

•

String toString()

•

String toUpperCase()

•

+1-732-546-3607

String trim()

java.lang.StringBuffer
A thread-safe, mutable sequence of characters. String Buffer represents a String which
can be modified and has a capacity which can grow dynamically. String buffers are safe
for use by multiple threads.
The methods are synchronized where necessary so that all the operations
on any particular instance behave as if they occur in some serial order that is consistent
with the order of the method calls made by each of the individual threads involved.
•

StringBuffer append( String s )

•

StringBuffer append( Object obj )

•

StringBuffer insert( int offset, String s )

•

StringBuffer reverse()

•

StringBuffer setCharAt( int offset, char c )

•

StringBuffer setLength( int newlength )

•

String toString()

java.lang.String Concatenation
•

Java has overloaded the + operator for Strings

•

a+b+c is interpreted as

new StringBuffer().append(a).append(b).append(c).toString()
www.p2cinfotech.com

+1-732-546-3607

StringTokenizer
The string tokenizer class allows an application to break a string into tokens. The
tokenization method is much simpler than the one used by the StreamTokenizer class.
The StringTokenizer methods do not distinguish among identifiers, numbers, and
quoted strings, nor do they recognize and skip comments.
 The set of delimiters (the characters that separate tokens) may be specified
either at creation time or on a per-token basis.
 An instance of StringTokenizer behaves in one of two ways, depending on
whether it was created with the returnTokens flag having the value true or false:
 If the flag is false, delimiter characters serve to separate tokens. A token is
a maximal sequence of consecutive characters that are not delimiters.
 If the flag is true, delimiter characters are considered to be tokens. A token
is either one delimiter character, or a maximal sequence of consecutive
characters that are not delimiters.

Contenu connexe

Tendances

Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37myrajendra
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming languageMd.Al-imran Roton
 
Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with javaAAKANKSHA JAIN
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop Kumar
 
Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1Mahmoud Alfarra
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programmingChaffey College
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS ConceptBoopathi K
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm designNahid Hasan
 
virtual function
virtual functionvirtual function
virtual functionVENNILAV6
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packagesVINOTH R
 

Tendances (20)

OOP java
OOP javaOOP java
OOP java
 
Java collections
Java collectionsJava collections
Java collections
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with java
 
C++ chapter 1
C++ chapter 1C++ chapter 1
C++ chapter 1
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 
Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
 
virtual function
virtual functionvirtual function
virtual function
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 

En vedette

Short definitions of all testing types
Short definitions of all testing typesShort definitions of all testing types
Short definitions of all testing typesGaruda Trainings
 
Interview questions and answers for quality assurance
Interview questions and answers for quality assuranceInterview questions and answers for quality assurance
Interview questions and answers for quality assuranceGaruda Trainings
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 
Yaazli International Hibernate Training
Yaazli International Hibernate TrainingYaazli International Hibernate Training
Yaazli International Hibernate TrainingArjun Sridhar U R
 
Non ieee dot net projects list
Non  ieee dot net projects list Non  ieee dot net projects list
Non ieee dot net projects list Mumbai Academisc
 
For Loops and Variables in Java
For Loops and Variables in JavaFor Loops and Variables in Java
For Loops and Variables in JavaPokequesthero
 
Yaazli International Web Project Workshop
Yaazli International Web Project WorkshopYaazli International Web Project Workshop
Yaazli International Web Project WorkshopArjun Sridhar U R
 
Yaazli International AngularJS 5 Training
Yaazli International AngularJS 5 TrainingYaazli International AngularJS 5 Training
Yaazli International AngularJS 5 TrainingArjun Sridhar U R
 
Yaazli International Spring Training
Yaazli International Spring Training Yaazli International Spring Training
Yaazli International Spring Training Arjun Sridhar U R
 

En vedette (20)

Short definitions of all testing types
Short definitions of all testing typesShort definitions of all testing types
Short definitions of all testing types
 
SAP BI 7.0 Info Providers
SAP BI 7.0 Info ProvidersSAP BI 7.0 Info Providers
SAP BI 7.0 Info Providers
 
Interview questions and answers for quality assurance
Interview questions and answers for quality assuranceInterview questions and answers for quality assurance
Interview questions and answers for quality assurance
 
Top 14 qa interview tips
Top 14 qa interview tipsTop 14 qa interview tips
Top 14 qa interview tips
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Yaazli International Hibernate Training
Yaazli International Hibernate TrainingYaazli International Hibernate Training
Yaazli International Hibernate Training
 
02basics
02basics02basics
02basics
 
Non ieee dot net projects list
Non  ieee dot net projects list Non  ieee dot net projects list
Non ieee dot net projects list
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
 
Toolbarexample
ToolbarexampleToolbarexample
Toolbarexample
 
For Loops and Variables in Java
For Loops and Variables in JavaFor Loops and Variables in Java
For Loops and Variables in Java
 
Yaazli International Web Project Workshop
Yaazli International Web Project WorkshopYaazli International Web Project Workshop
Yaazli International Web Project Workshop
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Savr
SavrSavr
Savr
 
Java quick reference v2
Java quick reference v2Java quick reference v2
Java quick reference v2
 
Yaazli International AngularJS 5 Training
Yaazli International AngularJS 5 TrainingYaazli International AngularJS 5 Training
Yaazli International AngularJS 5 Training
 
Yaazli International Spring Training
Yaazli International Spring Training Yaazli International Spring Training
Yaazli International Spring Training
 
Core java online training
Core java online trainingCore java online training
Core java online training
 
09events
09events09events
09events
 
Singleton pattern
Singleton patternSingleton pattern
Singleton pattern
 

Similaire à Fundamental classes in java

Similaire à Fundamental classes in java (20)

Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Java
JavaJava
Java
 
Java Unit 2(Part 1)
Java Unit 2(Part 1)Java Unit 2(Part 1)
Java Unit 2(Part 1)
 
Java String
Java String Java String
Java String
 
Java tutorial part 3
Java tutorial part 3Java tutorial part 3
Java tutorial part 3
 
Java Day-4
Java Day-4Java Day-4
Java Day-4
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
chapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptxchapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptx
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Java
JavaJava
Java
 
Net framework
Net frameworkNet framework
Net framework
 
Learn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.netLearn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.net
 
Learning core java
Learning core javaLearning core java
Learning core java
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Java R20 - UNIT-5.docx
Java R20 - UNIT-5.docxJava R20 - UNIT-5.docx
Java R20 - UNIT-5.docx
 
Java R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdfJava R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdf
 
Javasession6
Javasession6Javasession6
Javasession6
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 

Plus de Garuda Trainings

Software testing life cycle
Software testing life cycleSoftware testing life cycle
Software testing life cycleGaruda Trainings
 
Performance testing interview questions and answers
Performance testing interview questions and answersPerformance testing interview questions and answers
Performance testing interview questions and answersGaruda Trainings
 
Loadrunner interview questions and answers
Loadrunner interview questions and answersLoadrunner interview questions and answers
Loadrunner interview questions and answersGaruda Trainings
 
Business analysis interview question and answers
Business analysis interview question and answersBusiness analysis interview question and answers
Business analysis interview question and answersGaruda Trainings
 
Quality center interview questions and answers
Quality center interview questions and answersQuality center interview questions and answers
Quality center interview questions and answersGaruda Trainings
 
Software development life cycle
Software development life cycleSoftware development life cycle
Software development life cycleGaruda Trainings
 
Interview Questions and Answers for Java
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for JavaGaruda Trainings
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobGaruda Trainings
 
Dot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineDot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineGaruda Trainings
 
Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testingGaruda Trainings
 

Plus de Garuda Trainings (11)

Software testing life cycle
Software testing life cycleSoftware testing life cycle
Software testing life cycle
 
Performance testing interview questions and answers
Performance testing interview questions and answersPerformance testing interview questions and answers
Performance testing interview questions and answers
 
Loadrunner interview questions and answers
Loadrunner interview questions and answersLoadrunner interview questions and answers
Loadrunner interview questions and answers
 
Business analysis interview question and answers
Business analysis interview question and answersBusiness analysis interview question and answers
Business analysis interview question and answers
 
Quality center interview questions and answers
Quality center interview questions and answersQuality center interview questions and answers
Quality center interview questions and answers
 
Software development life cycle
Software development life cycleSoftware development life cycle
Software development life cycle
 
Interview Questions and Answers for Java
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for Java
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
 
Dot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineDot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement online
 
Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testing
 
SQL for ETL Testing
SQL for ETL TestingSQL for ETL Testing
SQL for ETL Testing
 

Dernier

EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Dernier (20)

EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

Fundamental classes in java

  • 1. www.p2cinfotech.com +1-732-546-3607 Fundamental Classes Overview of java.lang package Object The package java.lang contains classes and interfaces that are essential to the Java language. These include: • Object Class • Math Class • The wrapper classes • String • StringBuffer • StringTokenizer java.lang (non-objectives)  Cloneable : A class implements the Cloneable interface to indicate to the clone method in class Object that it is legal for that method to make a field-forfield copy of instances of that class.  SecurityManager : The security manager is an abstract class that allows applications to implement a security policy.  Exceptions : The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.  Errors : An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.  ClassLoader : The class ClassLoader is an abstract class. Applications implement subclasses of ClassLoader in order to extend the manner in which the Java Virtual Machine dynamically loads classes.
  • 2. www.p2cinfotech.com +1-732-546-3607 java.lang.Object Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.  public boolean equals( Object object ) a) should be overrided b) provides “deep” comparison c) not the same as ==! • • == checks to see if the two objects are actually the same object equals() compares the relevant instance variables of the two objects  public String toString() a)should be overrided b) returns a textual representation of the object c) useful for debugging java.lang.Math : The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.     class is final constructor is private methods are static public static final double E • as close as Java can get to e, the base of natural logarithms  public static final double PI • as close as Java can get to pi, the ratio of the circumference of a circle to its diameter
  • 3. www.p2cinfotech.com +1-732-546-3607 int, long, float, double int, long, float, double abs() max(x1, x2) int, long, float, double min( x1, x2) Returns absolute value Returns the greater of x1 and x2 Returns the smaller of x1 and x2  double ceil( double d ) • returns the smallest integer that is not less than d, and equal to a mathematical integer • double x = Math.ceil( 423.3267 ); x == 424.0;  double floor( double d ) • returns the largest integer that is not greater than d, and equal to a mathematical integer • double x = Math.floor( 423.3267 ); x == 423.0;  double random() • returns a random number between 0.0 and 1.0 • java.util.Random has more functionality  double sin( double d ) • returns the sine of d  double cos( double d ) • returns the cosine of d  double tan( double d ) • returns the tangent of d  double sqrt( double d ) • returns the square root of d java.lang Wrapper Classes Wrapper class wraps (encloses) around a data type and gives it an object appearance. Wherever, the data type is required as an object, this object can be used. Wrapper classes include methods to unwrap the object and give back the data type. It can be compared with a chocolate. The manufacturer wraps the chocolate with some foil or paper to prevent from pollution. The user takes the chocolate, removes and throws the wrapper and eats it.
  • 4. www.p2cinfotech.com Primitive Data Type boolean byte char short int long float double +1-732-546-3607 Wrapper Class Boolean Byte Character Short Integer Long Float Double  encapsulates a single, immutable value  all wrapper classes can be constructed by passing the value to be wrapper to the constructor • double d = 453.2344; • Double myDouble = new Double( d );  can also pass Strings that represent the value to be wrapped (doesn’t work for Character) • Short myShort = new Short( “2453” ); • throws NumberFormatException  the values can be extracted by calling XXXvalue() where XXX is the name of the primitive type.  wrapper classes useful for classes such as Vector, which only operates on Objects java.lang.String The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared.  uses 16-bit Unicode characters  represents an immutable string  Java programs have a pool of literals • when a String literal is created, it is created in the pool • if the value already exists, then the existing instance of String is used • both == and equals() work
  • 5. www.p2cinfotech.com Difference between equals() and == Example:1 String s1 = “test”; String s2 = “test”; s1 == s2; // returns true s1.equals( s2 ); // returns true Example:2 String s3 = “abc”; String s4 = new String( s3 ); s3 == s4; // returns false s3.equals( s4 ); // returns true String methods: • char charAt( int index) • String concat( String addThis ) • int compareTo( String otherString ) • boolean endsWith( String suffix ) • boolean equals( Object obj ) • boolean equalsIgnoreCase( String s ) • int indexOf( char c ) • int lastIndexOf( char c ) • int length() • String replace( char old, char new ) +1-732-546-3607
  • 6. www.p2cinfotech.com • boolean startsWith( String prefix ) • String substring( int startIndex ) • String toLowerCase() • String toString() • String toUpperCase() • +1-732-546-3607 String trim() java.lang.StringBuffer A thread-safe, mutable sequence of characters. String Buffer represents a String which can be modified and has a capacity which can grow dynamically. String buffers are safe for use by multiple threads. The methods are synchronized where necessary so that all the operations on any particular instance behave as if they occur in some serial order that is consistent with the order of the method calls made by each of the individual threads involved. • StringBuffer append( String s ) • StringBuffer append( Object obj ) • StringBuffer insert( int offset, String s ) • StringBuffer reverse() • StringBuffer setCharAt( int offset, char c ) • StringBuffer setLength( int newlength ) • String toString() java.lang.String Concatenation • Java has overloaded the + operator for Strings • a+b+c is interpreted as new StringBuffer().append(a).append(b).append(c).toString()
  • 7. www.p2cinfotech.com +1-732-546-3607 StringTokenizer The string tokenizer class allows an application to break a string into tokens. The tokenization method is much simpler than the one used by the StreamTokenizer class. The StringTokenizer methods do not distinguish among identifiers, numbers, and quoted strings, nor do they recognize and skip comments.  The set of delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis.  An instance of StringTokenizer behaves in one of two ways, depending on whether it was created with the returnTokens flag having the value true or false:  If the flag is false, delimiter characters serve to separate tokens. A token is a maximal sequence of consecutive characters that are not delimiters.  If the flag is true, delimiter characters are considered to be tokens. A token is either one delimiter character, or a maximal sequence of consecutive characters that are not delimiters.