Skip to content

Java Basics

Glossary

123 terms from Java Basics, in plain words, each with the chapter that teaches it.

A

Accessor
A method a record creates for each of its components, named after the component. For `MenuItem(String name, int priceCents)` you read the price with `priceCents()`, with no `get` prefix.
Annotation
A note for the compiler that starts with `@`. `@Override` asks it to check that a method really replaces an existing one, such as `toString`, so a typo becomes an error.
API (Application Programming Interface)
The set of classes and methods a library offers to your code. The Java API documentation lists every class and method in Java's library.
Argument
A value you hand to a method when you call it. In `lineTotal(475, 3)`, 475 and 3 are the arguments.
ArithmeticException
The exception Java throws when a calculation is impossible, such as dividing an `int` by zero. The message reads `/ by zero`.
Array
A fixed-length, ordered group of values of one type, such as the seven daily sales figures `int[] sales`. You reach each element by its index, and you can't change the length.
ArrayIndexOutOfBoundsException
The exception thrown when you ask an array (or list) for an index that doesn't exist, such as index 7 in a 7-element array. The last valid index is `length - 1`.
ArrayList
The most common kind of `List`: an ordered collection that grows and shrinks as you add and remove elements, like a shopping cart. You create one with `new ArrayList<>()`.
Arrays
A toolbox class of helper methods for arrays. `Arrays.toString` makes an array printable and `Arrays.sort` puts it in order.
Assignment
Storing a value in a variable with `=`, which means "store this value", not "is equal to". Declaring a variable gives its type and name; later assignments leave the type out.

B

Block
A group of statements between braces `{ }`, such as a method's body or the code under an `if` or a loop. A variable declared inside a block exists only there.
boolean
The type that holds only `true` or `false`, the answer to a yes-or-no question.
break
A statement that leaves a loop immediately. It's the usual way to end a `while (true)` loop.
Bytecode
The compact instructions the compiler produces from your source code, saved in `.class` files. The JVM runs bytecode, which is why the same program works on Windows, macOS and Linux.

C

Call
To run a method by writing its name followed by parentheses, with any arguments inside, as in `IO.println("Hi")`.
camelCase
The Java naming style for variables and methods: start with a small letter and capitalize each later word, as in `priceCents`.
Cast
Converting a value to another type by writing the new type in parentheses in front, such as `(double) bags / cafes`. Casting a decimal to `int` drops the decimals without rounding.
catch
A `try` block holds risky code, and a `catch` block says what to do if a given exception is thrown inside it. This lets a bad input like `ten` print a friendly message instead of crashing the program.
char
The type for a single character, written in single quotes, such as `'L'`.
Checked exception
An exception the compiler forces you to catch or declare with `throws`, such as `IOException` when reading a file. Unchecked exceptions, like `NumberFormatException` and `ArithmeticException`, have no such requirement.
Class
A definition of a new type: the data its objects hold (fields), how they are set up (constructors) and what they can do (methods). `Product` is a class, and each product in the shop is an object made from it.
Collections
A toolbox class of helper methods for lists, such as `Collections.sort` and `Collections.max`.
Comment
A note for humans that Java ignores, written after `//` or between `/*` and `*/`. Good comments explain why the code does something.
Compact constructor
A block inside a record, written as the record's name with no parentheses, that runs when a record is created and before the values are stored. It's where you reject bad values, such as a price of 0 or less.
Comparison operators
Operators that ask a yes-or-no question and give a `boolean`: `==` equal, `!=` not equal, `<`, `<=`, `>` and `>=`. Use `equals`, not `==`, for strings.
Compile error
A mistake the compiler finds before your program runs, such as a missing semicolon or a misspelled name. The program won't start until you fix it.
Compiler
The program (`javac`) that checks your source code and translates it into bytecode.
Component
One of the values a record holds, listed in the parentheses after the record's name. `MenuItem(String name, int priceCents)` has two components.
Concatenation
Joining strings with `+`. If one side is a number, Java turns it into text first, and it works from left to right: `"Total: " + 2 + 3` gives `Total: 23`.
ConcurrentModificationException
The exception Java throws if you add or remove items in a map or list while looping over it.
Condition
A `true` or `false` test that decides whether an `if` block runs or a loop repeats, such as `totalCents >= 5000`.
Constant
A value that must never change, declared with `final` and named in capitals with underscores, like `OUNCES_PER_BAG`. On a field, `final` means it is set once and never pointed at another object.
Constructor
A special method that sets up a new object. It has the class's name and no return type, and it runs when you write `new Product(...)`.
continue
A statement that skips the rest of the current pass through a loop and moves on to the next pass.

