Introduction to Java
Dashboard
Topic 1/30
Home › Introduction to Java

🚀 Introduction to Java

Discover what Java is, its rich history, core features, and how the Java ecosystem operates.

What is Java?

Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.

History of Java

Java was developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. Initially called "Oak", it was later renamed to Java. Sun Microsystems was later acquired by Oracle Corporation in 2010.

Key Java Features

  • Platform Independent: Java code is compiled into bytecode, which is platform-independent and can be run on any machine with a JVM.
  • Object-Oriented: Everything in Java is an object (except primitives). It models real-world entities using objects.
  • Robust: Strong memory management, automatic garbage collection, and exception handling make Java extremely reliable.
  • Secure: Java provides a secure execution environment, preventing unauthorized memory access and minimizing virus threats.
  • Multithreaded: Java supports multithreading out-of-the-box, allowing concurrent execution of multiple tasks.
  • Distributed: Java facilitates building distributed applications over networks using RMI and EJB.

JVM, JRE, and JDK Differences

To understand the Java ecosystem, you must know the difference between the JVM, JRE, and JDK:

  • JVM (Java Virtual Machine): An abstract machine that enables your computer to run a Java program. It converts Java bytecode into machine-specific code.
  • JRE (Java Runtime Environment): Contains the JVM plus Java libraries and other components needed to run Java applications.
  • JDK (Java Development Kit): A full featured SDK for Java. It contains everything the JRE has, plus development tools like the compiler (javac) and debugger.
Note: If you just want to run Java programs, you only need the JRE. If you want to write and compile Java programs, you need the JDK.
[JDK] -> Contains [JRE] + Development Tools (javac, jdb)
[JRE] -> Contains [JVM] + Library Classes
[JVM] -> Executes the bytecode
        

Java Editions

Edition Description
Java SE (Standard Edition) Core Java platform for general-purpose desktop and server environments.
Java EE (Enterprise Edition) Built on top of Java SE, used for developing large-scale, distributed enterprise applications.
Java ME (Micro Edition) Designed for resource-constrained devices like mobile phones and embedded systems.

The Compilation Process & Bytecode

When you write Java code, it is saved in a .java file. The Java compiler (javac) compiles this file into a .class file, which contains bytecode. Bytecode is a highly optimized set of instructions designed to be executed by the JVM.

Simple HelloWorld Walkthrough Java
public class HelloWorld {
    public static void main(String[] args) {
        // Print Hello World to the console
        System.out.println("Hello, World!");
    }
}
            

Line-by-Line Breakdown:

  • public class HelloWorld: Defines a class named HelloWorld. In Java, all code must reside inside a class.
  • public static void main(String[] args): The entry point of the application. The JVM looks for this exact method signature to start execution.
  • System.out.println("Hello, World!");: A statement that prints the specified text to the standard output (console).

🎯 Frequently Asked Interview Questions

Q1: What makes Java platform-independent?
Answer: Java source code is compiled into Bytecode (.class file) by javac, which is non-machine specific. This bytecode runs on any system that has a Java Virtual Machine (JVM) matching that operating system ("Write Once, Run Anywhere").
Q2: Differentiate between JDK, JRE, and JVM.
Answer:
  • JVM (Java Virtual Machine): Executes bytecode line-by-line using JIT compiler.
  • JRE (Java Runtime Environment): JVM + Core Libraries (rt.jar) required to run applications.
  • JDK (Java Development Kit): JRE + Developer tools (javac, javadoc, jdb) required to develop applications.
Q3: Why is Java not considered a 100% pure Object-Oriented Language?
Answer: Because Java supports 8 primitive data types (int, char, boolean, double, etc.) which are not objects. Languages like Smalltalk treat everything strictly as an object.
Q4: What is the JIT (Just-In-Time) Compiler?
Answer: The JIT compiler is part of the JVM. It compiles hot bytecode sequences directly into native machine code at runtime, caching the compiled native code to dramatically boost execution speed.