Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code...
If you can't read please download the document
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment
Objective In this session you will learn : What is Class Loader
? What is Byte Code Verifier? JIT & JAVA API Features of Java
Java Environment Setup How to set path in Java What is Life Cycle
of Java?
Slide 3
What is Class Loader ? Classloader is a subsystem of JVM that
is used to load class files at runtime. A class loader is an object
that is responsible for loading classes. The ClassLoader is an
abstract class. Given the binary name of a class A typical strategy
is to transform the name into a file name and then read a "class
file" of that name from a file system.
Slide 4
Continue... ClassLoader in Java works on three principle:
delegation, visibility and uniqueness. Delegation Delegation
principle forward request of class loading to parent class loader
and only loads the class, if parent is not able to find or load
class. Visibility Visibility principle allows child class loader to
see all the classes loaded by parent ClassLoader, but parent class
loader can not see classes loaded by child. Uniqueness Uniqueness
principle allows to load a class exactly once, which is basically
achieved by delegation and ensures that child ClassLoader doesn't
reload the class already loaded by parent.
Slide 5
Example
Slide 6
How to load class explicitly in Java? Java provides API to
explicitly load a class by Class.forName(class name) and
Class.forName(class name, initialized, classloader). JDBC code
which is used to load JDBC drives we have seen in Java program to
Connect Oracle database.
Slide 7
What is Byte Code Verifier? The JVM verifies all bytecode
before it is executed. This verification consists primarily of
three types of checks: 1.Branches are always to valid locations
2.Data is always initialized and references are always type-safe
3.Access to private or package private data and methods is rigidly
controlled The first two of these checks take place primarily
during the verification step that occurs when a class is loaded and
made eligible for use. The third is primarily performed
dynamically, when data items or methods of a class are first
accessed by another class.
Slide 8
Bytecode interpreter and just-in-time compiler For each
hardware architecture a different Java bytecode interpreter is
needed. When a computer has a Java bytecode interpreter, it can run
any Java bytecode program, and the same program can be run on any
computer that has such an interpreter. A just-in-time compiler may
translate Java bytecode into native machine language while
executing the program. The translated parts of the program can then
be executed much more quickly than they could be interpreted. This
technique gets applied to those parts of a program frequently
executed. This way a just-in-time compiler can significantly speed
up the overall execution time. Java bytecode is intended to be
platform-independent and secure.
Slide 9
JIT A Just-In-Time (JIT) compiler is a feature of the run-time
interpreter, that instead of interpreting bytecode every time a
method is invoked, will compile the bytecode into the machine code
instructions of the running machine, and then invoke this object
code instead. Ideally the efficiency of running object code will
overcome the inefficiency of recompiling the program every time it
runs.
Slide 10
Continue...
Slide 11
JAVA API By default JAR File loaded by Class Loader By default
Java Package used by all classes An API (Application Programming
Interface) is a collection of packages, a package is the collection
of classes, interfaces and sub-packages. A sub-package is a
collection of classes interfaces and sub sub packages etc.
Slide 12
Features of Java There is given many features of java.
Slide 13
1)Simple According to Sun, Java language is simple because:
syntax is based on C++ (so easier for programmers to learn it after
C++). Removed many confusing and/or rarely-used features e.g.,
explicit pointers, operator overloading etc. No need to remove
unreferenced objects because there is Automatic Garbage Collection
in java.
Slide 14
Comparison Table of Features(C,C++& Java)
Slide 15
2)Object-oriented Object-oriented means we organize our
software as a combination of different types of objects that
incorporates both data and behaviour. Object Class Inheritance
Polymorphism Abstraction Encapsulation
Slide 16
3) Platform Independent A platform is the hardware or software
environment in which a program runs. There are two types of
platforms software-based and hardware-based. Java provides
software-based platform.
Slide 17
4) Secured No explicit pointer, Programs run inside virtual
machine sandbox. Classloader, Bytecode Verifier & Security
Manager.
Slide 18
5) Robust Robust simply means strong. Java uses strong memory
management. There is automatic garbage collection in java. There is
exception handling and type checking mechanism in java. All these
points makes java robust.
Slide 19
6) Architecture-neutral Architecture represents processor. A
Language or Technology is said to be Architectural neutral which
can run on any available processors in the real world without
considering there architecture and vendor (providers) irrespective
to its development and compilation. The languages like C, CPP are
treated as architectural dependent.
Slide 20
7) Portable A portable language is one which can run on all
operating systems and run on all processors without considering
their vendors and architectures. JAVA is a portable language.
Slide 21
8)High-performance
Slide 22
9)Multithreaded A flow of control is known as thread. When any
Language execute multiple thread at a time that language is known
as multithreaded Language.
Slide 23
10)Distributed We can create distributed applications in java.
RMI and EJB are used for creating distributed applications.
Slide 24
Java is very powerful ? Java is very powerful language can be
used to developed both client server architecture and distributed
architecture based application.
Slide 25
Continue...
Slide 26
Java Environment Setup
Slide 27
Continue... Javac is a tool which is available in bin folder so
you must set the PATH upto bin folder. In a bin folder all tools
are available like javap, javah, jar, javac, java, appletviewer
etc. These all tools are used for different-different purpose.