Java Programming Introduction

Beginner
⏱️ 15 min read
📚 Updated: Jul 2026
🎯 5 Examples
JVM · javac · main()

What You’ll Learn

This page is a self-contained introduction to Java programming—no prior coding experience required. You will understand what Java is, write your first program, and learn how the JVM runs your code on any platform.

01

What is Java

Platform-independent OOP.

02

History

James Gosling & JVM.

03

Hello World

First program.

04

Compile & run

javac workflow.

05

Open source

OpenJDK today.

06

Building blocks

Core concepts.

🤔 What is Java Programming?

Java is a high-level, object-oriented programming language designed to be platform-independent. You write human-readable source code once; a compiler turns it into bytecode, and the Java Virtual Machine (JVM) executes that bytecode on Windows, Linux, macOS, and many other systems.

Java powers enterprise backends, Android apps, big-data tools, financial systems, and cloud microservices. Its large ecosystem of libraries and frameworks—Spring, Hibernate, Apache Kafka, and more—helps teams build reliable software at scale.

Java is also known for automatic memory management (garbage collection). The JVM reclaims unused objects so you focus on logic instead of manual memory allocation, while still learning structured, type-safe code.

💡
Beginner tip

Start with System.out.println, variables, and simple if/for loops. Once those feel natural, move on to classes, collections, and exception handling.

👤 Who Created Java?

James Gosling is widely known as the “Father of Java.” While working at Sun Microsystems in the mid-1990s, he led the team that designed Java (originally called Oak) for embedded and consumer devices. The language shipped publicly in 1995 with the slogan “Write Once, Run Anywhere.”

Oracle acquired Sun in 2010 and continues to steward Java today, while the open-source OpenJDK community drives most modern development.

Version / EventYearHighlight
Java (Oak) started1991James Gosling, Sun Microsystems
Java 1.0 released1996First public JDK
Java 2 (J2SE)1998Swing, Collections framework
Java 52004Generics, enhanced for-loop
Oracle acquires Sun2010Java stewardship moves to Oracle
Java 82014Lambda expressions, Streams API
Java 11 (LTS)2018Long-term support release
Java 17 (LTS)2021Records, sealed classes
Java 21 (LTS)2023Virtual threads, pattern matching

⚙️ How Does Java Work?

Java follows a compile-then-run model that separates your source code from the underlying operating system:

  1. Write — You create .java source files with classes and a main method.
  2. Compilejavac translates source into platform-neutral bytecode (.class files).
  3. Run — The JVM loads bytecode, may JIT-compile hot paths to native code, and executes your program.
  4. Manage memory — The garbage collector frees objects you no longer reference.

This design is why the same JAR file can run on a developer’s laptop, a Linux server, or a cloud container—as long as a compatible JVM is installed.

📖 Is Java Easy to Learn?

Java has a reputation for being slightly more verbose than Python, but it rewards that structure with clear error messages, predictable syntax, and concepts that transfer directly to Kotlin, C#, and other languages.

For beginners, the learning curve is manageable if you:

  • Type out every example instead of only reading it
  • Fix compiler errors one at a time—they usually point to the exact line
  • Keep programs small until variables, loops, and methods feel automatic
  • Use an IDE (IntelliJ IDEA, VS Code, Eclipse) for autocomplete and debugging

Many universities and bootcamps choose Java as a first language because it teaches disciplined object-oriented design without hiding how programs are structured.

🔓 Is Java Open Source?

Yes. OpenJDK is the free, open-source reference implementation of Java. It is licensed under the GNU General Public License (GPL) v2 with the Classpath Exception, which allows you to use Java libraries in your own applications freely.

Popular distributions such as Eclipse Temurin, Amazon Corretto, and Microsoft Build of OpenJDK are built from OpenJDK sources. You can download, study, and contribute to Java without licensing fees.

📝 Program Structure & Syntax

Every beginner Java program lives inside a class. The public class name must match the filename (e.g. HelloWorld.java):

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

Syntax rules

  • public class HelloWorld — defines the class; filename must be HelloWorld.java.
  • public static void main(String[] args) — entry point; the JVM calls this method when the program starts.
  • System.out.println — prints a line of text to the console.
  • Semicolons — end statements; braces { } define blocks.
  • Case-sensitiveSystem and system are different identifiers.
  • Comments// line comment or /* block comment */.

💻 How to Compile and Run Java

Install a JDK (Java Development Kit), which includes the compiler (javac) and runtime (java). Then use a terminal in the folder containing your source file:

Java
javac HelloWorld.java
java HelloWorld
  • javac — compiles .java source into .class bytecode.
  • java HelloWorld — runs the program (use the class name, not HelloWorld.class).
  • JDK vs JRE — you need the full JDK to compile; the JRE (or modern JDK) is enough to run compiled programs.
  • IDEs — IntelliJ IDEA Community, VS Code with Java extensions, or Eclipse provide run buttons and debugging.
  • Online Java Compiler — run Java in the browser without installing anything.

🧰 Core Building Blocks

As you continue learning Java, these are the main ideas you will encounter:

ConceptWhat it does
Types & variablesint, double, boolean, String, and more
Control flowif, else, switch for decisions
Loopsfor, while, do-while for repetition
MethodsReusable functions inside classes
Classes & objectsEncapsulate data and behavior (OOP)
Arrays & collectionsint[], ArrayList, HashMap
ExceptionsHandle errors with try/catch
Packages & importsOrganize code across files and libraries

⚡ Quick Reference

TaskExample
Print lineSystem.out.println("Hi");
Read integerScanner sc = new Scanner(System.in); int n = sc.nextInt();
String variableString name = "Alex";
Conditionif (x > 0) { ... }
for loopfor (int i = 0; i < n; i++) { ... }
Import classimport java.util.Scanner;

