DEV Community

Rakesh Daniel
Rakesh Daniel

Posted on

Java for Absolute Beginners: A Complete, Easy Guide

Java is a popular, platform-independent programming language used to build mobile apps, web applications, enterprise software, and backend systems. This blog explains Java from “What is Java?” to your first Hello, World! program in a simple, learner-friendly order.

1. Why Java?

Choose Java because it is:

  • Platform-independent: Write once, run anywhere. The same compiled Java program can run on Windows, Linux, and macOS if Java is installed.
  • Beginner-friendly: Java has clear rules, strong error checking, and a huge learning community.
  • Job-oriented: Java is widely used in banks, e-commerce companies, Android development, backend APIs, and large enterprise systems.
  • Safe and stable: Java manages memory automatically and prevents many common programming mistakes.
  • Works well with others: Java connects easily with databases, web services, cloud platforms, and other programming tools.

2. What Is Java?

Java is an object-oriented programming language created by James Gosling and his team at Sun Microsystems. It was officially released in 1996 as JDK 1.0.

Java programs are first compiled into an intermediate format called bytecode. The Java Virtual Machine (JVM) then runs that bytecode on your computer. This is why Java can run on different operating systems.

3. Java History and Versions

Java version Release year Important point
JDK 1.0 1996 First public Java release javaalmanac+1
Java 5 2004 Generics, enums, enhanced for-loop
Java 6 2006 Major enterprise improvements ops
Java 8 2014 Lambdas, Streams, major long-term version ops
Java 11 2018 LTS version, widely used in companies javaalmanac
Java 17 2021 LTS version javaalmanac
Java 21 2023 LTS version javaalmanac
Java 25 2025 Recent LTS version javaalmanac

Today, Java releases a new version every six months, while some versions are marked LTS (Long-Term Support), meaning companies use them for a longer time.

4. JDK, JRE, and JVM

These three names confuse beginners, so remember this simple order:

JDK = JRE + development tools
JRE = JVM + Java libraries

Term Full form What it does
JDK Java Development Kit Used to write, compile, and debug Java programs. It includes the JRE plus tools such as the compiler. docs.oracle+1
JRE Java Runtime Environment Used to run Java programs. It contains the JVM and required libraries. docs.oracle+1
JVM Java Virtual Machine Actually executes bytecode and makes Java platform-independent. docs.oracle+1

Simple example:

  • You write Java code → need JDK
  • You run an already-built Java application → need JRE
  • The program actually executes → JVM does the work

5. How Java Works: Full Flow

Here is the deep workflow from your code to hardware output:
You write source code in a file named Main.java.

  • The Java compiler (javac) converts it into bytecode: Main.class.
  • The JVM loads the .class file.
  • The JVM checks the bytecode for safety.
  • The JVM uses the Just-In-Time (JIT) compiler to convert frequently used bytecode into machine code.
  • The operating system sends instructions to the hardware.
  • The CPU executes the instructions.
  • The output appears on your screen.
Main.java
   ↓ javac compiler
Main.class (bytecode)
   ↓ JVM
Machine code
   ↓ Operating System
CPU / Hardware
   ↓
Output on screen
Enter fullscreen mode Exit fullscreen mode

Bytecode is not normal human-readable Java code and not direct machine code. It is an intermediate code understood by the JVM. This is the main reason Java is called “write once, run anywhere.

6. Java Memory Management and Garbage Collection

Java manages memory automatically.

  • When you create an object, Java stores it in the heap memory.
  • When an object is no longer used, the Garbage Collector (GC) removes it.
  • This reduces memory leaks and makes programming safer.

Example:

Student s1 = new Student();
s1 = null; // Now the Student object has no reference
Enter fullscreen mode Exit fullscreen mode

Later, the Garbage Collector may remove that unused Student object from memory. You do not need to manually delete memory like in some lower-level languages.

7. Java Programming Paradigm

Java mainly follows Object-Oriented Programming (OOP).

OOP has four main principles:

  • Encapsulation: Keep data and methods together inside a class.
  • Inheritance: A child class can reuse features from a parent class.
  • Polymorphism: One action can behave in different ways.
  • Abstraction: Hide complex details and show only necessary features. Java also supports procedural-style coding inside methods, but its main strength is OOP.

8. Class vs Object

A class is a blueprint. An object is a real thing created from that blueprint.

class Car {
    String color;

    void drive() {
        System.out.println("Car is driving");
    }
}

public class Main {
    public static void main(String[] args) {
        Car myCar = new Car(); // Object creation
        myCar.color = "Red";
        myCar.drive();
    }
}
Enter fullscreen mode Exit fullscreen mode
  • Car is the class.
  • myCar is the object.
  • new Car() creates an object in memory.

9. Java Naming Conventions

Good naming makes code readable.

Item Rule Example
Class name Start with capital letter Student, Main
Method name Start with small letter calculateMarks()
Variable name Start with small letter studentName
Constant All capital letters MAX_MARKS
Package name Small letters com.school.app

This is called camelCase for variables and methods, and PascalCase for class names.

10. Variables and Data Types

A variable is a named container that stores data.

int age = 20;
String name = "rakesh";
double marks = 89.5;
boolean isActive = true;
Enter fullscreen mode Exit fullscreen mode

Primitive data types

Java has eight primitive data types.

Data type Size Used for Default field value
byte 1 byte Small whole numbers 0
short 2 bytes Small whole numbers 0
int 4 bytes Whole numbers 0
long 8 bytes Big whole numbers 0L
float 4 bytes Decimal numbers 0.0f
double 8 bytes Larger decimal numbers 0.0d
char 2 bytes One character '\u0000'
boolean 1 bit conceptually True or false false

