Introduction to Java

What is Java?

Java is a **high-level, object-oriented programming language** designed to be **platform-independent**. It follows the **"Write Once, Run Anywhere" (WORA)** principle, meaning Java code can run on any system with a Java Virtual Machine (JVM).

Key Features of Java

  • Platform Independent: Java runs on multiple platforms via the JVM.
  • Object-Oriented: Supports classes, objects, inheritance, and polymorphism.
  • Secure: Provides built-in security features like bytecode verification.
  • Robust: Includes strong memory management and exception handling.
  • Multi-threaded: Supports concurrent programming.

Understanding JVM, JRE, and JDK

  • JVM (Java Virtual Machine): Executes Java bytecode on different operating systems.
  • JRE (Java Runtime Environment): Contains JVM + libraries needed to run Java applications.
  • JDK (Java Development Kit): Includes JRE + compilers and tools for Java development.

Writing a Simple Java Program

Let’s write our first **"Hello, World!"** Java program.

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

Explanation of the Code

  • public class HelloWorld - Defines a class named **HelloWorld**.
  • public static void main(String[] args) - The **main() method** is the entry point of a Java application.
  • System.out.println("Hello, World!"); - Prints "Hello, World!" to the console.

How to Compile and Run Java Code

Step 1: Save the File

Save the file as HelloWorld.java.

Step 2: Compile the Code

javac HelloWorld.java

Step 3: Run the Program

java HelloWorld

Conclusion

Java is a powerful and widely used programming language. This tutorial covered its basic introduction, features, and how to write and run a simple program.

📌 Next Topic: Java Variables and Data Types