Glossary
Array
A data structure used to store a fixed-size sequential collection of elements of the same data type.
Example:
A list of student scores like {85, 92, 78, 95} can be stored efficiently in an integer array.
Array Index
A numerical position used to access individual elements within an array, starting from 0 for the first element.
Example:
In an array int[] scores = {100, 90, 80};, scores[0] refers to the element at array index 0, which is 100.
ArrayIndexOutOfBoundsException
A runtime error that occurs when a program attempts to access an array element using an index that is outside the valid range of indices for that array.
Example:
Trying to access myArray[10] when myArray only has 5 elements (indices 0-4) will cause an ArrayIndexOutOfBoundsException.
Class
A blueprint or template for creating objects, defining their common attributes (fields) and behaviors (methods).
Example:
The Car class might define attributes like color and make, and behaviors like startEngine() and accelerate() for all car objects.
Conditional Statements
Code constructs that allow a program to execute different blocks of code based on whether a specified condition evaluates to true or false.
Example:
An online store might use a conditional statement to check if a user's cart total is over $50 to apply a free shipping discount.
For Loop
A control flow statement used for iterating a specific number of times, typically when the number of iterations is known beforehand.
Example:
To print numbers from 1 to 10, you would use a for loop that initializes a counter, checks if it's less than or equal to 10, and increments it each time.
If Statement
A fundamental conditional statement that executes a block of code only if its specified condition is true.
Example:
If a game character's health is less than 10, an if statement could trigger a 'low health' warning on the screen.
Immutable (String)
Describes objects whose state cannot be modified after they are created. In Java, Strings are immutable.
Example:
When you concatenate two strings like "Hello" + "World", you don't change "Hello"; instead, a new immutable string "HelloWorld" is created.
Inheritance
An object-oriented programming principle where a new class (subclass) acquires the properties and behaviors (fields and methods) of an existing class (superclass), promoting code reuse.
Example:
A SportsCar class could use inheritance to extend a Car class, automatically gaining color and startEngine() while adding its own unique features like turboBoost().
Method
A block of code within a class that defines a specific behavior or action that an object of that class can perform.
Example:
The bark() method in a Dog class would define the action of a dog barking.
Method Overriding
A feature of object-oriented programming where a subclass provides its own specific implementation for a method that is already defined in its superclass.
Example:
While a generic Animal class might have a makeSound() method, a Dog subclass would use method overriding to implement makeSound() specifically as "Woof!" instead of a generic sound.
Object
An instance of a class, representing a real-world entity with its own unique state (attribute values) and behavior.
Example:
If Car is a class, then myRedCar = new Car(); creates an object named myRedCar that is a specific instance of a car.
Polymorphism
An object-oriented programming concept that allows objects of different classes to be treated as objects of a common superclass, enabling a single interface to represent different underlying forms.
Example:
If Animal has a makeSound() method, polymorphism allows you to call animal.makeSound() on a Dog object (which barks) or a Cat object (which meows) through a common Animal reference.
String
A sequence of characters, treated as an object in Java, used to represent text.
Example:
The variable userName storing "Alice" is an example of a String.
Subclass
A class that inherits from another class (its superclass), gaining access to its public and protected members.
Example:
In a game, Warrior and Mage could be subclasses of a Character superclass, inheriting basic health and movement abilities.
Superclass
A class whose properties and methods are inherited by another class (its subclass).
Example:
The Vehicle superclass might define common attributes like speed and fuelType that all types of vehicles, like Car or Motorcycle, would share.
While Loop
A control flow statement that repeatedly executes a block of code as long as a specified condition remains true.
Example:
A program waiting for user input might use a while loop to keep prompting the user until valid input is received.
charAt(int i) (String method)
A String method that returns the character at the specified index `i` within the string.
Example:
To get the first letter of a name String name = "Charlie";, you would use name.charAt(0) to retrieve 'C', as string indices start at 0.
equals(String other) (String method)
A String method used to compare the content of two strings, returning `true` if they have the same sequence of characters, and `false` otherwise.
Example:
To check if a user's typed password inputPassword matches the stored correctPassword, you must use inputPassword.equals(correctPassword) instead of ==.
indexOf(String str) (String method)
A String method that returns the starting index of the first occurrence of the specified substring `str` within the string, or -1 if not found.
Example:
If String sentence = "The quick brown fox";, sentence.indexOf("fox") would return 16, indicating where the word 'fox' begins.
length (Array property)
A property of an array that returns the number of elements it can hold.
Example:
If String[] names = new String[5];, then names.length would be 5, indicating the maximum capacity of the array.
length() (String method)
A String method that returns the number of characters in the string.
Example:
If String password = "secret123";, password.length() would return 9, which could be used to enforce a minimum password length().
substring(int begin, int end) (String method)
A String method that returns a new string that is a part of the original string, starting from the `begin` index up to, but not including, the `end` index.
Example:
From String url = "www.example.com";, url.substring(4, 11) would extract "example", representing the domain name.