🌱BeginnerJava Foundations

What is Java?

Learn what Java is, why it matters, and the key ideas that make it one of the most used programming languages in the world.

Overview

Java is a high-level, object-oriented programming language created by Sun Microsystems in 1995 (now owned by Oracle). It was designed with one central promise: "Write Once, Run Anywhere." Java code is compiled into bytecode that runs on the Java Virtual Machine (JVM), so a program written on Windows will run identically on macOS or Linux without any changes. Java is one of the most widely used programming languages in the world. It powers Android apps, enterprise back-end systems, large-scale web services, and embedded devices. Its strict type system and object-oriented design help teams write maintainable code at scale. Java is object-oriented, meaning everything is organized around classes and objects. It is strongly typed, which means you must declare what kind of data each variable holds. These features catch many bugs at compile time, before the program even runs.

Key Points

  • •"Write Once, Run Anywhere" - Java bytecode runs on any device with a JVM installed
  • •Object-Oriented: programs are built from classes and objects that model real-world concepts
  • •Strongly typed: every variable has a declared type and type errors are caught at compile time
  • •Platform-independent: the JVM handles the differences between operating systems
  • •Widely used in Android development, enterprise back-ends, and large-scale web services
  • •Large standard library and massive ecosystem make almost any task achievable without third-party code

Examples

A minimal Java program

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

Every Java program needs at least one class and a main method - this is where execution begins.

Java is object-oriented - everything is a class

public class Dog {
    String name;
    int age;

    void bark() {
        System.out.println(name + " says: Woof!");
    }
}

A class is a blueprint. You create objects (instances) from it to work with real data.

Java is strongly typed - every variable has a type

int score = 95;
double price = 4.99;
boolean isActive = true;
String message = "Hello";

Declaring types helps the compiler catch mistakes like trying to add a number to a name.

Common Mistakes

  • Confusing Java with JavaScript - they are completely different languages with different purposes and syntax
  • Thinking Java is only for Android - it is widely used in servers, desktop apps, and enterprise systems
  • Skipping learning the JVM model - understanding bytecode and the JVM makes many Java concepts click

Note

You do not need to install anything to start learning Java. Visit onecompiler.com/java or replit.com and write your first program in the browser right now.

Exercises

Write Java code and click Run to execute it instantly. When your output looks correct, mark as done.

Loading editor…

Completed: 0 / 4 exercises

Knowledge Check

Question 1 of 4

What does "Write Once, Run Anywhere" mean in Java?