Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 201 ยท Getting Started

Getting Started with Java

Learn what Java is, where it runs today and how to write your first Java 25 program, in both the short modern form and the classic public class Main style.

Java is a general-purpose programming language built for programs that need to be reliable, fast and long-lived. It was created at Sun Microsystems in the mid-1990s and is now developed in the open as OpenJDK, with a new version every six months. Some of the largest systems in the world, from banks to search engines, have run on Java for decades.

In this course you'll learn Java from your very first line to collections, streams, concurrency and the JVM itself. Every lesson has live editors: press Run and your code is compiled and executed by a real Java 25 installation on our server, with the output shown right under the editor. You don't need to install anything to follow along.

Where Java is used

Java is everywhere, even if you rarely see it. You'll meet it in:

  • Back-end servers. Online shops, banking systems, booking sites and countless company APIs run on Java, often with frameworks like Spring Boot. (Our separate Advanced Java course covers that world in depth.)
  • Android. Android apps are written in Java or Kotlin, and Kotlin itself grew up on the Java platform and uses the same libraries.
  • Big data and infrastructure. Tools such as Apache Kafka, Hadoop, Cassandra and Elasticsearch are written in Java or run on the Java Virtual Machine.
  • Developer tools. IntelliJ IDEA, Eclipse, Maven, Gradle and Jenkins are Java programs.
  • Games and desktop software. Minecraft's original edition is the best-known example.

Java's main promise is "write once, run anywhere": you compile your code once, and the same compiled program runs on Windows, macOS and Linux. You'll see how that works in the next lesson.

Why do companies keep choosing it? Java is statically typed, so the compiler catches many mistakes before the program ever runs. It manages memory for you with a garbage collector, so whole classes of crashes common in older languages simply don't happen. And it takes backward compatibility seriously: code written twenty years ago usually still compiles today.

Your first program

Here is a complete Java program. Press Run:

Java Hello, Java

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Let's read it piece by piece:

  • void main() { ... } defines the main method: the place where your program starts. Java runs the lines inside the curly braces from top to bottom.
  • void means the method doesn't hand back a result. It just does its work.
  • IO.println(...) prints a line of text. IO is a small built-in helper class for console input and output, and println stands for "print line".
  • "Hello, Java!" is a string: text written between double quotes.
  • Each instruction ends with a semicolon ;. Leaving one out is the most common beginner error.

Edit the messages and run again. Add a third line. Then delete a semicolon and press Run: instead of output, you'll see a compiler error that names the file, the line number and the problem. Java checks your whole program before it runs, which is why you'll get used to reading these messages quickly.

Note: This short form, a file containing just void main(), is called a compact source file. It became a standard part of Java in Java 25 (2025). Older Java versions require the longer form shown below.

Java can calculate

Java understands arithmetic, and println can print the result of any expression, not just text:

Java Numbers and text

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

A few things to notice:

  • 22 / 7 prints 3, not 3.142.... When both numbers are whole numbers (ints), Java does whole-number division and drops the fraction. You'll learn the rules in Working with Numbers.
  • // starts a comment: a note for humans that Java ignores. See Comments and Javadoc.
  • int apples = 12; creates a variable named apples that holds a whole number. Unlike some languages, Java makes you say what type of value a variable holds. Variables explains this properly.
  • The + operator joins text and values together into one string.

The classic form: public class Main

Before Java 25, every Java program had to be wrapped in a class, and the main method needed a longer, very specific signature. You'll see this form in nearly every book, tutorial, job interview and existing project, so you should be able to read it from day one:

Java The classic Hello World

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Here's what the extra words mean, in brief. Each one gets its own lesson later:

Part Meaning
public class Main { ... } Declares a class named Main. In Java, all code lives inside classes.
public The method can be called from anywhere, including by the Java launcher.
static The method belongs to the class itself, so Java can call it without creating an object first.
void The method returns no value.
main The special name Java looks for when the program starts.
String[] args An array of text values passed in from the command line.
System.out.println The traditional way to print a line. System.out is the standard output stream.

In a compact source file, Java writes that wrapper class for you behind the scenes, and the main method may drop public, static and String[] args. The program is still a normal Java class; you just don't have to type the boilerplate.

