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
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.
Completed: 0 / 4 exercises
Knowledge Check
Question 1 of 4