Java Introduction
Java is a general-purpose, object-oriented programming language that first appeared in 1995. Its famous promise is "write once, run anywhere": you compile your source code into bytecode, and that bytecode runs unchanged on any machine that has a Java Virtual Machine (JVM) — Windows, macOS, Linux, servers, phones and even smart cards.
Three decades later Java is still one of the most widely used languages in the world. It powers bank back-ends, online shops, big-data platforms, Android apps and countless internal business systems.
What is Java used for?
- Web back-ends and REST APIs (Spring Boot, Jakarta EE, Quarkus)
- Android apps (Java and its cousin Kotlin both run on Android)
- Large enterprise systems in banking, insurance and retail
- Big-data tools such as Apache Kafka, Hadoop and Elasticsearch
- Desktop tools and IDEs (IntelliJ IDEA itself is written in Java)
- Games — the original Minecraft is a Java program
Why learn Java?
| Feature | What it means for you |
|---|---|
| Platform independent | The same compiled program runs on every JVM |
| Strongly, statically typed | Many mistakes are caught by the compiler before the program runs |
| Object-oriented | Code is organised into classes and objects that model real things |
| Automatic memory management | A garbage collector frees memory you no longer use |
| Huge standard library | Collections, file I/O, networking, dates, concurrency — all built in |
| Massive job market | Java developers are in demand all over the world |
How a Java program runs
- You write source code in a file ending in
.java. - The compiler
javactranslates it into bytecode stored in a.classfile. - The JVM (
java) loads the bytecode and runs it, compiling hot code paths to fast machine code on the fly.
You do not need to install anything to follow this course: every example on ExcelTAD is compiled and run on a real JDK in the cloud.
Your first Java program
Every Java program starts in a method called main that lives inside a class. Press ▶ Run to compile and run this program, then change the text and run it again.
class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}Hello, World!
System.out.println prints a line of text followed by a line break. Don't worry about public static void and String[] args yet — the Syntax chapter explains every word.
Tip: In every playground on ExcelTAD you can edit the code and press Ctrl+Enter to run it.
Printing several lines
Statements inside main run from top to bottom, one after another:
class Main {
public static void main(String[] args) {
System.out.println("Java is portable.");
System.out.println("Java is object-oriented.");
System.out.println("Java is everywhere!");
}
}Java is portable.
Java is object-oriented.
Java is everywhere!
Java vs. other languages
| Java | Python | C++ | |
|---|---|---|---|
| Typing | static | dynamic | static |
| Runs on | JVM (bytecode) | interpreter | native machine code |
| Memory | garbage collected | garbage collected | manual / RAII |
| Syntax family | C-style braces { } |
indentation | C-style braces { } |
If you already know C, C++ or C#, Java's syntax will look very familiar. If you come from Python, the biggest change is that every variable has a fixed type and every statement ends with a semicolon.
Note: Java and JavaScript are completely different languages. The similar name was a marketing decision in the 1990s.
Test yourself
What does the Java compiler javac produce?
- Machine code for one CPU
- Bytecode in .class files
- A Python script
- HTML pages
Which method does a Java program start running from?
- start()
- run()
- main()
- init()
What does JVM stand for?
- Java Variable Manager
- Java Virtual Machine
- Joint Vector Module
- Java Version Monitor