SlideShare a Scribd company logo
1 of 20
JAVA UNIT 2(Part 1)
BY: SURBHI SAROHA
SYLLABUS
ī‚´ Java Lang package
ī‚´ Simple type wrappers
ī‚´ Number,Double,float,byte,short,int,long,character,Boolean,process and void.
ī‚´ The Maths class.
ī‚´ Java Utility and Collection Classes.
Contâ€Ļ.
ī‚´ Arrays as collections
ī‚´ Algorithms
ī‚´ Wrappers as implementations
ī‚´ Extending the abstract implementation legacy collections
ī‚´ Framework classes
ī‚´ Traversing collections with enumeration’s
Java Lang package
ī‚´ Provides classes that are fundamental to the design of the Java programming language.
ī‚´ The most important classes are Object, which is the root of the class hierarchy, and Class, instances
of which represent classes at run time.
ī‚´ Following are the Important Classes in Java.lang package :
ī‚´ Boolean: The Boolean class wraps a value of the primitive type boolean in an object.
ī‚´ Byte: The Byte class wraps a value of primitive type byte in an object.
ī‚´ Character – Set 1, Set 2: The Character class wraps a value of the primitive type char in an object.
ī‚´ Character.Subset: Instances of this class represent particular subsets of the Unicode character set.
ī‚´ Character.UnicodeBlock: A family of character subsets representing the character blocks in the
Unicode specification.
ī‚´ Class – Set 1, Set 2 : Instances of the class Class represent classes and interfaces in a running Java
application.
Contâ€Ļ
ī‚´ ClassLoader: A class loader is an object that is responsible for loading classes.
ī‚´ ClassValue: Lazily associate a computed value with (potentially) every type.
ī‚´ Compiler: The Compiler class is provided to support Java-to-native-code compilers and related
services.
ī‚´ Double: The Double class wraps a value of the primitive type double in an object.
ī‚´ Enum: This is the common base class of all Java language enumeration types.
ī‚´ Float: The Float class wraps a value of primitive type float in an object.
ī‚´ InheritableThreadLocal: This class extends ThreadLocal to provide inheritance of values from
parent thread to child thread: when a child thread is created, the child receives initial values for all
inheritable thread-local variables for which the parent has values.
ī‚´ Integer :The Integer class wraps a value of the primitive type int in an object.
ī‚´ Long: The Long class wraps a value of the primitive type long in an object.
Contâ€Ļ
ī‚´ Math – Set 1, Set 2: The class Math contains methods for performing basic
numeric operations such as the elementary exponential, logarithm, square root,
and trigonometric functions.
ī‚´ Number: The abstract class Number is the superclass of classes BigDecimal,
BigInteger, Byte, Double, Float, Integer, Long, and Short.
ī‚´ Object: Class Object is the root of the class hierarchy.
ī‚´ Package: Package objects contain version information about the implementation
and specification of a Java package.
ī‚´ Process: The ProcessBuilder.start() and Runtime.exec methods create a native
process and return an instance of a subclass of Process that can be used to control
the process and obtain information about it.
ī‚´ ProcessBuilder: This class is used to create operating system processes.
Contâ€Ļ
ī‚´ Math – Set 1, Set 2: The class Math contains methods for performing basic
numeric operations such as the elementary exponential, logarithm, square root,
and trigonometric functions.
ī‚´ Number: The abstract class Number is the superclass of classes BigDecimal,
BigInteger, Byte, Double, Float, Integer, Long, and Short.
ī‚´ Object: Class Object is the root of the class hierarchy.
ī‚´ Package: Package objects contain version information about the implementation
and specification of a Java package.
ī‚´ Process: The ProcessBuilder.start() and Runtime.exec methods create a native
process and return an instance of a subclass of Process that can be used to control
the process and obtain information about it.
ī‚´ ProcessBuilder: This class is used to create operating system processes.
Contâ€Ļ
ī‚´ StringBuffer: A thread-safe, mutable sequence of characters.
ī‚´ StringBuilder: A mutable sequence of characters.
ī‚´ System: The System class contains several useful class fields and methods.
ī‚´ Thread: A thread is a thread of execution in a program.
ī‚´ ThreadGroup: A thread group represents a set of threads.
ī‚´ ThreadLocal: This class provides thread-local variables.
ī‚´ Throwable: The Throwable class is the superclass of all errors and exceptions in the
Java language.
ī‚´ Void: The Void class is an uninstantiable placeholder class to hold a reference to
the Class object representing the Java keyword void.
Simple type wrappers
ī‚´ A Wrapper class is a class whose object wraps or contains primitive data types.
ī‚´ When we create an object to a wrapper class, it contains a field and in this field, we
can store primitive data types.
ī‚´ In other words, we can wrap a primitive value into a wrapper class object.
ī‚´ Need of Wrapper Classes
ī‚´ They convert primitive data types into objects. Objects are needed if we wish to
modify the arguments passed into a method (because primitive types are passed
by value).
ī‚´ The classes in java.util package handles only objects and hence wrapper classes
help in this case also.
Contâ€Ļ.
ī‚´ Data structures in the Collection framework, such as ArrayList and Vector, store
only objects (reference types) and not primitive types.
ī‚´ An object is needed to support synchronization in multithreading.
ī‚´ Primitive Data types and their Corresponding Wrapper class
Number,Double,float,byte,short,int,
long,character,Boolean,process and void.
ī‚´ int myNum = 5; // Integer (whole number)
ī‚´ float myFloatNum = 5.99f; // Floating point number
ī‚´ char myLetter = 'D'; // Character
ī‚´ boolean myBool = true; // Boolean
ī‚´ String myText = "Hello"; // String
ī‚´ Data types are divided into two groups:
ī‚´ Primitive data types - includes byte, short, int, long, float, double, boolean and char
ī‚´ Non-primitive data types - such as String, Arrays and Classes
There are eight primitive data types in Java:
ī‚´ Data Type Size Description
ī‚´ byte 1 byte Stores whole numbers from -128 to 127
ī‚´ short 2 bytes Stores whole numbers from -32,768 to 32,767
ī‚´ int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647
ī‚´ long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
ī‚´ float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
ī‚´ double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits
ī‚´ boolean 1 bit Stores true or false values
ī‚´ char 2 bytes Stores a single character/letter or ASCII values
The Maths class
ī‚´ Java Math class provides several methods to work on math calculations like min(), max(), avg(), sin(),
cos(), tan(), round(), ceil(), floor(), abs() etc.
ī‚´ Example 1
ī‚´ public class JavaMathExample1
ī‚´ {
ī‚´ public static void main(String[] args)
ī‚´ {
ī‚´ double x = 28;
ī‚´ double y = 4;
ī‚´
ī‚´ // return the maximum of two numbers
ī‚´ System.out.println("Maximum number of x and y is: " +Math.max(x, y));
Contâ€Ļ
ī‚´ // return the square root of y
ī‚´ System.out.println("Square root of y is: " + Math.sqrt(y));
ī‚´
ī‚´ //returns 28 power of 4 i.e. 28*28*28*28
ī‚´ System.out.println("Power of x and y is: " + Math.pow(x, y));
ī‚´
ī‚´ // return the logarithm of given value
ī‚´ System.out.println("Logarithm of x is: " + Math.log(x));
ī‚´ System.out.println("Logarithm of y is: " + Math.log(y));
ī‚´
ī‚´ // return the logarithm of given value when base is 10
ī‚´ System.out.println("log10 of x is: " + Math.log10(x));
ī‚´ System.out.println("log10 of y is: " + Math.log10(y));
Contâ€Ļ.
ī‚´ // return the log of x + 1
ī‚´ System.out.println("log1p of x is: " +Math.log1p(x));
ī‚´
ī‚´ // return a power of 2
ī‚´ System.out.println("exp of a is: " +Math.exp(x));
ī‚´
ī‚´ // return (a power of 2)-1
ī‚´ System.out.println("expm1 of a is: " +Math.expm1(x));
ī‚´ }
ī‚´ }
Java Utility and Collection Classes.
ī‚´ Collections class in java is a useful utility class to work with collections in java.
ī‚´ The java.util.Collections class directly extends the Object class and exclusively
consists of the static methods that operate on Collections or return them.
ī‚´ Collections Class in java
ī‚´ Collections class contains polymorphic algorithms that operate on collections and
“wrappers” — which return a new collection backed by a specified collection. It is a
member of Java Collections Framework.
ī‚´ Collections class fields
ī‚´ Collections class contains 3 fields: EMPTY_LIST, EMPTY_SET, EMPTY_MAP, which can
be used to get immutable empty List, Map and Set respectively.
Example
ī‚´ package utility;
ī‚´ import java.util.Collections;
ī‚´ import java.util.ArrayList;
ī‚´ import java.util.List;
ī‚´ public class CollectionsDemo {
ī‚´ public static void main(String[] args) {
ī‚´ List<String>student<String>List = new ArrayList();
ī‚´ studentList.add("Neeraj");
ī‚´ studentList.add("Mahesh");
ī‚´ studentList.add("Armaan");
ī‚´
Contâ€Ļ.
ī‚´ studentList.add("Preeti");
ī‚´ studentList.add("Sanjay");
ī‚´ studentList.add("Neeraj");
ī‚´ studentList.add("Zahir");
ī‚´ System.out.println("Original List " + studentList);
ī‚´ Collections.sort(studentList);
ī‚´ System.out.println("Sorted alphabetically List " + studentList);
ī‚´ Collections.reverse(studentList);
ī‚´ }
Contâ€Ļ.
ī‚´ System.out.println("Reverse List " + studentList);
ī‚´ Collections.shuffle(studentList);
ī‚´ System.out.println("Shuffled List " + studentList);
ī‚´ System.out.println("Checking occurance of Neeraj: "
ī‚´ + Collections.frequency(studentList, "Neeraj"));
THANK YOU īŠ

More Related Content

What's hot

Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfacesDevaKumari Vijay
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core javaRajeev Uppala
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of javakamal kotecha
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Javakjkleindorfer
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objectsmaznabili
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHPLorna Mitchell
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IOJussi Pohjolainen
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objectsPraveen M Jigajinni
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objectskjkleindorfer
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaEdureka!
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIEduardo Bergavera
 
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
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 

What's hot (20)

Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfaces
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
 
Oops
OopsOops
Oops
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IO
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objects
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
 
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
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 

Similar to Java Unit 2(Part 1)

Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vectornurkhaledah
 
Java tutorial part 3
Java tutorial part 3Java tutorial part 3
Java tutorial part 3Mumbai Academisc
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)Akshay soni
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in javaGaruda Trainings
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptxVijalJain3
 
