- This topic clears your questions like Explain jvm architecture in java , jvm architecture in java with diagram, how JVM works internally and areas of Java Virtual Machine.
- Virtual machine : In general terms Virtual machine is a software that creates an environment between the computer and end user in which end user can operate programs.
- As per functionality Virtual machine is creation of number of different identical execution environments on a single computer to execute programs is called Virtual machine.
- Java Virtual machine: it is also Virtual machine that runs java bytecode by creating five identical run time areas to execute class members.
Function of java virtual machine
- The bytecode is generated by java compiler in a JVM understandable format.
- As a programmer we develop a java application and when we compile a java program, the compiler will generate .class (dot class) file.
- The .class file contains byte code (Special java instructions).
- To execute a java program we take the help of JVM (java virtual machine) to the JVM we have to provide .class file as the input.
Types of JVMs:
- The java 2 SDK , Standard Edition , contains two implementation of the java virtual machine
- Java HotSpot Client VM
- Java Hotspot Server VM
Java HotSpot Client VM:
- The Hotspot Client VM is the default virtual machine of the java 2 SDK and java 2 run time environment .
- As its name implies, it is tuned for best performance when running applications in a client environment by reducing application start up time and memory footprint.
Java HotSpot Server VM:
- The java HotSpot server VM is designed for maximum program execution speed for applications running in a server environment.
- The Java HotSpot Server VM is invoked by using the server command line option when an application , as in java server MyApp.
- Some of the features java HotSpot technology , common to both VM implementations, are the following.
- Applications are launched using a standard interpreter, but the code is then analyzed as it runes to detect performance bottlenecks, or "hot spots".
- The Java HotSpot VMs compile those performance critical portions of the code for a boost in performance , while avoiding unnecessary compilation of seldom used code.
- The Java HotSpot VMs also uses the adoptive compiler to decide on the fly , how best to optimize compiled code with techniques such as in lining.
- The run time analysis performed by the compiler allows it to eliminate guesswork in determining which optimizations will yield the largest performance benefit.
Rapid memory allocation garbage collection:
- Java HotSpot technology provides for rapid memory allocation for objects , and it has a fast, efficient, state-of-the-art garbage collector.
- The Java programming language allows for use of multiple , concurrent paths of program execution (called threads).
- Java HotSpot technology provides a thread- handling capability that is designed to scale readily for use in large , shared memory multiprocessor servers.
Jvm architecture in java with diagram
Class Loader Sub System:
- The class loader sub system will take a .class file as the input and performance the following operations.
- The class loader sub system is responsible for loading the .class file (Byte code) into the JVM.
- Before loading the Byte code into the JVM it will verify where there the Byte code is valid or not. This verification will be done by Byte code verifier.
- If the Byte code is valid then the memory for the Byte code will be allocated in different areas.
- The different areas into which the Byte code is loaded are called as Run Time Data Areas. The various run time data areas are.
- Java Virtual Machine Method Area can be used for storing all the class code and method code.
- All classes bytecode is loaded and stored in this run time area , and all static variables are created in this area.
- JVM Heap Area can be used for storing all the objects that are created.
- It is the main memory of JVM , all objects of classes :- non static variables memory are created in this run time area.
- This runtime area memory is finite memory.
- This area can be configured at the time of setting up of runtime environment using non standard option like
- java -xms <size> class-name.
- This can be expandable by its own , depending on the object creation.
- Method area and Heap area both are sharable memory areas.
3.Java Stack area:
- JVM stack Area can be used for storing the information of the methods. That is under execution. The java stack can be considered as the combination of stack frames where every frame will contain the stat of a single method.
- In this runtime area all Java methods are executed.
- In this runtime JVM by default creates two threads. they are
- 1.main method
- 2.Garbage Collection Thread
- main thread responsible to execute java methods starts with main method.
- Also responsible to create objects in heap area if its finds new keyword in any method logic.
- Garbage collection thread is responsible to destroy all unused objects from heap area.
4.PC Register (program counter) area:
- The PC Register i Java Virtual Machine will contain address of the next instruction that have to be executed.
5.Java Native Stack:
- Java native stack area is used for storing non-java coding available in the application. The non-java code is called as native code.
- The Execution Engine of JVM is Responsible for executing the program and it contains two parts.
- JIT Compiler (just in time compiler).
- The java code will be executed by both interpreter and JIT compiler simultaneously which will reduce the execution time and them by providing high performance. The code that is executed by JIT compiler is called as HOTSPOTS (company).
- Java Program to Print prime numbers?
- What happens if we place return statement in try catch blocks
- Write a java program to convert binary to decimal
- Java Program to convert Decimal to Binary
- Is it possible to print message without using System.out.println()
- Java program to restrict a class from creating not more than three objects
- Java basic interview programs on this keyword
- Java Program to Sort elements of Java ArrayList Example
- Interfaces allows constructors?
- Can we create static constructor in java
- Super keyword interview questions java
- Java interview questions on final keyword
- Can we create private constructor in java
- Java Program Find Second highest number in an integer array
- Java interview programming questions on interfaces
- Top 15 abstract class interview questions
- Java interview Questions on main() method
- Sort employee object by id in descending order using comparable and TreesSet
- Top 20 collection framework interview Questions
- Java Interview Program to find smallest and second smallest number in an array
- Java Coding Interview programming Questions : Java Test on HashMap
- Explain java data types with example programs
- How to check internet connection using java
- Constructor chaining in java with example programs
- Top 10 Interview Programs and questions on method overriding in java
- Swap two numbers without using third variable in java
- Find sum of digits in java
- How to create immutable class in java
- AtomicInteger in java
- Check Even or Odd without using modulus and division
- String Reverse Without using String API
- Find Biggest substring in between specified character
- Check string is palindrome or not?
- Reverse a number in java?
- Fibonacci series with Recursive?
- Fibonacci series without using Recursive?
- Sort the String using string API?
- Sort the String without using String API?
- what is the difference between method overloading and method overriding?
- How to find largest element in an array with index and value ?
- Sort integer array using bubble sort in java?
- Object Cloning in java example?
- Method Overriding in java?
- Program for create Singleton class?
- Print numbers in pyramid shape?
- Check armstrong number or not?
- Producer Consumer Problem?
- Remove duplicate elements from an array
- Convert Byte Array to String
- Print 1 to 10 without using loops
- Add 2 Matrices
- Multiply 2 Matrices
- How to Add elements to hash map and Display
- Sort ArrayList in descending order
- Sort Object Using Comparator
- Count Number of Occurrences of character in a String
- Can we Overload static methods in java
- Can we Override static methods in java
- Can we call super class static methods from sub class
- Explain return type in java
- Can we call Sub class methods using super class object?
- Can we Override private methods ?
- Basic Programming Questions to Practice : Test your Skill
- Java programming interview questions on collections