← Back to Week 2 Hub

Glossary / Key Terms

Every important term from Week 2 — search or browse by topic

🔍
Strings
String
A sequence of characters (text) stored as an object in Java. Strings are enclosed in double quotes and are one of the most commonly used types.
String greeting = "Hello, World!";
Immutable
Something that cannot be changed after it is created. In Java, Strings are immutable — every operation that appears to modify a String actually creates a brand-new String object in memory.
String name = "Alice"; name = name.toUpperCase(); // Creates a NEW String "ALICE" // The original "Alice" object still exists (until garbage collected)
StringBuilder
A mutable alternative to String that lets you modify text without creating new objects each time. Use it when you need to build a string piece by piece, especially inside loops.
StringBuilder sb = new StringBuilder(); sb.append("Hello"); sb.append(", "); sb.append("World!"); String result = sb.toString(); // "Hello, World!"
Mutable
Something that can be changed after it is created. StringBuilder is mutable — you can add, remove, or replace characters without creating a new object.
Concatenation
Joining two or more Strings together using the + operator. Since Strings are immutable, each concatenation creates a new String object.
String full = "Hello" + " " + "World"; // "Hello World"
Escape Character
A backslash (\) followed by a special character to represent things you cannot type directly in a String. Common escapes: \n (new line), \t (tab), \" (double quote), \\ (backslash).
System.out.println("She said \"Hello\""); // She said "Hello" System.out.println("Line1\nLine2"); // Two separate lines
charAt()
Returns the single character at a given index position in a String. The index is zero-based, so the first character is at index 0.
String word = "Java"; char first = word.charAt(0); // 'J' char last = word.charAt(3); // 'a'
indexOf()
Returns the index (position) of the first occurrence of a character or substring within a String. Returns -1 if not found.
String text = "Hello World"; int pos = text.indexOf("World"); // 6 int nope = text.indexOf("Java"); // -1
substring()
Extracts a portion of a String. Takes a start index (inclusive) and an optional end index (exclusive). If no end index is given, it goes to the end of the String.
String text = "Hello World"; String sub1 = text.substring(6); // "World" String sub2 = text.substring(0, 5); // "Hello"
split()
Divides a String into an array of substrings based on a delimiter (separator pattern). The delimiter itself is removed from the results.
String csv = "Alice,Bob,Charlie"; String[] names = csv.split(","); // names[0] = "Alice", names[1] = "Bob", names[2] = "Charlie"
trim()
Returns a new String with leading and trailing whitespace removed. Does not affect spaces in the middle of the String.
String messy = " Hello World "; String clean = messy.trim(); // "Hello World"
equals()
Compares the content of two Strings for an exact match (case-sensitive). Always use this instead of == to compare Strings.
String a = "Hello"; String b = "Hello"; boolean same = a.equals(b); // true
equalsIgnoreCase()
Compares the content of two Strings while ignoring uppercase vs lowercase differences. Useful for user input where capitalization may vary.
String input = "YES"; boolean match = input.equalsIgnoreCase("yes"); // true
startsWith()
Returns true if the String begins with the specified prefix. Case-sensitive.
String url = "https://example.com"; boolean secure = url.startsWith("https"); // true
endsWith()
Returns true if the String ends with the specified suffix. Case-sensitive.
String file = "report.pdf"; boolean isPdf = file.endsWith(".pdf"); // true
length()
Returns the number of characters in a String. Note: this is a method (with parentheses), unlike array.length which is a field (no parentheses).
String word = "Java"; int len = word.length(); // 4
Pattern.quote()
Wraps a string so that special regex characters (like . or |) are treated as plain text. Useful with split() when your delimiter has special meaning in regex.
String data = "one|two|three"; // Wrong: split("|") treats | as regex OR // Right: String[] parts = data.split(Pattern.quote("|")); // parts = ["one", "two", "three"]
Type Conversion
Integer.parseInt()
Converts a String containing a whole number into an int value. Throws NumberFormatException if the String is not a valid integer.
String text = "42"; int number = Integer.parseInt(text); // 42
Double.parseDouble()
Converts a String containing a decimal number into a double value. Throws NumberFormatException if the String is not a valid number.
String text = "3.14"; double pi = Double.parseDouble(text); // 3.14
Float.parseFloat()
Converts a String containing a decimal number into a float value. Less commonly used than Double.parseDouble() since double is the default decimal type in Java.
String text = "2.5"; float value = Float.parseFloat(text); // 2.5f
NumberFormatException
An error thrown when you try to parse a String into a number but the String does not contain a valid number. For example, parsing "abc" or "" as an integer.
int x = Integer.parseInt("abc"); // CRASH! NumberFormatException int y = Integer.parseInt(""); // CRASH! NumberFormatException
LocalDate
A class from java.time that represents a date (year, month, day) without a time component. You can parse dates from Strings or create them directly.
LocalDate today = LocalDate.now(); // Current date LocalDate date = LocalDate.parse("2026-04-12"); // From String (ISO format)
DateTimeFormatter
A class that defines patterns for formatting and parsing dates. Lets you convert between date objects and custom String representations like "MM/dd/yyyy".
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("MM/dd/yyyy"); LocalDate date = LocalDate.parse("04/12/2026", fmt); String text = date.format(fmt); // "04/12/2026"
ISO 8601
An international standard date format: YYYY-MM-DD (e.g., 2026-04-12). This is the default format that LocalDate.parse() expects when no formatter is specified.
Object-Oriented Programming
Class
A blueprint or template that defines what data (fields) and behavior (methods) a type of object will have. Think of it as a cookie cutter — it defines the shape, but is not a cookie itself.
public class Employee { private String name; private double salary; }
Object
A concrete, individual thing created from a class. Each object has its own copy of the fields defined in the class. If the class is the cookie cutter, the object is the actual cookie.
Employee emp1 = new Employee("Alice", 50000); Employee emp2 = new Employee("Bob", 55000); // emp1 and emp2 are two separate objects
Instance
Another word for an object. When you create an object from a class, that object is called an "instance" of that class. emp1 is an instance of Employee.
Instantiate
The act of creating a new object (instance) from a class. You instantiate a class by using the new keyword followed by a constructor call.
new Keyword
The keyword that tells Java to create a new object in memory. It allocates space for the object, calls the constructor, and returns a reference to the new object.
Employee emp = new Employee("Alice", 50000); // ^^^ allocates memory and calls constructor
Constructor
A special method that runs automatically when you create a new object with new. It initializes the object's fields. Has the same name as the class and no return type.
public class Employee { private String name; public Employee(String name) { // Constructor this.name = name; } }
Parameterless Constructor
A constructor that takes no parameters. Sets fields to default values. Java provides one automatically only if you do not write any constructors yourself.
public Employee() { this.name = "Unknown"; this.salary = 0; }
Parameterized Constructor
A constructor that accepts one or more parameters, allowing you to set field values when the object is created instead of using defaults.
public Employee(String name, double salary) { this.name = name; this.salary = salary; }
Encapsulation
The practice of keeping an object's fields private and controlling access through public getter and setter methods. This protects the data from being changed in unexpected ways.
Access Modifier
A keyword that controls who can see and use a class, field, or method. The three you learn in Week 2 are public, private, and package-private (default).
public
An access modifier meaning "anyone can access this." Used on methods you want other classes to call (like getters and setters) and on the class itself.
public String getName() { return this.name; }
private
An access modifier meaning "only this class can access this." Used on fields to enforce encapsulation — outside code must use getters and setters instead.
private String name; // Only accessible inside this class
Package-Private (Default)
The access level when you write no modifier at all. The member is visible to any class in the same package, but hidden from classes in other packages.
String name; // No modifier = package-private
Getter
A public method that returns the value of a private field. Named getFieldName() by convention. Provides read access without exposing the field directly.
public String getName() { return this.name; }
Setter
A public method that sets (changes) the value of a private field. Named setFieldName() by convention. Can include validation logic to prevent bad data.
public void setName(String name) { this.name = name; }
this Keyword
A reference to the current object. Used inside a class to distinguish between a field and a parameter with the same name, or to call another constructor.
public void setName(String name) { this.name = name; // this.name = field, name = parameter }
Overloading
Having multiple methods (or constructors) with the same name but different parameter lists. Java picks which one to call based on the arguments you pass.
// Method overloading public double calculate(double price) { ... } public double calculate(double price, double tax) { ... } // Constructor overloading public Employee() { ... } public Employee(String name) { ... } public Employee(String name, double salary) { ... }
Signature
The combination of a method's name and its parameter types (in order). The signature is what makes each overloaded method unique. Return type is NOT part of the signature.
// These have DIFFERENT signatures: calculate(double) // 1 param calculate(double, double) // 2 params calculate(int) // different type
Loops
while Loop
A loop that checks its condition before each iteration. If the condition is false from the start, the body never executes. Use when you don't know in advance how many times to repeat.
int count = 0; while (count < 5) { System.out.println(count); count++; }
do/while Loop
A loop that executes the body first, then checks the condition. Guarantees the body runs at least once, even if the condition is false. Great for menu-driven programs.
int choice; do { System.out.println("Enter choice (0 to quit): "); choice = scanner.nextInt(); } while (choice != 0);
for Loop
A loop with three parts in one line: initialization, condition, and update. Best when you know exactly how many times to repeat.
for (int i = 0; i < 10; i++) { System.out.println("Step " + i); } // init: int i = 0 | condition: i < 10 | update: i++
for-each Loop (Enhanced for)
A simplified loop for iterating through every element in an array or collection. You get each element directly — no index variable needed. Cannot modify the array or skip elements.
String[] names = {"Alice", "Bob", "Charlie"}; for (String name : names) { System.out.println(name); }
Iteration
One single pass through a loop's body. If a loop runs 5 times, that is 5 iterations. Also used broadly to mean "repeating a process."
Loop Counter
A variable (often named i, j, or count) that tracks how many times a loop has run. In a for loop, this is the variable in the initialization part.
for (int i = 0; i < 5; i++) { // ^^^ loop counter }
Infinite Loop
A loop whose condition never becomes false, so it runs forever. Usually a bug (you forgot to update the counter), but sometimes intentional with a break to exit.
// Bug: forgot count++ while (count < 5) { System.out.println(count); // Prints forever! } // Intentional: while (true) { if (done) break; }
break
A statement that immediately exits the current loop entirely. Execution continues with the first line after the loop. Only breaks out of the innermost loop.
for (int i = 0; i < 100; i++) { if (i == 5) break; // Stops the loop at i=5 System.out.println(i); } // Prints: 0, 1, 2, 3, 4
continue
A statement that skips the rest of the current iteration and jumps to the next one. The loop itself keeps running — only the current pass is cut short.
for (int i = 0; i < 5; i++) { if (i == 2) continue; // Skips i=2 System.out.println(i); } // Prints: 0, 1, 3, 4
Thread.sleep()
Pauses the program for a given number of milliseconds. Often used inside loops to create a visible delay (e.g., a countdown timer). Requires handling InterruptedException.
for (int i = 3; i > 0; i--) { System.out.println(i); Thread.sleep(1000); // Wait 1 second } System.out.println("Go!");
Arrays
Array
A fixed-size container that holds multiple values of the same type. Once created, its size cannot change. Access elements by their index number.
int[] scores = new int[5]; // Empty array of 5 ints String[] names = {"Alice", "Bob"}; // Array with initial values
Element
A single value stored inside an array. Each element has a position (index) and holds one value of the array's declared type.
int[] scores = {90, 85, 78}; // 90 is element at index 0, 85 is element at index 1, etc.
Index (Subscript)
The number that identifies an element's position in an array. Used inside square brackets to read or write a specific element.
int[] scores = {90, 85, 78}; int first = scores[0]; // Read element at index 0 scores[1] = 95; // Write element at index 1
Zero-Based Indexing
The rule that array indices start at 0, not 1. The first element is at index 0, the second at index 1, and the last element is at index length - 1.
String[] colors = {"Red", "Green", "Blue"}; // Index: 0 1 2 // colors.length = 3, but last valid index = 2
array.length
A field (not a method — no parentheses!) that returns the number of elements in an array. Compare with String.length() which is a method (with parentheses).
int[] scores = {90, 85, 78}; int size = scores.length; // 3 (no parentheses!) // vs String: String word = "Hello"; int len = word.length(); // 5 (with parentheses!)
ArrayIndexOutOfBoundsException
An error thrown when you try to access an array index that does not exist — either negative or greater than or equal to length.
int[] arr = {10, 20, 30}; // Valid indices: 0, 1, 2 int x = arr[3]; // CRASH! ArrayIndexOutOfBoundsException int y = arr[-1]; // CRASH! ArrayIndexOutOfBoundsException
Arrays.sort()
Sorts the elements of an array in ascending order. Modifies the array in place (does not create a new one). Works on both primitive and object arrays.
int[] nums = {3, 1, 4, 1, 5}; Arrays.sort(nums); // nums is now {1, 1, 3, 4, 5}
System.arraycopy()
Copies elements from one array to another. Takes five arguments: source array, source position, destination array, destination position, and number of elements to copy.
int[] src = {1, 2, 3, 4, 5}; int[] dest = new int[5]; System.arraycopy(src, 0, dest, 0, 5); // dest is now {1, 2, 3, 4, 5}
Arrays.fill()
Sets every element in an array (or a range of elements) to the same value. Useful for initializing an array to a specific default.
int[] scores = new int[5]; Arrays.fill(scores, 100); // scores is now {100, 100, 100, 100, 100}
Arrays.equals()
Compares two arrays element by element and returns true if they have the same length and identical elements in the same order. Do not use == to compare arrays — it only checks if they are the same object.
int[] a = {1, 2, 3}; int[] b = {1, 2, 3}; boolean same = Arrays.equals(a, b); // true boolean wrong = (a == b); // false (different objects!)
Arrays.binarySearch()
Searches a sorted array for a specific value and returns its index. The array must be sorted first! Returns a negative value if the element is not found.
int[] nums = {10, 20, 30, 40, 50}; int idx = Arrays.binarySearch(nums, 30); // 2 int nope = Arrays.binarySearch(nums, 35); // negative (not found)
null
A special value meaning "no object." When you create an array of objects (like Strings), every element starts as null until you assign a real value. Trying to call a method on null causes a NullPointerException.
String[] names = new String[3]; // names[0] = null, names[1] = null, names[2] = null System.out.println(names[0].length()); // CRASH! NullPointerException
No terms match your search. Try a different keyword.

Tip: Use Ctrl+F for browser-level search, or use the filter box above to narrow by topic and term name.

← Week 2 Cheat Sheet Common Errors Guide →