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 (20)

Array and string
Array and stringArray and string
Array and string
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
02 data types in java
02 data types in java02 data types in java
02 data types in java
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Strings
StringsStrings
Strings
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Storage classes
Storage classesStorage classes
Storage classes
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Structure in C
Structure in CStructure in C
Structure in C
 
structure and union
structure and unionstructure and union
structure and union
 
Python set
Python setPython set
Python set
 
Java annotations
Java annotationsJava annotations
Java annotations
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Switch statement
Switch statementSwitch statement
Switch statement
 
Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structure
 

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

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Dernier (20)

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

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.