Click to reveal answer.
A primitive data type.
Click to reveal answer.
An object wrapper class.
Click to reveal answer.
On the **stack**. If its a local variable inside a method. In the heap if its a class field
Click to reveal answer.
On the heap.
Click to reveal answer.
false
Click to reveal answer.
null
Click to reveal answer.
No.
Click to reveal answer.
Java Generics do not support primitive data types.
Click to reveal answer.
Autoboxing.
Click to reveal answer.
Unboxing.
Click to reveal answer.
Boolean.valueOf()
Click to reveal answer.
booleanValue()
Click to reveal answer.
A NullPointerException is thrown.
Click to reveal answer.
To avoid the memory overhead and GC pressure caused by creating wrapper objects.
Click to reveal answer.
Boolean.TRUE.equals(variable)
Click to reveal answer.
1 bit.
Click to reveal answer.
It includes an object header in addition to the primitive value.
Click to reveal answer.
It skips the right-hand side if the left-hand side is false.
Click to reveal answer.
It skips the right-hand side if the left-hand side is true.
Click to reveal answer.
& evaluates both sides regardless of the first value (no short-circuiting).
Click to reveal answer.
| evaluates both sides regardless of the first value (no short-circuiting).
Click to reveal answer.
false
Click to reveal answer.
The XOR operator (^).
Click to reveal answer.
false
Click to reveal answer.
== compares memory references, while .equals() compares logical values.
Click to reveal answer.
boolean is a primitive data type, while Boolean is an object wrapper class.
Click to reveal answer.
false
Click to reveal answer.
null
Click to reveal answer.
It is stored on the heap and includes an object header plus the internal primitive value.
Click to reveal answer.
Java Generics do not support primitives; they require **object types** like Boolean.
Click to reveal answer.
A **compilation error** (primitives do not have methods).
Click to reveal answer.
It automatically converts the primitive boolean to a Boolean object using Boolean.valueOf().
Click to reveal answer.
It extracts the primitive value by automatically calling the booleanValue() method.
What is the "Hidden Danger" of unboxing a Boolean object that is null?
Click to reveal answer.
It throws a NullPointerException (NPE) because the compiler tries to call .booleanValue() on a null reference.
Click to reveal answer.
It causes performance degradation due to constant object creation and increased Garbage Collection pressure.
Click to reveal answer.
The == operator compares memory references (addresses) rather than logical values.
Click to reveal answer.
Use Boolean.TRUE.equals(yourObject).
Click to reveal answer.
It skips evaluation of the right operand because the overall result is guaranteed to be false.
Click to reveal answer.
It skips evaluation of the right operand because the overall result is guaranteed to be true.
Click to reveal answer.
To perform a null check before accessing a member: if (user != null && user.isActive()).
Click to reveal answer.
&& is short-circuiting, while & forces evaluation of both sides regardless of the first result.
Click to reveal answer.
It returns true only if the two inputs are different (one true, one false).
Click to reveal answer.
false
Click to reveal answer.
It flips the value (e.g., !true becomes false).
Click to reveal answer.
An object header in Java is a small block of metadata stored at the beginning of every object in heap memory. It serves as the runtime identity card for the object, allowing the Java Virtual Machine (JVM) to perform memory management, garbage collection, and synchronization.
Click to reveal answer.
In the Metaspace (part of the class metadata), rather than within individual heap objects.
Click to reveal answer.
Exactly one copy, shared by all instances.
Click to reveal answer.
It cannot access instance fields or instance methods because it lacks a this parameter.
Click to reveal answer.
Because static members belong to the class itself and are initialized when the class is loaded.
Click to reveal answer.
It ensures the variable can be assigned only once; its value becomes a constant.
Click to reveal answer.
It prevents any subclass from overriding that specific method.
Click to reveal answer.
The class cannot be extended (subclassed), ensuring its behavior cannot be altered through inheritance.
Click to reveal answer.
The java.lang.String class.
Click to reveal answer.
No; only the methods are effectively final. The fields must be explicitly marked final to be constant.
Click to reveal answer.
It is accessible only by classes within the same package.
Click to reveal answer.
It is accessible within the same package and by subclasses in different packages.
Click to reveal answer.
To maintain encapsulation, allowing internal data representation to change without breaking external code.
Click to reveal answer.
It is the ultimate ancestor (root) of all classes in the Java hierarchy.
Click to reveal answer.
A sealed class explicitly defines which specific subclasses are permitted to extend it.
Click to reveal answer.
It allows a permitted subclass of a sealed class to be further extended by any other class.
Click to reveal answer.
extends is used for class inheritance (IS-A); implements is used to conform to an interface's contract.
Click to reveal answer.
It ensures that changes to a variable are visible to all threads immediately by preventing local caching.
Click to reveal answer.
It ensures mutual exclusion by requiring a thread to acquire the object's intrinsic lock before execution.
Click to reveal answer.
By marking the field with the transient keyword.
Click to reveal answer.
The method is implemented in a platform-dependent language like C or C++ and is defined outside the JVM.
Click to reveal answer.
Native methods can bypass standard Java access control and language-level safety mechanisms. Native methods can modify final fields because they bypass the compile-time and runtime access checks by operating directly on raw memory. When you call a native method like System.setOut, the operation is executed via native code (usually C or C++). At this native layer, the concepts of Java language modifiers like final or private do not exist.
Click to reveal answer.
It allows access to static members (fields/methods) without qualifying them with their class name.
Click to reveal answer.
To lock its semantics and ensure subclasses cannot change its fundamental behavior.
Click to reveal answer.
Bundling data (fields) and the methods that operate on that data into a single unit (class).
Click to reveal answer.
What Java mechanism is primarily used to implement encapsulation?
Click to reveal answer.
Declaring fields as private to prevent direct external access or modification.
Click to reveal answer.
Through public getter and setter methods.
Click to reveal answer.
Logic inside a setter method can check for invalid inputs before updating the field.
Click to reveal answer.
It allows internal implementation changes without breaking external code that relies on the public API.
Click to reveal answer.
To ensure the balance is only modified through validated methods like deposit() or withdraw().
Click to reveal answer.
private.
Click to reveal answer.
It makes the field read-only to external classes.
Click to reveal answer.
It prevents unauthorized or accidental corruption of an object's internal state.
Click to reveal answer.
A block of code marked with the static keyword that initializes class-level members.
Click to reveal answer.
A block of code marked with the static keyword that initializes class-level members.
Click to reveal answer.
Automatically, when the class is first loaded into memory by the JVM.
Click to reveal answer.
Exactly once.
Click to reveal answer.
The static block executes first.
Click to reveal answer.
Top-to-bottom, in the exact order they appear in the source code.
Click to reveal answer.
Because it executes at class loading, before any object instances (and their this/super contexts) exist.
Click to reveal answer.
Static blocks allow the use of logic (e.g., loops, conditions) and error handling (try-catch).
Click to reveal answer.
The static block (runs at class load, whereas the constructor runs at instantiation).
Click to reveal answer.
Inside a static block.
In the initialization sequence of a new object, what is the execution order of the static block, instance initializer, and constructor?
Click to reveal answer.
1. Static block
2. Instance initializer
3. Constructor
Click to reveal answer.
They allow loading properties or configurations before the application logic or main starts.
Click to reveal answer.
The javac compiler.
Click to reveal answer.
.class
Click to reveal answer.
It is architecture-neutral (portable), allowing the same code to run on any system with a JVM.
Click to reveal answer.
The java command.
Click to reveal answer.
Class loaders.
Click to reveal answer.
It ensures the bytecode is safe to run and does not bypass security rules or corrupt memory.
Click to reveal answer.
It translates and executes bytecode one instruction at a time.
Click to reveal answer.
The Interpreter starts the program quickly but is slower for repeated tasks.
Click to reveal answer.
A section of code (like a loop or method) that is executed frequently.
Click to reveal answer.
It translates frequently executed bytecode into native machine code for the specific CPU.
Click to reveal answer.
To balance startup time and long-term performance using multiple compilers (C1 and C2).
Click to reveal answer.
It provides quick initial compilation with simple optimizations.
Click to reveal answer.
It performs aggressive, high-level optimizations on the most critical sections of code.
Click to reveal answer.
The JVM uses a verifier to prevent memory corruption and provides automatic garbage collection.
Click to reveal answer.
A copy of the actual numeric or boolean value.
Click to reveal answer.
A copy of the object reference (the memory address).
Click to reveal answer.
A copy of the object reference (the memory address).
Click to reveal answer.
Because the parameter is a copy of the reference pointing to the same underlying object in memory.
Click to reveal answer.
No.
What is the effect on the caller's variables after executing a swap(Object a, Object b) method that reassigns its parameters locally?
Click to reveal answer.
The caller's variables remain unchanged.
Click to reveal answer.
The method only swaps local copies of the references.
If a method triples an int parameter x (e.g., x = x * 3), what happens to the original variable in the calling method?
Click to reveal answer.
It remains unchanged.
Click to reveal answer.
False; it receives a copy of the reference to the object.
Click to reveal answer.
Both pass a copy, but the object reference copy allows access to the original object's state.
Click to reveal answer.
A class that is defined inside another enclosing class.
Click to reveal answer.
Yes.
Does an enclosing outer class automatically have direct access to private members of its nested class?
Click to reveal answer.
No (it requires an instance reference of the nested class).
Click to reveal answer.
public, protected, private, or package-private (default).
Click to reveal answer.
Static nested classes and inner classes (non-static nested classes).
Click to reveal answer.
OuterClass.StaticNested obj = new OuterClass.StaticNested();
What is the syntax to instantiate a non-static inner class named Inner using an existing outer instance outerObj?
Click to reveal answer.
OuterClass.Inner obj = outerObj.new Inner();
Click to reveal answer.
Because it is associated with the outer class itself, not with any specific outer instance.
Click to reveal answer.
By creating or receiving an explicit object instance of the outer class.
Click to reveal answer.
Local inner classes and anonymous inner classes.
Click to reveal answer.
Because every inner class instance holds an implicit strong reference to an outer class instance.
Does an instance of a static nested class hold an implicit reference to an instance of its outer class?
Click to reveal answer.
No.
If Inner is a static nested class, what is the syntax to call its static method msg() from an external class?
Click to reveal answer.
Outer.Inner.msg();
One of the challenges of developing concurrent programs in Java is the mismatch between the concurrency features offered by the platform and how developers need to think about concurrency in their programs.
Threads are the easiest way to tap the computing power of multiprocessor systems. As processor counts increase exploiting concurrency effectively will only become more important.




