Getting Started with Java
From source code to the first chatbot increment
1.1 Learning objectives
By the end of this chapter, you should be able to:
- explain the role of the JDK, the compiler, and the JVM;
- create, compile, and run a Java class;
- distinguish compile-time errors, runtime exceptions, and logic errors;
- follow basic naming and file conventions.
1.2 Java and its platform

Figure 1.1. From source code to executing a Java program.
Java combines a programming language with an execution platform. Code written in a .java file is transformed by the javac compiler into bytecode, stored in a .class file. The JVM executes that bytecode on the operating system.
The JDK bundles the compiler, the JVM, and the other tools needed to develop and run programs. On modern installations, you only need to install a compatible JDK; there is no need to look separately for a “development JRE.”

This book uses Java 21 or later. Confirm your setup in the terminal:
java -version
javac -version
1.3 First program

Figure 1.2. Comic: the first dialogue with Java.
Create a file named Chapter01FirstProgram.java:
public class Chapter01FirstProgram {
public static void main(String[] args) {
System.out.println("TutorJavaBot: Hello!");
System.out.println("TutorJavaBot: Shall we study Java?");
}
}
The public class and the file must have the exact same name, including uppercase and lowercase letters.
Compile and run:
javac Chapter01FirstProgram.java
java Chapter01FirstProgram
Expected output:
TutorJavaBot: Hello!
TutorJavaBot: Shall we study Java?
The main method is the entry point:
public: can be called by the JVM;static: does not require creating an object first;void: does not return a value;String[] args: receives command-line arguments.
1.4 Basic conventions
In Java:
- classes use
PascalCase, such asTutorJavaBot; - variables and methods use
camelCase, such asuserName; - constants use uppercase letters, such as
MAX_ATTEMPTS; - statements normally end with a semicolon;
- curly braces delimit code blocks.
Comments should explain intent or context rather than repeating an obvious statement:
// This message introduces the character that accompanies you throughout the book.
System.out.println("TutorJavaBot: Hello!");
1.5 How to interpret errors
A compile-time error prevents the .class file from being created, such as a missing curly brace. A runtime exception occurs after the program starts, such as an invalid numeric conversion. A logic error does not stop the program, but produces the wrong result.
Always read the compiler’s first error message, locate the file and line number, and fix one cause at a time.
1.6 Project evolution: version 1
The chatbot does not accept input yet. At this first checkpoint, it simply:
- introduces its name;
- states the purpose of the conversation;
- exits normally.
The complete example is in examples/src/Chapter01FirstProgram.java.
1.7 Verifiable practice
- Add a third message listing the commands that will be implemented in the book.
- Rename the class and the file consistently.
- Remove a semicolon, observe the compiler error, and then restore the code.
Completion criteria:
- the
javaccommand finishes without error messages; - the executed class has the same name as the file;
- all three messages appear in the expected order.
Before moving on
You should be able to explain, without looking at the text, the sequence
.javafile → compiler →.classfile → JVM.