Glossary
Abstraction
The principle of hiding complex implementation details and showing only the essential features of an object or system.
Example:
When you use new Scanner(System.in)
, you're using abstraction because you don't need to know how the Scanner
internally reads input, just that it does.
Constructor
A special method used to create and initialize new objects of a class, setting up their initial characteristics.
Example:
When you write new Car("Red", 4)
, the Car
constructor is called to build a new car object.
Constructor Overloading
The ability for a class to have multiple constructors, each with a unique signature (different number or types of parameters, or different order of parameter types).
Example:
A Student
class might have one constructor Student(String name)
and another Student(String name, int id)
, demonstrating constructor overloading.
Constructor Signature
The unique blueprint of a constructor, defined by its class name and the ordered types of its parameters.
Example:
For a Book
class, Book(String title, String author)
is a constructor signature, distinct from Book(int pages, String title)
.
Default Constructor
A constructor that takes no parameters. If no constructors are explicitly defined in a class, Java provides a public, no-argument default constructor.
Example:
If you create new Game()
, and no other constructors are defined, Java provides a default constructor to initialize the Game
object.
Object Creation
The process of instantiating a new object from a class, typically involving the `new` keyword and a constructor call.
Example:
The line Dog myDog = new Dog("Buddy");
demonstrates object creation for a Dog
instance named myDog
.
Parameter List
The set of values or arguments passed to a constructor or method, providing initial data for the object's attributes or for method execution.
Example:
In new Game("Chess", 2)
, ("Chess", 2)
is the parameter list providing the game name and player count.
Pass-by-Reference
In Java, for objects and arrays, a copy of the memory address (reference) is passed, meaning changes made to the object through the parameter *do* affect the original object.
Example:
When you pass a List<String> names
to a method, it's pass-by-reference, so adding an element to names
inside the method will modify the original list.
Pass-by-Value
Java's mechanism for passing arguments, where a copy of the primitive value is passed to the method, so changes inside the method do not affect the original variable.
Example:
If you pass an int score
to a method, the method receives a pass-by-value copy, so changing score
inside the method won't change the original score
outside.
`NullPointerException`
A common runtime error in Java that occurs when an attempt is made to use a `null` object reference as if it were a valid object, such as calling a method on it.
Example:
If String name = null;
and you try name.length();
, it will cause a NullPointerException because name
doesn't point to a valid String object.
`new` keyword
A Java keyword used to allocate memory for a new object and invoke its constructor.
Example:
To make a new Robot
object, you must use Robot r2d2 = *new* Robot();
.
`null` object
A reference variable that does not point to any object in memory, indicating the absence of an object.
Example:
Setting String message = *null*;
means the message
variable currently refers to no string object.