Java is a class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is intended to let application developers Write Once and Run Anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java was developed by James Gosling at Sun Microsystems Inc. in May 1995 and later acquired by Oracle Corporation and is widely used for developing applications for desktop, web, and mobile devices.

<aside> 💡

Compiler and Interpreter

Java uses both compiler and interpreter. Java source code is converted into bytecode at compilation time. The interpreter executes this bytecode at runtime and produces output. Java is interpreted that is why it is platform-independent.

</aside>

public class GFG
{ 
    public static void main(String args[]) 
    { 
        System.out.println("Hello World"); 
    } 
}

Why Java platform independent?

Java is considered a platform-independent language because of its ability to run on any operating system or hardware environment that supports the Java Virtual Machine (JVM). This is achieved through the generation of bytecode during the compilation process.

What is Bytecode?

Bytecode is an intermediate, machine-independent representation of the source code, created after the Java compiler processes the program. Unlike traditional compiled languages, which generate machine-specific code, Java's bytecode is designed to be interpreted and executed by the JVM.

Bytecode.png

How Does it Work?

  1. Source Code Compilation:
  2. Execution by JVM:

Differences between JDK, JRE and JVM?

Understanding the difference between JDK, JRE, and JVM plays a very important role in understanding how Java works and how each component contributes to the development and execution of Java applications. The main difference between JDK, JRE, and JVM is:

Why Packages?

Packages in Java are essential for organizing code, managing dependencies, and maintaining scalability in projects. Here are the key reasons for using packages: