What is JDK?
JDK stands for Java Development Kit. From the name, we can understand that it is mainly used for development purposes. We can develop java programs and use JDK to compile and run them.
Let’s see what all the contents inside JDK are.
Inside JDK we have the following:
- Java Runtime Environment(JRE) and other tools like
- jar and so on.
- javac – It is the compiler that compiles.java file to the .class file.
Eg. javac Sample.java
- java – It is the interpreter which runs the program using the class file generated after compiling.
Eg. java Sample
- javadoc – It is used to generate documentation from the source code in HTML format.
- jar – Compresses all files related to a java application into a single unit.
Platform independence: JDK is platform specific as we can notice that we have different installation instructions for different platforms while trying to download JDK.
What is JRE?
It stands for Java Runtime Environment (ie) it acts as an environment for the java programs to execute. It serves what all a java program needs, in order to run smoothly.
It contains JVM (Java Virtual Machine) and other libraries like
- lang etc.
It basically has the runtime libraries which get imported whenever a java program asks for them.
Other than that, it has AWT (Abstract Window Toolkit), and Swing libraries for creating User Interfaces(UI).
In addition to that, it has several integration libraries like
- Remote Invocation Method (RMI)
- Java Database Connectivity (JDBC)
- Java Naming and Directory Interface (JNDI).
- Most of the maths operations, input, and output operations are performed with the help of the inbuilt methods in the collection classes.
- User Interfaces are built with Java using libraries like Swing, and AWT.
- In addition to that, we can also perform networking and database activities with the respective libraries.
Platform independence: It is not platform independent.
What is JVM?
- It stands for Java Virtual Machine. By virtual machine, it creates an interface between the system’s hardware and the java program.
- It is because of this JVM, that Java is platform independent because for each java program a JVM is created and all the class files and libraries are imported into the memory.
It doesn’t contain any tools specifically, it’s mainly concerned with memory management activities. It is not available separately, it’s always installable along with JRE.
- It mainly acts as a memory management unit to perform memory-related activities like garbage collection etc.
- Its main function is to talk with the underlying hardware about the usage of its resources to execute the program.
Platform independence: It is platform independent.
Then how is Java Platform Independent?
Neither JDK, JRE, nor JVM is platform independent, but Java as a whole is platform independent. That’s because the bytecode that is generated after compilation is the same for every machine. It is the JVM that executes the bytecode using the resources of the system-specific hardware underhood, to run the program thus making it platform independent.