Tip: Don't try to memorize public static void main(String[] args) as a magic spell. By the end of the Methods chapter, every word will make sense. For now, just recognize it.

IO.println or System.out.println?

Both print a line of text followed by a line break:

  • System.out.println has existed since Java 1.0 and works in every version. You'll see it in almost all existing code.
  • IO.println arrived in Java 25. It is shorter, and it is part of the same effort that made compact source files possible. It works in any Java 25 program, not only compact files.

Here they are side by side, in one program:

Java Both ways to print

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

In this course, early lessons often use IO.println in short demos and System.out.println in classic programs, so you get comfortable with both. Printing Output covers all the details, including formatted output with printf.

When you'll see each form

Compact source file (void main()) Classic class (public static void main)
Learning and quick experiments Existing projects, books and interview code
Small scripts and tools Programs with several classes and packages
Java 25 and later only Every Java version

Professional applications are made of many classes organized into packages, so they use the classic structure. Even there, the program has exactly one starting point: a main method.

How the editor runs your code

When you press Run, your code is sent to our server, compiled by the Java 25 compiler and run in an isolated sandbox. A few things are worth knowing:

  • Output printed with println appears under the editor. Error messages appear in red after the normal output.
  • Compile errors stop the program before it starts. Read the first error first: later errors are often side effects of it.
  • Input: some lessons have an Input box. Whatever text is in it is fed to your program as if you had typed it at the keyboard. Reading User Input shows how to use it.
  • The class name is free. On your own computer, a file with a public class Main must normally be saved as Main.java. Our editor launches single files directly, so you can name the class anything.
  • Limits: each run has a few seconds and no internet access, which is plenty for learning.

Let's see a compiler error on purpose. This program has two mistakes; press Run and read the messages:

Java A program with mistakes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

The compiler reports ';' expected on line 3 and points at the exact spot with a caret ^. Fix it and run again: now you get a second error on line 4, cannot find symbol, because Java treats io and IO as completely different names. Fix that too. Learning to read these messages calmly is one of the most valuable skills in programming, and Java Syntax has a guide to the most common ones.

How to learn with this course

  • Run every example, then change it. Break it on purpose and see what Java says. Small experiments teach faster than reading.
  • Type code yourself instead of only reading. Your fingers learn the syntax.
  • Take the quiz at the end of each lesson. The questions check whether you can predict what code does, which is the real skill.
  • Go in order through the first chapters. Each lesson builds on the previous ones, and later chapters assume you know the basics.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does this compact program print? void main() { IO.println(10 / 4); }

    Both 10 and 4 are whole numbers (ints), so Java does whole-number division and drops the fraction. Write 10.0 / 4 to get 2.5.
  2. 2. Which statement about compact source files is true?

    Compact source files became standard in Java 25. Java creates the surrounding class for you, and both IO.println and System.out.println work inside them.
  3. 3. You run a program and the editor shows Main.java:3: error: ';' expected. What happened?

    An error: from the compiler means the code couldn't be compiled at all, so no line of the program ran. The number after the file name is the line where Java noticed the problem.
  4. 4. What is the difference between IO.print("Hi") and IO.println("Hi")?

    println means "print line": it prints the text and then ends the line. print leaves the cursor on the same line, so the next output continues right after it.
  5. 5. Why does io.println("Hi"); fail to compile in Java?

    Java treats uppercase and lowercase letters as different, so io is an unknown name. The compiler reports cannot find symbol or a similar error.

Summary

  • Java is a statically typed, garbage-collected language used for servers, Android, big-data tools, developer tools and more.
  • A program starts at its main method. In Java 25, a compact source file can be as short as void main() { IO.println("Hi"); }.
  • The classic form, public class Main with public static void main(String[] args), works in every Java version and is what you'll see in most existing code.
  • IO.println (Java 25) and System.out.println (every version) both print a line; print prints without a line break.
  • Statements end with semicolons, Java is case-sensitive, and the compiler checks the whole program before it runs.

Next: How Java Works: JDK, JVM and Bytecode, where you'll follow your code from source file to running program.