Java14
Java14Java14
Java14aiter2002
 
There are 37 classes in java.lang package as per Java SE7 The java.pdf
There are 37 classes in java.lang package as per Java SE7 The java.pdfThere are 37 classes in java.lang package as per Java SE7 The java.pdf
There are 37 classes in java.lang package as per Java SE7 The java.pdfaparnatiwari291
 
Unit3 packages &amp; interfaces
Unit3 packages &amp; interfacesUnit3 packages &amp; interfaces
Unit3 packages &amp; interfacesKalai Selvi
 
Java programming basics
Java programming basicsJava programming basics
Java programming basicsHamid Ghorbani
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2sadhana312471
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptxssuser8347a1
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-Circle
 
OOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixOOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixNovita Sari
 
JavaBasicsCore1.ppt
JavaBasicsCore1.pptJavaBasicsCore1.ppt
JavaBasicsCore1.pptbuvanabala
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 

Similar to Java Unit 2(Part 1) (20)

Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Java String
Java String Java String
Java String
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Java tutorial part 3
Java tutorial part 3Java tutorial part 3
Java tutorial part 3
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in java
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Java14
Java14Java14
Java14
 
There are 37 classes in java.lang package as per Java SE7 The java.pdf
There are 37 classes in java.lang package as per Java SE7 The java.pdfThere are 37 classes in java.lang package as per Java SE7 The java.pdf
There are 37 classes in java.lang package as per Java SE7 The java.pdf
 
