Ques:-What is Java Virtual Machine?
Ans:- Java Virtual Machine
JVM is the main component of Java architecture and it is the part of the JRE (Java Runtime Enviroment) . It provides the cross platform functionality to java. This is a software process that converts the compiled Java byte code to machine code. Byte code is an intermediary language between Java source and the host system. Most programming language like C and Pascal converts the source code into machine code for one specific type of machine as the machine language vary from system to system . Mostly compiler produce code for a particular system but Java compiler produce code for a virtual machine . JVM provides security to java.
The programs written in Java or the source code translated by Java compiler into byte code and after that the JVM converts the byte code into machine code for the computer one wants to run. JVM is a part of Java Run Time Environment that is required by every operating system requires a different JRE .
The architecture of the JVM is given below . This architecture tell us how the JVM works . Firstly we write the simple java program(source code) the java compiler converts the source code into the bytecode , after that JVM reads this bytecode and converts this into the machine code.
Ques 2:- JVM provides portability explain..?
Ans:- Implementations of java specification for a variety of CPUs and architectures provides the feature of portability. Foremost, without the availability of a JRE for a given environment, it is impossible to run Java software. JVM forms the part of large system i.e. the Java Runtime Environment (JRE). Each operating system and CPU architecture requires a JRE. JRE consists of a set of base classes i.e. an implementation of the base Java API as well as a JVM. The byte code format is same on all platforms as it runs in the same JVM and it is totally independent from the Operating System and the CPU architecture.
JVM is java interpreter as it converts the byte code into machine code for the computer one wants to run.
JRE consists of a number of classes based on JavaAPI and JVM, and without JRE, it is impossible to run Java. So its portability really made it possible in developing write once and run anywhere software .
How to write First Java program
Create a simplest java program :
public class MyFirstProgram
public static void main(String arr )
System.out.println(" I am creating my first java program");
Save the file with same name as the public class just adding the extension ?.java? e.g. MyFirstProgram.java.
Now compile as:
c:\ javac MyFirstProgram.java
This creates a class file in with the same name, This is the bytecode form of Java program.
Now to execute this code:
c:\ java MyFirstProgram
I am creating my first java program
Ques 3: - Memory Management with JVM ?
Ans:- Memory Management with JVM :-
the Java language in combination with runtime eliminates the problems of memory management and corrupted pointers.
There is no explicit allocation of memory in Java, memory is allocated only to objects.
JVM's heap stores all objects created.
JVM ask the operating system for enough memory to run the JVM itself and some free memory for the application to create new objects.
If the free memory area is getting too small, the JVM will ask the operating system for more and if there is no more additional memory available from the operating system, then JVM stops the application and issues the "Out of memory error".
The Java runtime employs a garbage collector to reclaim the memory occupied by an object.
Ques 4: Difference amongst JVM
Specification, JVM Implementation, JVM Runtime.
I. Java Virtual Machine Specification
JVM Specification = Java programming
language + Java Virtual Machine architecture + Java class-file format.
1. Java Programming Language
Java Programming Language is a developed by Sun MicroSystems.
Programming languages, like natural language follow the syntactic and semantic rules. Java programming language has some form of written specification of syntax and semantics; which are defined only through the sun's official implementation. Java language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode which run on any Java Virtual Machine regardless of any computer architecture.
2. Java Virtual Machine architecture
Java Virtual Machine is responsible for interpreting Java bytecode, and translating it into actions or operating system calls. JVM is the main component of Java architecture and it is the part of the JRE (Java Runtime Enviroment). The Java Virtual Machine provides a platform-independent way of executing code, by abstracting the differences between operating systems and CPU architectures.
3. Java class-file format:
Programs written in Java (source code) are translated by Java compiler into byte code and after that the JVM converts the byte code into machine code for the computer one wants to run. This class file format makes java a portable language.
II JVM Implementation:
Though implementations of Java Virtual Machines are designed to be compatible, no two JVMs are exactly alike. For example, garbage collection algorithms vary from one JVM to another, so it becomes impossible to know exactly when memory will be reclaimed. The thread scheduling algorithms are different between one JVM and another , so that it is impossible to accurately predict when one thread will be executed over another.
We have multiple implementations of JVM Specifications defined by Sun Microsystems like:
(i) Java HotSpot VM: developed by Sun Microsystems.
There are two implementations of the Java HotSpot VM:
The main differences of the two implementations are:
(ii) JRockit JVM : developed by BEA Systems
III. JVM Runtime:
The Java Virtual Machine is responsible for interpreting Java bytecode, and translating further the obtained code into actions or operating system calls. For example, a request to establish a socket connection to a remote machine will involve an operating system call. Different operating systems handle sockets in different ways - but the programmer doesn't need to worry about such details. It is the responsibility of the JVM to handle these translations, so that the operating system and CPU architecture on which Java software is running is completely irrelevant to the developer.
JVM Runtime Environment contains the two parts such as:
Java API classes: Java API classes are the predefined classes required for the program compilation and interpretation.
Java Virtual Machine: JVM is also a part of the JRE. The Java Virtual Machine is responsible for interpreting Java bytecode, and translating this into actions or operating system calls .
Implementations of java specification for a variety of CPUs and architectures provides the feature of portability. Foremost, without the availability of a JRE for a given environment, it is impossible to run Java software. JVM forms the part of large system i.e. the Java Runtime Environment (JRE). Each operating system and CPU architecture requires a JRE. JRE consists of a set of base classes i.e. an implementation of the base Java API as well as a JVM.
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial