JVM is a specification which specifies the working of Java Virtual Machine which is an abstract machine. The Java Virtual Machine or JVM is an environment that provides execution of Java programs.
The code written in Java is compiled into an intermediate code which is known as the bytecode. The bytecode is the one that is executed by JVM. Any code which has been compiled into the bytecode can run on any system that has JVM installed on it.
Also Read:- How to build your career as a Java developer?
This is why Java is said to be platform independent as any system that has JVM installed in it can run Java code. JVM has some considerable advantages and disadvantages that a developer should be aware of before starting development using Java programming language.
Advantages of Java Virtual Machine
Java Virtual Machine (JVM) has some not advantages, which are, as follows:
- Ensures Security
When Java was initially developed, security was the priority. That is the reason why Java programs run separated in an enclosed area of the Java Virtual Machine which acts as a protecting shield.
Java Virtual Machine allows developers to write Java programs that are highly secure with help of its built-in security features.
Java Virtual Machine keeps the Operating System secure by preventing any malicious software from attacking it. It ensures its safety by not allowing the Java applications to interact with the Operating System resources.
2. Cross Platform
A program that is Cross platform has the capability to run successfully on different types of hardware. Java is also a cross platform language i.e. it is possible to run a single piece of code written on a particular hardware on any other hardware that has JVM installed on it.
Therefore, JVM makes Java a cross platform language. A browser is not always needed for a Java program to execute, there are many java apps available too for the same. They run on the desktop the same way as the regular programs do.
3. Just-in-time compiler
The Java Virtual Machine comes with a Just-in-time compiler which converts the Java code into a low level machine language that can run as fast as the regular applications.
This compiled code goes into the cached memory of the browser, this means that one can use the code again without downloading it again and again compiling it.
Disadvantages of Java Virtual Machine
Although, Java Virtual Machine has notable advantages, it comes with many disadvantages also.
- Platform specific features
Java cannot be used without Java Runtime Environment being installed on your system. So in order to start coding in Java, firstly you need to install the latest version of Java Virtual Machine.
Because of JVM running on several Operating Systems, there is a possibility that JVM does not have a feature that is specific to that particular operating system. Therefore, there can be any feature that does not look the same way as it did on some other operating system.
2. Speed
In a Java Virtual Machine, the code is first converted into bytecode and then the bytecode is converted into the machine code for the system to finally run it.
Therefore, this is the reason why the Java Virtual Machine tends to work slower and hence making a Java code run slower when compared to its equivalent C or C++ code. The compilation to bytecode that helps the code to run on any platform eventually turns out to be a disadvantage when performance is concerned.
Java bytecode is system neutral and optimization of the same according to any specific hardware set is not possible. The reason behind this is that for a code to get optimize system specific features are the necessity and since the bytecode is system neutral it is not possible to optimize it.
Just like a real computing machine, Java Virtual Machine too manages the memory space and processes instructions. Therefore, the Java Virtual Machine is responsible for almost everything in running a Java program.
A Java code is completely dependent on the Java Virtual Machine which makes it platform dependent and itself is platform dependent. Thus, before proceeding towards Java development one should have the basic idea of what is a Java Virtual Machine.