1.1 Hello World and the JVM
A program is a set of instructions that asks a computer to solve a problem. A beginner-friendly way to think about programming is this: computers do not understand natural human language. Even a request as simple as “calculate 1 + 2” must be written as precise executable steps.
At the lowest level, computers process binary information represented with 0 and 1. A programming language helps turn human intent into structured instructions. You write source code, the Java compiler checks it and turns it into bytecode, and the Java Virtual Machine (JVM) runs that bytecode on your computer. This “compile to bytecode, run on a virtual machine” model is one reason Java programs can run on many different operating systems.
Common mainstream programming languages include:
- Python: beginner-friendly and widely used for data analysis, AI, automation, and web backends.
- C: closer to low-level computer systems, often used for operating systems, embedded systems, and performance-sensitive programs.
- C++: extends C with more abstraction, and is common in game engines, high-performance computing, and large software systems.
- Java: widely used in enterprise backends, Android development, and large cross-platform systems.
- JavaScript / TypeScript: central to web frontends, and also used for backend and full-stack development.
- Go, Rust, and C#: common in cloud services, systems programming, game development, and enterprise applications.
These languages differ in syntax, use cases, and learning curve, but they share the same basic goal: turning human ideas into precise instructions a computer can execute.
What is a program?
Most programs combine four basic kinds of action:
- Input: receive data from a keyboard, file, network, or another source.
- Processing: calculate, compare, transform, or store data.
- Output: display a result, write a file, or send data somewhere else.
- Control flow: decide what runs first, what repeats, and what only runs when a condition is true.
When learning Java, you do not need to master every syntax rule immediately. First build this mental model: a program is a clear sequence of steps, and the computer follows those steps exactly.
Flowchart
A flowchart is a visual way to describe program steps before writing code.
The flowchart below describes how to sum integers from 1 to 100. Notice the diamond-shaped node: it represents a decision. If the condition is true, the program keeps adding; if it is false, the program prints the result and stops.
Sum integers from 1 to 100
A standard flowchart uses terminators for start/end, rectangles for processes, and a diamond for decisions.
In code, this becomes initialization, a loop condition, accumulation, variable update, and final output.
public class SumOneToHundred {
public static void main(String[] args) {
int i = 1;
int total = 0;
while (i <= 100) {
total = total + i;
i = i + 1;
}
System.out.println(total);
}
}Your first Java program
Hello World is usually the first program in a new language. Its job is simple: print a piece of text to the screen.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}Output:
Hello World!There are five details to notice right away:
public class HelloWorlddefines a class namedHelloWorld.
mainis the usual entry method of a Java program.
- The braces
{}group the statements that belong to the class and method.
System.out.println()prints text and adds a newline.
- Each statement ends with a semicolon
;.
You can read the middle line as: “call System.out.println, and display the string Hello World! on the screen.”
Running Java code
Many beginners write Java in an IDE that runs with one click, such as IntelliJ IDEA, Eclipse, VS Code with Java extensions, Android Studio, or an online judge / teaching environment. In these tools you usually create a Java source file, click Run or Build, and see the result in an output panel.
If you use a terminal, save the file as HelloWorld.java, then compile and run it with the JDK tools:
javac HelloWorld.java
java HelloWorldjavac compiles source code into bytecode in a .class file. java HelloWorld asks the JVM to load that bytecode and run the main method.
Later lessons focus on Java syntax and problem solving, and assume you already have an IDE, teaching platform, or other one-click setup to run the examples.
Hello World in other languages
Different languages use different syntax, but the purpose is the same: display text on the screen. Comparing these examples shows which structures Java spells out explicitly.
print("Hello World!")#include <stdio.h>
int main(void) {
printf("Hello World!\n");
return 0;
}#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}Java makes the program entry point and class structure explicit. At first this feels longer than Python, but the structure becomes useful as programs grow.
Comments
Comments are notes for humans. They are not executed as program instructions. Use comments to explain intent, record context, or mark a point that future readers should understand.
Common Java comment styles:
- Single-line comments start with
//.
- Multi-line comments are wrapped in
/* ... */.
System.out.println("Hello World!"); // display "Hello World!"More comments are not always better. For beginners, a good rule is to comment why something is done, not merely repeat what the line already says.