Examples Gallery

Five starter programs you can type, compile, and run today. Save each as a .java file (class name must match filename) and use javac and java as shown above.

Example 1 — Hello, World!

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

System.out.println() outputs text. main() is where execution begins. The class name HelloWorld must match the filename.

Example 2 — Variables and output

Java
public class Vars {
    public static void main(String[] args) {
        int age = 20;
        double gpa = 3.85;
        char grade = 'A';
        String name = "Alex";

        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.printf("GPA: %.2f%n", gpa);
        System.out.println("Grade: " + grade);
    }
}

Example 3 — Reading user input

Java
import java.util.Scanner;

public class InputDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = sc.nextInt();
        System.out.println("You entered: " + num);
        sc.close();
    }
}

Scanner reads typed input from the keyboard. Always close it in small programs, or use try-with-resources in larger projects.

Example 4 — A simple method

Java
public class AddDemo {
    static int add(int a, int b) {
        return a + b;
    }

    public static void main(String[] args) {
        System.out.println("Sum = " + add(3, 5));
    }
}

Example 5 — Even or odd with if-else

Java
import java.util.Scanner;

public class EvenOdd {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter n: ");
        int n = sc.nextInt();

        if (n % 2 == 0)
            System.out.println(n + " is even");
        else
            System.out.println(n + " is odd");

        sc.close();
    }
}

This shows basic decision-making: one branch runs when the condition is true, the other when it is false.

📚 Why Learn Java Programming?

  • Write Once, Run Anywhere — bytecode and the JVM make Java highly portable across devices and servers.
  • Enterprise demand — banks, e-commerce, and large backends rely on Java and Spring every day.
  • Android development — Kotlin is now preferred for new apps, but Java skills still transfer directly.
  • Strong OOP foundation — classes, inheritance, and interfaces prepare you for C#, Kotlin, and more.
  • Rich ecosystem — mature libraries, build tools (Maven, Gradle), and IDE support speed up learning.
  • Stable career path — Java has remained in the top languages for decades with steady job demand.

📋 Java vs Other Languages

LanguageRuntimeBest for beginners when…
JavaJVM (bytecode)You want OOP, portability, and enterprise or Android career paths
PythonInterpreterYou want the fastest path to scripts, automation, and data science
C#.NET (CLR)You target Microsoft/Azure ecosystems or Unity game development
C++NativeYou need maximum performance and low-level systems control

🧠 How a Java Program Runs

1

Write source (.java)

You create classes, methods, and a main entry point in a text editor or IDE.

Edit
2

Compile to bytecode

javac checks syntax and produces a .class file with JVM bytecode.

Compile
3

JVM executes

The JVM loads bytecode, may JIT-compile hot code, and runs main.

Runtime
=

Output appears

System.out.println prints to your terminal; garbage collection frees unused objects.

Summary

  • Java was created by James Gosling at Sun Microsystems in the 1990s.
  • It is object-oriented, platform-independent, and runs on the JVM.
  • Source compiles to bytecode; the same program can run on many operating systems.
  • Every program needs a class (matching the filename) and a main method.
  • Compile with javac File.java, run with java ClassName.
  • OpenJDK makes Java free and open source for everyone.

💡 Best Practices

✅ Do

  • Match the public class name to the filename exactly
  • Use meaningful names (studentCount, not x)
  • Brace every if and loop body for clarity
  • Close Scanner streams when you open them
  • Type out examples yourself—muscle memory matters
  • Read compiler errors from the first line downward

❌ Don’t

  • Compare strings with == (use .equals() instead)
  • Ignore warnings about unchecked types or deprecated APIs
  • Put all logic inside main forever—split into methods and classes
  • Skip understanding OOP before jumping into Spring or Android
  • Copy code without knowing what each line does
  • Assume Java only runs on old enterprise servers—modern Java is actively evolving

❓ Frequently Asked Questions

Java is a high-level, object-oriented language designed for portability. Source code compiles to bytecode that runs on the Java Virtual Machine (JVM), so the same program can run on Windows, Linux, macOS, and more without recompiling for each platform.
Yes. Java has clear syntax, strong typing, and excellent learning resources. It teaches object-oriented concepts used in enterprise software, Android development, and backend systems. The syntax is a bit more verbose than Python, but the structure helps you build solid habits.
Install a JDK (Java Development Kit), save code as HelloWorld.java, compile with javac HelloWorld.java, then run java HelloWorld. You can also use the online Java compiler on CodeToFun if you cannot install a JDK yet.
Yes. OpenJDK is the official open-source reference implementation of Java, available under the GNU General Public License with the Classpath Exception. Oracle JDK and many distributions (Temurin, Amazon Corretto) are built from or compatible with OpenJDK.
Practice variables, if-else, loops, and methods in small console programs. Then learn classes and objects, arrays, ArrayList, exception handling, and file I/O. Build habits early: match class names to filenames, read compiler errors carefully, and type examples yourself.
Java is statically typed and compiled to bytecode before running on the JVM; Python is dynamically typed and usually interpreted. Java requires more boilerplate but catches many errors at compile time. Both are excellent first languages—Python for quick scripts, Java for structured OOP and large applications.
Did you know?

Java was originally named Oak after a tree outside James Gosling’s office. The team renamed it Java because of trademark issues—and because they drank a lot of coffee. The coffee-cup logo and “Write Once, Run Anywhere” slogan helped Java become one of the most widely taught languages in the world.

Try It Yourself

Copy any example from this page into the online compiler and run it instantly.

Open Java Compiler →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful