> For the complete documentation index, see [llms.txt](https://cs61b-2.gitbook.io/cs61b-textbook-fall-2026/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cs61b-2.gitbook.io/cs61b-textbook-fall-2026/1.-introduction/1.1-your-first-java-program.md).

# 1.1 Your First Java Program

The classic first program when introducing any new language is **Hello World**, or a program that prints `Hello World` to the console. In Java, **Hello World** can be written as such:

```java
void main() {
    IO.println("Hello world!");
}
```

Compare this with the Python equivalent:

```python
print("hello world!")
```

Compared to the extreme simplicity of Python, we observe the following features of this simplest Java program:

* The **`main`** function: all the code that runs must be inside of a function called main. We'll cover what the `void` means later.
* **Curly braces** `{}` enclose sections of code (functions, classes, and other types of code that will be covered in future chapters).
* All statements must end with a **semi-colon**.
* Printing requires us to use dot notation, going to some library called `IO` and asking for its print function.

For fun, see [Hello world! in other languages](https://www.rosettacode.org/wiki/Hello_world/Text).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cs61b-2.gitbook.io/cs61b-textbook-fall-2026/1.-introduction/1.1-your-first-java-program.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
