What is Java? JDK, JRE and JVM
Java is a programming language and also a platform. When people say “Java” they can mean the language (the code you write), or the whole platform (the tools and the runtime which run your code).
How a Java program runs
- You write the code in a text file with the extension
.java(the source code). - The compiler (
javac) checks the code and changes it into bytecode, saved in a.classfile. - The JVM (Java Virtual Machine) reads the bytecode and runs it on your computer.
Because the bytecode is the same everywhere, and every system has its own JVM, the same .class file can run on any operating system.
Let us see it
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Terminal
$ javac Hello.java
$ ls
Hello.class
Hello.java
$ java Hello
Hello, Java!
The compiler made Hello.class, and the java command started the JVM and ran it.
JDK, JRE and JVM
| Name | Full name | What it is |
|---|---|---|
| JVM | Java Virtual Machine | Runs the bytecode. It also does memory management (garbage collection) |
| JRE | Java Runtime Environment | The JVM plus the standard libraries, needed to run Java programs |
| JDK | Java Development Kit | The JRE plus the developer tools: javac compiler, jar, javadoc and more |
To write Java programs you need the JDK. Modern downloads of Java come as a JDK, so you get everything in one install.
Main features of Java
- Object oriented: the code is organized in classes and objects.
- Platform independent: bytecode runs on any JVM.
- Strongly typed: every variable has a type, and the compiler checks it.
- Automatic memory management: the garbage collector frees the memory which is not used anymore. You do not use
free()like in C. - Multi threaded: programs can do many jobs at the same time.
- Secure and robust: no pointer arithmetic, and good error handling with exceptions.
Java editions
- Java SE (Standard Edition): the core language and libraries. This tutorial teaches it.
- Jakarta EE (Enterprise Edition): extra APIs for big web and enterprise applications.
- Java ME: an old edition for small devices, rarely used now.
Note:
Java is not the same as JavaScript. They have a similar name, but they are different languages with different uses. See the difference between Java and JavaScript. Next: Java Install and Setup.
Congratulations! Chapter Finished. Learn more about the similar topics:
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |