Professional Documents
Culture Documents
Byte -> Short -> Char -> Int -> Long -> Float -> Double
->If the targeted value to be converted has a smaller length e.g. 4 bytes, to a
larger data type e.g. 8 bytes.
Double -> FLoat -> Long -> Int -> Char -> Short -> Byte
Features of JAVA
Object Oriented
In Java, everything is an Object. Java can be easily extended since it is based on the Object
model.
Platform Independent
Unlike many other programming languages including C and C++, when Java is compiled, it is
not compiled into platform specific machine, rather into platform-independent bytecode.
Simple
With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication
techniques are based on public-key encryption.
Robust
Java makes an effort to eliminate error-prone situations by emphasising mainly on compile time
error checking and runtime checking
Multithreaded
With Java's multithreaded feature it is possible to write programs that can perform many tasks
simultaneously. This design feature allows the developers to construct interactive applications
that can run smoothly.
High Performance
What is JDK,JRE.JIT,JVM
JAVA DEVELOPMENT KIT (JDK)
Java Development Kit The Java Development Kit (JDK) is a software development
environment used for developing Java applications. It includes the Java Runtime Environment
(JRE), an interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation
generator (Javadoc) and other tools needed in Java development.
The Java Runtime Environment provides the minimum requirements for executing a Java
application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files.
Helps interpreter to execute JAVA byte code.Basically improves performance of JAVA program
execution.
-> Loading : The Class loader reads the .class file, generate the corresponding binary data and
save it in method area. After loading .class file, JVM creates an object of type Class to represent
this file in the heap memory.
• Bootstrap class loader- Responsible for loading .class file from RT.jar and saving in memory.
• Extension class loader : It is child of bootstrap class loader. Responsible for loading the
additional class file say from JRE,LIB or from EXT folder.
• Preparation : JVM allocates memory for class variables and initializing the memory to default
values.
• Resolution : It is the process of replacing symbolic references from the type with direct
references.
-> Initialization : In this phase, all static variables are assigned with their values defined in the
code
JVM needs memory area to store class file.This run time data areas has many types of memories
like method area,heap memory area,stack memory area,PC register,native memory.
Method area : In method area, all class level information like class name.
Stack area : For every thread, JVM create one run-time stack which is stored here.
Native method stacks : For every thread, separate native stack is created. It stores native method
information.
3) Execution Engine
Execution engine execute the .class (bytecode). It reads the byte-code line by line, use data and
information present in various memory area and execute instructions. It can be classified in
three parts :-
• Interpreter : It interprets the bytecode line by line and then executes. The disadvantage here
is that when one method is called multiple times, every time interpretation is required.
Class Types
In Java, the class is a blueprint from which we can create an individual object. Java
provides a keyword named class by which we can declare a class. Inside the class, we
define class members and functions. It is not possible to create Java programs without
class.
1. Final Class
When a variable, function, or class is declared final, its value persists throughout the
program. Declaring a method with the final keyword indicates that the method cannot be
overridden by subclasses.
2. Static Class
Static is a Java word that explains how objects are kept in memory.A static class has
only static members. An object cannot be created for a static class.
3. Abstract Class
A class that has zero or more abstract methods and is specified with the abstract
keyword is called an abstract class. We must rigorously extend the abstract classes to a
concrete class in order to use them because they are incomplete classes.
4. Concrete Class
A normal class with an implementation for all of its methods and no abstract methods is
called a concrete class.
5. POJO Class
A Plain Old Java Object class has only private variables with setter and getter methods
to access them.
7. Inner Class
We can define a class within a class in Java, and these classes are referred to as
nested classes.
Constructor Types
A constructor in Java is similar to a method that is invoked when an object of the class
is created.A constructor has the same name as that of the class and does not have any
return type
Test() {
// constructor body
• No-Arg Constructor
• Parameterized Constructor
Constructor Chaining
Constructor chaining is the process of calling one constructor from another constructor
with respect to current object.
One of the main use of constructor chaining is to avoid duplicate codes while having
multiple constructor (by means of constructor overloading) and make code more
readable.
• Within same class: It can be done using this() keyword for constructors in the
same class
• From base class: by using super() keyword to call the constructor from the
base class.
• The this() expression should always be the first line of the constructor.
• There should be at-least be one constructor without the this() keyword
(constructor 3 in above example).
• Constructor chaining can be achieved in any order.
WRAPPER CLASS
A Wrapper class is a class which contains the primitive data types (int, char, short, byte,
etc). In other words, wrapper classes provide a way to use primitive data types (int,
char, short, byte, etc) as objects. Autoboxing
and unboxing feature convert primitives into objects and objects into primitives
automatically. The automatic conversion of primitive into an object is known as
autoboxing and vice-versa unboxing.
boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double
Data Abstraction
Data abstraction is the process of hiding certain details and showing only
essential information to the user.Abstraction can be achieved with abstract
classes The
abstract keyword is a non-access modifier, used for classes and methods:
• Abstract class: is a restricted class that cannot be used to create objects (to
access it, it must be inherited from another class).
• Abstract method: can only be used in an abstract class, and it does not have a
body. The body is provided by the subclass (inherited from).
Primitive types are the basic types of data: byte, short, int, long, float, double, boolean,
char. Primitive variables store primitive values.
Reference types are any instantiable class as well as arrays: String, Scanner, Random,
Die, int[], String[], etc. Reference variables store addresses to locations in memory for
where the data is stored.