What is Java?

Java is a programming language and a platform.

Java is a high-level, robust, secured and object-oriented programming language.

Platfom: Any hardware or software environment in which a program runs, is known as a platform. Since Java has its own runtime environment (JRE) and API,  it is called platform.

ByteCode :
The output of a Java compiler is not a executable but it is a bytecode. ByteCode is a highly optimized set of instructions designed to be executed by the Java run-time system, which is Java virtual machine (JVM).

Translating a Java program into byte code makes it much easier to port it to different environments since we need JVM to be implemented for whatever platform we intend the program to run.

Although the details of JVM may differ from environment to environment, all understand the same byte code.

If a Java program was not compiled to byte code but was instead compiled to native executable code, then we would have to create different executable versions of the same programs based on environments(OS) as well as based on CPU types.

Each Java program runs in its own JVM, so it also makes it secure. It does not have any side effects on the outside system.

In general, when a program is compiled into intermediate form (bytecode) and then interpreted at runtime by the JVM, it runs slower than it would run if compiled to native code.

However, the byte code has been highly optimized, so it works faster than expected.

Also, Hotspot technology was release soon after Java release. It provides a Just-in-time (JIT) compiler for byte code. (The same happens for MS .net code. Code is compiled to MSIL and then JIT compiles it to native code).

So, when JIT compiler is part of JVM, selected portions of bytecode are compiled to executable code in real time, on a piece by piece, demand basis.  This gives a significant performance boost.

What are JDK, JRE, JVM ?
JVM(Java Virtual Machine) is a specification or a abstract machine. It provides runtime environment in which java bytecode can be executed.

JVMs are available for many hardware and software platforms. Basically Java is platform-independent but JVM, JRE and JDK are platform-dependent.

The JVM mainly does the following tasks :
1. Loads code
2. Verifies code
3. Executes code
4. Provides runtime environment

There are different implementations available like oraclejdk and openjdk.

JRE(Java Runtime Environment) is implementation of JVM. It is physical. It contains set of libraries + other libraries that JVM uses at runtime.

jre

JDK(Java Development Kit) contains JRE + development tools.

jdk

Comments

Popular posts from this blog

Collection Framework - HashSet And LinkedHashSet class

Collection Framework - Cursors in Java

Hashed data structures