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");
ī´