D

double
The type for numbers with a decimal point, such as `0.75`. Doubles aren't always exact, so money is kept in whole cents instead.

E

Eclipse Temurin
A free, widely used JDK build from the Adoptium project, made from the open-source OpenJDK code. It behaves the same as other OpenJDK builds.
Element
One value stored in an array or list.
Encapsulation
Keeping an object's fields private and offering safe public methods instead. `Product` hides `stock`, so it only changes through `sell` and `restock`.
entrySet
A map method that gives every key-value pair so you can loop over them. Each entry has `getKey()` and `getValue()`.
equals
The correct way to check whether two strings hold the same text. `==` instead checks whether two names point to the very same object, so it can be false even for matching text.
Escape sequence
A backslash code that stands for one special character inside a string: `\n` for a new line, `\"` for a quote mark and `\\` for a backslash.
Exception
An object describing an error that happens while the program runs, such as `NumberFormatException`. It is thrown, and if nothing catches it the program stops with a stack trace.

F

Field
A variable that belongs to an object, such as a product's `name`, `priceCents` and `stock`; every object gets its own copy. In a `void main()` file, a variable outside all methods is also a field.
finally
A block after `try` that runs whether or not an exception happened, used for clean-up such as closing a file.
for loop
A loop used when you know how many times to repeat. It has a starting value, a condition and an update, separated by semicolons.
For-each loop
A loop written like `for (int bags : sales)` that runs once for each element of an array or collection, without needing an index.
Format string
Text with placeholders such as `%s`, `%d` and `%.2f` that `formatted` fills in with values. A number after the `%` sets a width to line up columns, and a minus sign pads on the right instead.

G

Generics
Types written in angle brackets that say what a collection holds, such as `List<String>` or `Map<String, Integer>`.
getOrDefault
A map method that returns the value for a key, or a default you choose if the key is missing. It avoids the `null` that `get` would return.
Getter
A method that returns a private field, named `get` plus the field name, such as `getStock()`.

H

Hash code
A number worked out from a key that lets `HashMap` and `HashSet` find things quickly. Strings, number types and records provide one automatically.
HashMap
The most common kind of map (and its set counterpart), which finds keys quickly but keeps them in no useful order.

I

if statement
Runs a block of code only when its condition is `true`; `else` covers the other case, and `else if` chains more tests. Java runs only the first block whose condition is true.
IllegalArgumentException
The standard exception for "this argument isn't allowed". A method throws it when it is given a value it can't accept, such as a bad quantity, a negative price or an unknown drink.
Immutable
Can't be changed after it's created, like strings and records. To "change" one you make a new one.
Import
A line at the top of a classic Java file that says which package a name comes from, such as `import java.util.List;`. Short `void main()` files don't need it.
Index
A position in a string, array or list, counting from 0. In `"MUG-BL"`, `M` is at index 0.
Inheritance
A way for one class to be a special kind of another class, as `NumberFormatException` is a kind of `IllegalArgumentException`. Code written for the general type also works with the more specific one.
int
The type for whole numbers up to about 2.1 billion either way, such as `int bags = 4;`.
Integer division
Dividing two `int`s, which gives only the whole-number part. `10 / 4` is `2`, so use a `double` on one side to get `2.5`.
IO
A toolbox of input and output methods that comes with Java: `IO.println` prints a line, `IO.print` prints without ending the line, and `IO.readln` asks the user for text.
IOException
A checked exception that reading a file can throw. You must catch it or add `throws IOException` to the method's first line to pass it to the caller.