Unit3 packages &amp; interfaces
Unit3 packages &amp; interfacesUnit3 packages &amp; interfaces
Unit3 packages &amp; interfaces
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
OOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixOOP, Networking, Linux/Unix
OOP, Networking, Linux/Unix
 
JavaBasicsCore1.ppt
JavaBasicsCore1.pptJavaBasicsCore1.ppt
JavaBasicsCore1.ppt
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 

More from SURBHI SAROHA

Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptxSURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxSURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxSURBHI SAROHA
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)SURBHI SAROHA
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)SURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3SURBHI SAROHA
 

More from SURBHI SAROHA (20)

Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
DBMS UNIT 3
DBMS UNIT 3DBMS UNIT 3
DBMS UNIT 3
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
 
JAVA UNIT 2
JAVA UNIT 2JAVA UNIT 2
JAVA UNIT 2
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)Dr. Mazin Mohamed alkathiri
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 

Java Unit 2(Part 1)

  • 1. JAVA UNIT 2(Part 1) BY: SURBHI SAROHA
  • 2. SYLLABUS ī‚´ Java Lang package ī‚´ Simple type wrappers ī‚´ Number,Double,float,byte,short,int,long,character,Boolean,process and void. ī‚´ The Maths class. ī‚´ Java Utility and Collection Classes.
  • 3. Contâ€Ļ. ī‚´ Arrays as collections ī‚´ Algorithms ī‚´ Wrappers as implementations ī‚´ Extending the abstract implementation legacy collections ī‚´ Framework classes ī‚´ Traversing collections with enumeration’s
  • 4. Java Lang package ī‚´ Provides classes that are fundamental to the design of the Java programming language. ī‚´ The most important classes are Object, which is the root of the class hierarchy, and Class, instances of which represent classes at run time. ī‚´ Following are the Important Classes in Java.lang package : ī‚´ Boolean: The Boolean class wraps a value of the primitive type boolean in an object. ī‚´ Byte: The Byte class wraps a value of primitive type byte in an object. ī‚´ Character – Set 1, Set 2: The Character class wraps a value of the primitive type char in an object. ī‚´ Character.Subset: Instances of this class represent particular subsets of the Unicode character set. ī‚´ Character.UnicodeBlock: A family of character subsets representing the character blocks in the Unicode specification. ī‚´ Class – Set 1, Set 2 : Instances of the class Class represent classes and interfaces in a running Java application.
  • 5. Contâ€Ļ ī‚´ ClassLoader: A class loader is an object that is responsible for loading classes. ī‚´ ClassValue: Lazily associate a computed value with (potentially) every type. ī‚´ Compiler: The Compiler class is provided to support Java-to-native-code compilers and related services. ī‚´ Double: The Double class wraps a value of the primitive type double in an object. ī‚´ Enum: This is the common base class of all Java language enumeration types. ī‚´ Float: The Float class wraps a value of primitive type float in an object. ī‚´ InheritableThreadLocal: This class extends ThreadLocal to provide inheritance of values from parent thread to child thread: when a child thread is created, the child receives initial values for all inheritable thread-local variables for which the parent has values. ī‚´ Integer :The Integer class wraps a value of the primitive type int in an object. ī‚´ Long: The Long class wraps a value of the primitive type long in an object.
  • 6. Contâ€Ļ ī‚´ Math – Set 1, Set 2: The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. ī‚´ Number: The abstract class Number is the superclass of classes BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, and Short. ī‚´ Object: Class Object is the root of the class hierarchy. ī‚´ Package: Package objects contain version information about the implementation and specification of a Java package. ī‚´ Process: The ProcessBuilder.start() and Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. ī‚´ ProcessBuilder: This class is used to create operating system processes.
  • 7. Contâ€Ļ ī‚´ Math – Set 1, Set 2: The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. ī‚´ Number: The abstract class Number is the superclass of classes BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, and Short. ī‚´ Object: Class Object is the root of the class hierarchy. ī‚´ Package: Package objects contain version information about the implementation and specification of a Java package. ī‚´ Process: The ProcessBuilder.start() and Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. ī‚´ ProcessBuilder: This class is used to create operating system processes.
  • 8. Contâ€Ļ ī‚´ StringBuffer: A thread-safe, mutable sequence of characters. ī‚´ StringBuilder: A mutable sequence of characters. ī‚´ System: The System class contains several useful class fields and methods. ī‚´ Thread: A thread is a thread of execution in a program. ī‚´ ThreadGroup: A thread group represents a set of threads. ī‚´ ThreadLocal: This class provides thread-local variables. ī‚´ Throwable: The Throwable class is the superclass of all errors and exceptions in the Java language. ī‚´ Void: The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.
  • 9. Simple type wrappers ī‚´ A Wrapper class is a class whose object wraps or contains primitive data types. ī‚´ When we create an object to a wrapper class, it contains a field and in this field, we can store primitive data types. ī‚´ In other words, we can wrap a primitive value into a wrapper class object. ī‚´ Need of Wrapper Classes ī‚´ They convert primitive data types into objects. Objects are needed if we wish to modify the arguments passed into a method (because primitive types are passed by value). ī‚´ The classes in java.util package handles only objects and hence wrapper classes help in this case also.
  • 10. Contâ€Ļ. ī‚´ Data structures in the Collection framework, such as ArrayList and Vector, store only objects (reference types) and not primitive types. ī‚´ An object is needed to support synchronization in multithreading. ī‚´ Primitive Data types and their Corresponding Wrapper class
  • 11. Number,Double,float,byte,short,int, long,character,Boolean,process and void. ī‚´ int myNum = 5; // Integer (whole number) ī‚´ float myFloatNum = 5.99f; // Floating point number ī‚´ char myLetter = 'D'; // Character ī‚´ boolean myBool = true; // Boolean ī‚´ String myText = "Hello"; // String ī‚´ Data types are divided into two groups: ī‚´ Primitive data types - includes byte, short, int, long, float, double, boolean and char ī‚´ Non-primitive data types - such as String, Arrays and Classes
  • 12. There are eight primitive data types in Java: ī‚´ Data Type Size Description ī‚´ byte 1 byte Stores whole numbers from -128 to 127 ī‚´ short 2 bytes Stores whole numbers from -32,768 to 32,767 ī‚´ int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647 ī‚´ long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 ī‚´ float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits ī‚´ double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits ī‚´ boolean 1 bit Stores true or false values ī‚´ char 2 bytes Stores a single character/letter or ASCII values
  • 13. The Maths class ī‚´ Java Math class provides several methods to work on math calculations like min(), max(), avg(), sin(), cos(), tan(), round(), ceil(), floor(), abs() etc. ī‚´ Example 1 ī‚´ public class JavaMathExample1 ī‚´ { ī‚´ public static void main(String[] args) ī‚´ { ī‚´ double x = 28; ī‚´ double y = 4; ī‚´ ī‚´ // return the maximum of two numbers ī‚´ System.out.println("Maximum number of x and y is: " +Math.max(x, y));
  • 14. Contâ€Ļ ī‚´ // return the square root of y ī‚´ System.out.println("Square root of y is: " + Math.sqrt(y)); ī‚´ ī‚´ //returns 28 power of 4 i.e. 28*28*28*28 ī‚´ System.out.println("Power of x and y is: " + Math.pow(x, y)); ī‚´ ī‚´ // return the logarithm of given value ī‚´ System.out.println("Logarithm of x is: " + Math.log(x)); ī‚´ System.out.println("Logarithm of y is: " + Math.log(y)); ī‚´ ī‚´ // return the logarithm of given value when base is 10 ī‚´ System.out.println("log10 of x is: " + Math.log10(x)); ī‚´ System.out.println("log10 of y is: " + Math.log10(y));
  • 15. Contâ€Ļ. ī‚´ // return the log of x + 1 ī‚´ System.out.println("log1p of x is: " +Math.log1p(x)); ī‚´ ī‚´ // return a power of 2 ī‚´ System.out.println("exp of a is: " +Math.exp(x)); ī‚´ ī‚´ // return (a power of 2)-1 ī‚´ System.out.println("expm1 of a is: " +Math.expm1(x)); ī‚´ } ī‚´ }
  • 16. Java Utility and Collection Classes. ī‚´ Collections class in java is a useful utility class to work with collections in java. ī‚´ The java.util.Collections class directly extends the Object class and exclusively consists of the static methods that operate on Collections or return them. ī‚´ Collections Class in java ī‚´ Collections class contains polymorphic algorithms that operate on collections and “wrappers” — which return a new collection backed by a specified collection. It is a member of Java Collections Framework. ī‚´ Collections class fields ī‚´ Collections class contains 3 fields: EMPTY_LIST, EMPTY_SET, EMPTY_MAP, which can be used to get immutable empty List, Map and Set respectively.
  • 17. Example ī‚´ package utility; ī‚´ import java.util.Collections; ī‚´ import java.util.ArrayList; ī‚´ import java.util.List; ī‚´ public class CollectionsDemo { ī‚´ public static void main(String[] args) { ī‚´ List<String>student<String>List = new ArrayList(); ī‚´ studentList.add("Neeraj"); ī‚´ studentList.add("Mahesh"); ī‚´ studentList.add("Armaan"); ī‚´
  • 18. Contâ€Ļ. ī‚´ studentList.add("Preeti"); ī‚´ studentList.add("Sanjay"); ī‚´ studentList.add("Neeraj"); ī‚´ studentList.add("Zahir"); ī‚´ System.out.println("Original List " + studentList); ī‚´ Collections.sort(studentList); ī‚´ System.out.println("Sorted alphabetically List " + studentList); ī‚´ Collections.reverse(studentList); ī‚´ }
  • 19. Contâ€Ļ. ī‚´ System.out.println("Reverse List " + studentList); ī‚´ Collections.shuffle(studentList); ī‚´ System.out.println("Shuffled List " + studentList); ī‚´ System.out.println("Checking occurance of Neeraj: " ī‚´ + Collections.frequency(studentList, "Neeraj"));