1/31
Comprehensive practice questions and review cards covering Java basics, OOP principles, inheritance, exceptions, collections, and I/O streams.
What is the meaning of "platform-independent" in Java?
Write once, run anywhere.
What is the primary purpose of the Java Virtual Machine (JVM)?
It is used to interpret and execute Java bytecode.
Which two components constitute the Java platform?
The Java Virtual Machine (JVM) and the Java Application Programming Interface (API).
What are the file extensions for Java source code and compiled Java code?
Java source code uses the extension .java, and compiled bytecode uses the extension .class.
What is the entry point method of a Java application?
The main method.
What is the default value of an uninitialized instance variable of type double in Java?
0.0
What is the output of attempting to modify an array element using an enhanced for-loop, as in: for (int i : a) { i = 1; } System.out.println(a[1]);?
0, because the enhanced for-loop variable receives a copy of each element's value and does not modify the underlying array.
What is a checked exception in Java?
A checked exception is an exception that is checked during compilation time.
Which access modifier is used to hide members of a class from outside classes?
private
If a class does not explicitly declare a constructor, what does the Java compiler automatically provide?
A default constructor.
Can constructors be overridden in Java?
No, constructors cannot be overridden because they are not inherited by subclasses.
When both a single-int overload method(int x) and a varargs overload method(int... a) exist, which one is chosen when passing a single integer argument like method(2)?
The exact match method(int x) is selected over the variable-argument method.
In Java inheritance, are instance variables overridden dynamically like instance methods?
No, instance variables are resolved at compile time based on the reference type, not overridden dynamically at runtime.
What is the difference between composition and inheritance?
Composition is a way to create objects by combining existing objects, while inheritance is a way to reuse code.
What is the key structural difference between a standard array and an ArrayList in Java?
A standard array has a fixed length that cannot change, whereas an ArrayList can dynamically adjust its size.
Which method is used to determine the number of elements in an ArrayList?
size()
What happens when a duplicate element is added to a Java Set?
The Set will keep the old element and reject/not add the duplicated one, preserving unique elements.
What is the internal data structure difference between HashSet and TreeSet?
HashSet is backed by a hash table, whereas TreeSet is backed by a balanced binary tree (Red-Black tree).
Which keyword prevents an object's member variable from being serialized during ObjectOutputStream operations?
transient
What are the fundamental data units of low-level streams and high-level streams?
The low-level stream's data unit is a byte; the high-level stream's data unit is a primitive type or character.
Which method of the File class checks if a file is marked as hidden?
isHidden()
Which checked exception is thrown when an attempt is made to open a nonexistent file using FileInputStream?
FileNotFoundException
What is the return type of the instanceof operator?
A boolean.
What is the correct syntax for an interface named B to inherit from interface A?
public interface B extends A {}
What is the accessibility scope of a variable declared with the default (package-private) modifier?
It can be accessed by classes and subclasses defined within the same package.
Which abstract class is the direct superclass of all numeric wrapper classes (Byte, Short, Integer, Long, Float, Double) in java.lang?
java.lang.Number
Why does calling super(color, price) after setting this.type = type in a subclass constructor cause a compile error?
Because a call to the superclass constructor (super()) must be the very first statement in a constructor.
Can a top-level outer class be declared with the private access modifier?
No, declaring a top-level class as private causes a compile-time error.
What is the result of calling str.concat(" University!") on a String str = "FPT" without reassigning the return value?
The length of str remains 3 because Strings in Java are immutable.
What does comparing two distinct newly allocated Integer objects with == (e.g., new Integer(0) == new Integer(0)) return?
false, because == compares object memory references, not their primitive values.
What is the range of values that can be assigned to a variable of type short in Java?
−215 through 215−1 (−32768 to 32767).
Why does passing a primitive double x to a method that performs x = x - 2; fail to modify the value of x in the caller?
Java uses pass-by-value, so the method receives a copy of the primitive value and modifications are local to that method.