Presentation on theme: "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."— Presentation transcript:
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?
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.
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.
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.
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.
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.
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.
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.
Features of Java There is given many features of java.
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.
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
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.
4) Secured No explicit pointer, Programs run inside virtual machine sandbox. Classloader, Bytecode Verifier & Security Manager.
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.
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.
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.
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.