J

java
The command that starts the JVM. `java Hello.java` compiles and runs a source file, while `java Hello` runs an already compiled `.class` file.
JAVA_HOME
Settings the Windows installer can make. "Add to PATH" lets you start Java from any folder, and `JAVA_HOME` tells some tools where Java is installed.
JDK (Java Development Kit)
The download you need to write Java: the compiler, the JVM and Java's library of ready-made code. OpenJDK is the open-source code that several companies build free JDKs from.
JShell
A tool in the JDK that runs one line of Java at a time, handy for trying ideas. Leave it with `/exit`.
JVM (Java Virtual Machine)
The program that runs bytecode. There is one for each operating system, so the same compiled Java program runs on all of them.

K

Keyword
A word reserved by Java, such as `int`, `void` or `class`, which you can't use as a name.

L

LinkedHashMap
A map that keeps its keys in the order you added them. The register uses one so the menu stays in the order the drinks were added.
List
An ordered collection that can hold many values, which you reach by index. `List.of(...)` makes a quick list that can never change.
Local variable
A variable declared inside a method or block. Other methods can't see it, and it's gone when the block ends.
Logical operators (&&, ||, !)
Operators that combine conditions: `&&` needs both true, `||` needs at least one true, and `!` flips true and false.
long
A type for bigger whole numbers than `int`; you write an `L` after the number, as in `9000000000L`.
Loop
Code that repeats: a `while` loop repeats while its condition is true, a `for` loop counts, and each pass is an iteration. If the condition never becomes false the loop is infinite; stop it with Ctrl+C.
LTS (long-term support)
A Java version that receives security fixes for years, rather than only until the next release. A new LTS version comes out every two years, and Java 25 is one of them.

M

main
The method Java runs first when a program starts. The short form is `void main()`; older code uses `public static void main(String[] args)`, where `args` holds words typed after the program's name.
Map
A collection of key-value pairs where each unique key leads to one value, such as an SKU leading to its stock.
Map.of
A quick way to make a small fixed map by listing keys and values in turn, such as `Map.of("UPS", 3, "USPS", 4)`.
Math
A toolbox class with number helpers: `Math.round` rounds, and `Math.max` and `Math.min` give the larger and smaller of two numbers.
Method
A named block of code that does one job, can take inputs and can hand back a result.

N

new
The keyword that creates a new value: an object, an array or an empty list, as in `new Product(...)`.
null
A reference to no object at all. A map's `get` returns `null` for a missing key, and calling a method on `null` crashes the program.
NullPointerException
The exception thrown when you call a method on a variable that is `null`, meaning it points to no object.
NumberFormatException
The exception thrown when text such as `ten` can't be converted into a number by `Integer.parseInt`. It's a special kind of `IllegalArgumentException`.

O

Object
One value made from a class, created with `new`. If `Product` is the form, each filled-in product is an object.
Overloading
Giving several methods the same name but different parameters, such as two `money` methods. Java picks the one that matches your arguments.

P

Package
A named group of related library classes. `List`, `ArrayList`, `Arrays` and `Collections` live in `java.util`.
Parameter
A variable in a method's first line that receives an argument when the method is called. `priceCents` and `quantity` are the parameters of `lineTotal`.
parseInt
Methods that convert text into a number. `Integer.parseInt("12")` gives the whole number 12; the user's typed input is always text first.
private
Access words: `private` means usable only inside the class, and `public` means usable from anywhere.
Program
A list of instructions for a computer, written in a language it understands.
Prompt
A sign that a tool is waiting for you to type, such as `jshell>`.

