JVMJDKJRE

Tuesday, March 31, 2009

Topics covered

JVM
JDK
JRE
Class Files


What is JVM?
It’s the short form of Java Virtual Machine. It is a program that interprets the bytecode of class files in to the native( machine ) code. The Java virtual machine knows nothing of the Java programming language, only of a particular binary format, the class file format.

Why JVM is called a virtual machine and not by some other name.
JVM is called Java Virtual Machine because it doesn’t exist physically. It is a virtual thing which performs some action. That’s why it is named virtual machine.

Is JVM platform-dependant.
Yes JVM is platform dependent. Only Java is platform independent

Why can't we have the same JVM across all the OS’s.
JVM acts as a interface between your program and the operating system. It would be impossible to have one JVM for all operating systems because the JVM relies on operating system calls to provide many of the facilities which Java programs use. The JVM exposes a consistent interface to Java programs but it has to adapt those services to the actually operating system underneath. Moreover the CPU instruction sets vary wildly from OS to OS.

Is both JVM and 'Java' (JDK Tool) same ?
No, they are different things. The JDK (SDK) is the place to CODE applications and compile them to byte codes. The JVM can be built into a Computer, Browser (or computer chip in your car, or in a thermostat, or in your cell phone or whatever) and takes already compiled code(byte code) and executes it.
We use JRE (Java Runtime Environment) to execute compiled code outside of an browser(JVM), at the operating system.

In which language java compiler and JVM was written?
They can be written in any decent language like C, C++ or Java.
The point is that a JVM can be written by anyone. Sun maintains the specifications (rules that must be followed) and other companies follow the specifications when creating a JVM for their product. I would guess that the JVM in Internet Explorer, since it is a Microsoft Product, is written in Visual Basic.


What’s the difference between loading the class and instantiating the class.

Class c = Class.forName("com.raverun.foo");

Pulling in byte codes from storage (i.e. network, local hard drive) into the current JVM. Loading classes means just only Loading them. Usually this task is carried out by default Class Loader or you can define your own class loader to load it.

Instantiating a class means creating an Object in the Heap.

MyClass class = new MyClass();

Note: When a class is loaded, it loads all the static data too.

What is JDK. Why we need it?
To write a java program with java syntax you need to have a Java Development Kit (JDK) installed in your computer. When you install the JDK, you get the compiler which is used to compile the java program(.java) into a class file(.class).

When you install the JDK, you also get Java Runtime environment(JRE) which is required to actually run the program.

What is a class file? What is it comprised of?
You get a class file when you compile a java code. It contains Java virtual machine instructions (or bytecodes) and a symbol table, as well as other ancillary information.

What is JRE?
The JRE (Java Runtime Environment) is the equivalent of a JVM but for running applications outside of a browser (like from the DOS prompt). When you run an applet or servlet it is running in a built-in JVM in the browser.

JVM is a part of JREJDK = Java API + Java Compiler + JRE

JRE = Entire environment (including the JVM) necessary for running Java applications (this includes classes, native code, etc). &JVM = CLASS LOADER + BYTE CODE CHECKER + INTERPRETER + SECURITY MANAGER + GARBAGE COLLECTOR In simple words JRE provides the environment to run Java applications and implicitly JVM is also a part of it.

0 comments:

Post a Comment