Introduction to Java

Java is a high-level, object-oriented, and platform-independent programming language. It is one of the most popular languages used for building web, mobile, and enterprise applications.

What is Java?

Java is a high-level, object-oriented, and platform-independent programming language. It is widely used for building web applications, Android apps, enterprise systems, automation tools, cloud applications, and more.

Java follows the principle of WORA (Write Once, Run Anywhere). This means once your program is compiled into bytecode, it can run on any device that has a Java Virtual Machine (JVM), regardless of operating system or hardware.

Features of Java

  • Simple: Designed to be easy for beginners. Java removes complex concepts like pointers and manual memory management.
  • Object-Oriented: Java is built around classes and objects, making it easy to model real-world problems.
  • Platform Independent: Java code is compiled into bytecode that can run on any platform with a JVM.
  • Secure: Java applications run inside a virtual machine with restricted access, reducing security risks.
  • Robust: Java has strong memory management, automatic garbage collection, and powerful exception handling.
  • Multithreaded: Java can perform multiple tasks simultaneously, which is useful for games, animations, or background tasks.

JVM, JRE, and JDK – Differences Explained

The three core components of Java are:

AcronymFull FormRole
JDKJava Development KitIncludes development tools like compiler (javac), debugger, and also contains JRE.
JREJava Runtime EnvironmentAllows you to run Java applications; contains JVM + core libraries.
JVMJava Virtual MachineExecutes Java bytecode and converts it into machine code understood by your OS.
                 ┌──────────────┐
                 │     JDK      │  ← Development Tools + JRE
                 └──────┬───────┘
                        │
                 ┌──────┴───────┐
                 │     JRE      │  ← JVM + Libraries
                 └──────┬───────┘
                        │
                 ┌──────┴───────┐
                 │     JVM      │  ← Executes Java Bytecode
                 └──────────────┘

How Java Code Runs (Execution Flow)

Every Java program goes through these steps:

  1. Writing the Program: You create a source code file ending with .java.
  2. Compilation: The Java compiler (javac) converts your source code into bytecode stored in a .class file.
  3. Execution: The JVM loads the bytecode, verifies it for safety, translates it into machine code, and executes it.
Source Code (.java) 
       ↓ compilation
Bytecode (.class)
       ↓ executed by
Java Virtual Machine (JVM)

Setting Up Your Java Development Environment

  1. Download and install the latest JDK (Oracle JDK or OpenJDK).
  2. Set the JAVA_HOME environment variable.
  3. Install an IDE such as:
    • IntelliJ IDEA (recommended)
    • Eclipse
    • VS Code with Java Extensions
  4. Verify installation using:
    java -version
    javac -version
            
Sidebar Ad Space
Advertisement Space