These default values apply to fields (class-level variables). Local variables must be initialized before use, otherwise Java gives a compile-time error.

Non-primitive data types
Non-primitive types are objects and reference types.

Examples:

  • String
  • Arrays
  • Classes
  • Interfaces
  • Collections such as ArrayList
String city = "Chennai";
int[] numbers = {10, 20, 30};
Enter fullscreen mode Exit fullscreen mode

11. Local vs Global Variables

Local variable
A local variable is created inside a method and can be used only inside that method.

public class Main {
    public static void main(String[] args) {
        int localNumber = 10; // Local variable
        System.out.println(localNumber);
    }
}
Enter fullscreen mode Exit fullscreen mode

Global variable / instance variable
A global variable is declared inside a class but outside methods. It can be used by the methods of that class.

public class Student {
    String name; // Global / instance variable

    void showName() {
        System.out.println(name);
    }
}
Enter fullscreen mode Exit fullscreen mode

Static and non-static global variable

public class College {
    static String collegeName = "ABC College"; // Static: shared by all objects
    String studentName;                        // Non-static: separate for each object
}
Enter fullscreen mode Exit fullscreen mode
  1. static variable: One copy is shared by all objects.
  2. Non-static variable: Every object gets its own separate copy.

12. Reserved Words

Reserved words, also called keywords, are special words already reserved by Java. You cannot use them as variable, class, or method names.

Examples:

public, class, static, void, main, int, double, if, else, for, while, return, new, this, extends, implements
Enter fullscreen mode Exit fullscreen mode

Wrong:
int class = 10; // Error
Correct:
int className = 10; // Correct

13. Readability and Compatibility

Java is readable because:

  • It uses clear English-like keywords.
  • It forces a structured format.
  • It supports comments.
  • It has strong naming conventions.

Java also “plays well with others” because it can connect with:

  • Databases such as MySQL, PostgreSQL, and Oracle
  • Web services and APIs
  • Cloud platforms
  • Android
  • Tools such as Maven, Gradle, Git, and Spring Boot
  1. Understanding Your First Java Program
public class Main {                                  // 1. Class declaration
    public static void main(String[] args) {         // 2. Entry point
        System.out.println("Hello, World!");         // 3. Print a line
    }
}
Enter fullscreen mode Exit fullscreen mode

public class Main

  • public is an access modifier.
  • class is a keyword used to create a class.
  • Main is the class name.

Access modifier means: “Who can access this class, method, or variable?”

Common access modifiers:

Modifier Meaning
public Accessible from anywhere
private Accessible only inside the same class
protected Accessible in the same package and child classes
default Accessible only within the same package

We write public class Main because the JVM must be able to access the class from outside and start the program.

public static void main(String[] args)
This is the entry point of every Java application. When you run the program, the JVM looks for this exact method and calls it first.

Break it down:

  • public: JVM can access this method from outside.
  • static: The method belongs to the class, not to an object. So JVM can call it without creating an object.
  • void: The method does not return any value.
  • main: This is the special method name the JVM searches for.
  • String[] args: This is an array of String values used to receive command-line inputs.

Example:
java Main Hello Java
Here:

  • args[0] = "Hello"
  • args[1] = "Java" String is a built-in Java class used to store text. args is only a variable name; you could name it anything, but args is the standard convention. The square brackets [] mean it is an array, because the program may receive multiple inputs.

System.out.println("Hello, World!");

  • System is a built-in Java class in the java.lang package.
  • out is a static field inside the System class. It represents the standard output stream.
  • println is a method that prints text and moves the cursor to the next line.
  • . means “access something inside something.” So:

System.out.println("Hello, World!");

means:

From the System class, access out, then call the println() method to print the text.

Left side of .: the class or object.
Right side of .: the field or method you want to use.

15. Built-in Java Classes

Java provides many ready-made classes so you do not need to write everything from zero.

Common built-in classes:

  • String: Text handling
  • Math: Mathematical operations
  • Scanner: Take user input
  • ArrayList: Dynamic list
  • HashMap: Key-value storage
  • LocalDate: Date handling
  • System: System-level operations and output

Example using Scanner:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter your name: ");
        String name = scanner.nextLine();

        System.out.println("Welcome, " + name);
    }
}
Enter fullscreen mode Exit fullscreen mode

16. What Is Aggregation in Java?

Aggregation means one class contains another class, but both can exist independently.

Example: A Department has Teacher objects. If the department is deleted, the teachers can still exist separately.

class Teacher {
    String name;

    Teacher(String name) {
        this.name = name;
    }
}

class Department {
    String departmentName;
    Teacher teacher; // Aggregation

    Department(String departmentName, Teacher teacher) {
        this.departmentName = departmentName;
        this.teacher = teacher;
    }
}
Enter fullscreen mode Exit fullscreen mode

Here, Department has-a Teacher. This is called a HAS-A relationship.

17. Java Future

Java has a strong future because it keeps updating while supporting old applications. Modern Java focuses on better performance, simpler syntax, cloud development, and long-term supported versions such as Java 17, 21, and 25.
Java is especially useful for:

  • Backend development
  • Android development
  • Enterprise software
  • Microservices
  • Big-data tools
  • Cloud-based applications

18. Quick Revision

  • Java is an object-oriented, platform-independent language.
  • JDK is for development; JRE is for running; JVM executes bytecode.
  • Bytecode makes Java portable.
  • Garbage Collection automatically removes unused objects.
  • Class is a blueprint; object is a real instance.
  • Primitive types store basic values; non-primitive types store objects.
  • main() is the entry point of a Java program.
  • System.out.println() prints output to the screen.
  • Java follows OOP concepts: encapsulation, inheritance, polymorphism, and abstraction.

Top comments (0)