R

Record
A one-line, immutable type for plain data, like `record MenuItem(String name, int priceCents) {}`. Java gives it a constructor, accessors, `toString` and an `equals` that compares contents.
Reference
What a variable of a class type holds: directions to where an object lives in memory, not the object itself. Copying the variable copies the reference, so both point to one object.
Remainder
What's left after whole-number division, given by `%`. Packing 23 bags in boxes of 6 leaves `23 % 6`, which is 5 bags.
Return
To hand a value back from a method with `return`, which also ends the method. The return type says what type comes back, and `void` means nothing does.

S

Scope
The part of a program where a variable exists, which is the block (braces) where it was declared.
Set
A collection with no duplicates; adding something already there does nothing. Use it when you only care whether something is present.
Single-file launch
Running `java Name.java` to compile and run a source file in one step, without a separate `javac` command.
SKU (stock-keeping unit)
A shop's short code for a product, such as `MUG-BL` for the speckled blue mug.
Source code
The instructions you write, saved in plain text files ending in `.java`.
Stack trace
The report Java prints when an exception isn't caught, listing the methods that were running. Find the first line naming your own file to see where to look.
Statement
One complete instruction in a program, ending with a semicolon.
static
Marks something that belongs to the class itself, not to any one object, so you call it on the class name, as in `Money.format(475)` or `Math.max`.
String
Text in double quotes, such as `"Portland"`. Strings are objects with many methods and never change once created; methods return new strings.
String methods (strip, substring, indexOf, split)
Methods called on a string with a dot: `strip` trims spaces, `substring` cuts out a part, `indexOf` finds where text starts, and `split` cuts a string into an array of pieces.
Switch expression
A `switch` that produces a value, with each `case` giving a result after `->` and `default` covering everything else. It ends with a semicolon.
System.out.println
The older way to print a line, still common in older code and tutorials. `System.out` is an object made for printing.

T

Terminal
A window where you type commands instead of clicking. On Linux and macOS, `sudo` in front of a command runs it as the administrator.
Ternary operator
A quick two-way choice, `condition ? a : b`, that gives `a` if true and `b` if false.
this
Means "the object being set up or used". `this.name = name;` copies the parameter into the object's field.
Throw
To create and raise an exception, as in `throw new IllegalArgumentException("...")`, so a mistake is reported where it happens.
Topics for the next book
Further Java topics beyond the basics: interfaces, lambdas and streams, `Optional` (a safer alternative to `null`), Maven and Gradle (project builders), JUnit (testing) and virtual threads (concurrency). They are the natural next steps after learning the core of the language.
toString
A method that decides how an object looks when printed or joined to a string. Writing your own replaces Java's unhelpful default such as `Product@2b4a2ec7`.
TreeMap
A map that keeps its keys sorted, which is useful when you'll print or report them.
Type
The kind of a value, such as `int` or `String`. A variable's type is fixed when you declare it.

U

UnsupportedOperationException
The exception thrown when you try to change a list made with `List.of`, which can't be changed.

V

var
Lets Java work out a variable's type from its value, as in `var cafes = 40;`. The type is still fixed afterwards.
Variable
A name that stores a value so you can use it later, declared with a type, a name and a value, as in `int bags = 4;`.
void
The return type of a method that does something but doesn't hand back a result, like `main` or a printing method.
VS Code (Visual Studio Code)
A free code editor from Microsoft. With the Extension Pack for Java installed, it colors code, suggests names and underlines mistakes in red as you type.

W

while loop
A loop that repeats as long as its condition is true, checking it before each pass. `while (true)` with a `break` inside means keep going until something says stop.
Wrapper types
The partner types a list can hold for the basic types: `Integer` for `int`, `Double` for `double`, `Boolean` for `boolean` and `Character` for `char`. Java converts between them automatically.