Can you compare a float to a double?
What is yes
DOUBLE JEOPARDY: This logical phenomenon allows the expression (obj != null && obj.getValue() > 10) to run without a NullPointerException even if the object is null.
What is Short-Circuit Evaluation?
What is the term for when a local variable or parameter has the same name as an instance variable, and how do you explicitly access the instance variable in this scenario?
What is this?
If a class has a private instance variable that is a mutable object (like an array), what must the "getter" method return to ensure the class remains encapsulated and the original data cannot be changed from outside?
What is a copy of the object? (Returning the original reference allows "aliasing," which breaks encapsulation).
This property is used to find the number of elements in a standard array, while this method is used for an ArrayList.
What are .length and .size()?
This error occurs when you use == instead of .equals() to compare two String objects for equality.
What is a Logic Error? (It compares memory addresses, not content).
What is the if-statement equivalent of default in switch statements?
True or False: A static method belongs to an object, not the class.
What is False?
What term describes combining data and methods into a single unit, like a class?
What is encapsulation?
This is the result of attempting to access arr[5] in an array that has a length of 5.
What is an ArrayIndexOutOfBoundsException?
This keyword declares a constant variable whose value cannot be changed once assigned.
What is final
True or False: An else block is mandatory in an if-else statement.
What is False?
If two methods in the same class have the same name but different parameter lists, what is this called?
What is method overloading?
What is the purpose of a constructor in a Java class, and how does it differ from a method?
What is instantiation or object initialization, setting values for instance variables, while a method defines behavior that objects of the class can perform.
A constructor has the same name as the class and does not have a return type, whereas a method can have any name (except the class name) and has a return type unless it is a void method.
True or False: An ArrayList can store primitive data types like int or double directly without using wrapper classes.
What is False? (They use Autoboxing to store Integer/Double objects).
DOUBLE JEOPARDY: An array is initialized as String[] words = new String[5];. If you immediately attempt to execute if (words[0].equals("hello")), this specific runtime error occurs, and explain why.
What is a NullPointerException? Because the array was initialized with a size, but each individual element (index) currently holds a null reference, not an actual String object.
What is the purpose of a break statement in a loop?
What is to immediately exit the loop?
What is the difference between a method parameter and an argument?
What is a parameter is the variable declared in the method signature, while an argument is the actual value passed to the method when it is called?
True or False: If you write a class without defining any constructors, the Java compiler will automatically provide a default no-argument constructor; however, if you provide any constructor with parameters, that default constructor is no longer provided.
What is true?
In a 2D array declared as int[][] mat = new int[3][4];, this expression represents the number of columns.
What is mat[0].length?
In a 2D array search, if you use for (int j : row) inside for (int[] row : matrix), this specific keyword is required to exit both loops immediately upon finding a value.
What is a return statement?
Given Double d1 = 0.5; Double d2 = 0.5;, why does d1 == d2 usually return false while 0.5 == 0.5 returns true?
Because Double (capital D) is an object. The == operator checks if they point to the same memory address (reference equality), whereas 0.5 is a primitive and == compares the actual value.
Explain the difference between a static method and an instance method, and give an example of when you might use each.
What is a static method belongs to the class and can be called without creating an object, while an instance method belongs to an object and requires an instance of the class? Use static methods for utility functions (Math.sqrt()), and instance methods for behavior tied to specific objects (dog.bark()).
What is the difference between private, public, and protected access modifiers in Java, and how do they affect how classes can interact with each other?
What is private restricts access to the class itself, meaning no other class can directly access its members. Public allows full access to the class and its members from any other class. Protected allows access within the same package and by subclasses (even if they are in different packages). These modifiers control the visibility and interaction between classes by determining which classes can access certain fields, methods, or constructors.
When removing elements from an ArrayList using a standard for loop, you must traverse in this direction to avoid skipping elements. Explain why.
What is backward (or from right to left)?