Skip to main content

Menu

System onlineAI Tutorials / 2026

AI Tutorials
Knowledge search

Recent · Popular · Tutorials

  • dart3 tutorials
  • java1 tutorial
  • Javascript3 tutorials
  • Node.js Introduction2 tutorials
  • dartdart · General · In depth
  • JavascriptJavascript · Advanced · In depth
  • JavascriptJavascript · Advanced · Mid
  • JavascriptJavascript · Advanced · Short

Find a tutorial

Tell the assistant what you want to learn. It suggests published chapters.

For example: “I want to learn Rust ownership from the start.” The conversation is kept only in this tab.

0 / 2,000 characters

Enter to send, Shift+Enter for a new line. Do not include personal information.

Chapter 1

What Java is and how it runs

Java is a programming language, but it is also a system for running programs almost anywhere. You write human-readable instructions called **source code**. A tool called the **compiler** translates them into **bytecode**, a compact intermediate format. The **Java Virtual Machine (JVM)** — a program
Level: GeneralLength: Short2 min read

What Java is and how it runs

Java is a programming language, but it is also a system for running programs almost anywhere. You write human-readable instructions called source code. A tool called the compiler translates them into bytecode, a compact intermediate format. The Java Virtual Machine (JVM) — a program on your computer — reads that bytecode and runs it. Because a JVM exists for Windows, Mac, Linux, and more, the same compiled Java program runs on all of them. That is Java's famous promise: write once, run anywhere.

Your first Java program

Code example in java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}

Save it as Hello.java. In a terminal, run javac Hello.java to compile, then java Hello to run. The text Hello, Java! appears on screen.

Every Java statement — one instruction — ends with a semicolon. Code lives inside classes (named containers for code), and the JVM always looks for a method named main to start your program.

Data: types, variables, and strings

Java knows the kind of data each piece of information holds. A primitive type is a simple built-in kind, such as int (whole numbers), double (decimals), and boolean (true or false). A variable is a named box that stores a value. Java converts types automatically only when no information is lost, like int into double; otherwise you must convert explicitly.

Code example in java
int count = 3;
double total = count * 2.5;   // int becomes double safely
boolean done = total > 7.0;
String greeting = "Hi, " + "Java";  // joining text is easy
System.out.println(done);     // prints true

A String is a piece of text, and + glues strings together.

Decisions, repetition, arrays, and methods

Programs make choices and repeat work:

Code example in java
int[] scores = {90, 75, 88};   // an array: numbered list of values

for (int i = 0; i < scores.length; i++) {
    if (scores[i] >= 80) {
        System.out.println(scores[i] + " passed");
    } else {
        System.out.println(scores[i] + " retry");
    }
}

An array is a fixed-size list where each item has a number, starting at 0. An if statement chooses between paths; a for loop repeats.

A method is a named, reusable block of code you can call with different inputs:

Code example in java
static String describe(int score) {
    return score >= 80 ? "passed" : "retry";
}

Exercise

Why can the same compiled Java program run on different operating systems?

Show answer

Because each operating system has its own JVM, and every JVM understands the same bytecode. The JVM adapts the bytecode to its machine.

Exercise

What number does an array's first item have?

Show answer

Zero. Arrays are numbered starting from 0, so scores[0] is the first item.

Spotted a mistake, or code that does not work?

Report an issue

Chapter: What Java is and how it runs

0 / 2,000 characters

Plain text, for example: the second code sample does not compile. Do not include personal information.

You can't do that