These questions update legacy finalization advice and review maps, Object methods, reference types, constants, and JavaBean conventions.
Answer: Finalization is deprecated for removal and should not be used for new resource-management code. Historically, automatic finalization invoked an object's finalizer at most once, and a finalizer could make the object reachable again. Neither behavior makes finalization a reliable cleanup protocol: execution is not prompt or guaranteed, and finalization can be disabled.
Use AutoCloseable with try-with-resources for deterministic resource release. Garbage collection reclaims memory; it does not replace explicit management of files or connections. Cleaner can support a carefully designed fallback for certain resources, but its execution is also not timely or guaranteed before process exit. Do not teach object resurrection as a recommended technique.
Answer: Map is an interface representing key-value associations, with at most one mapped value per key. Different keys may map to equal values. Keys and values use reference types in ordinary generic maps; primitive arguments can be boxed into wrapper objects.
The implementation determines ordering, null support, concurrency, and key equivalence. HashMap uses hashing and equals; TreeMap uses comparison, so a comparison result of zero identifies an existing key. Map does not extend Collection, although keySet, values, and entrySet expose collection views backed by the map.
Answer: They are public instance methods declared by Object and can be overridden by classes. Equals expresses equality, hashCode supports hashing, and toString supplies a textual representation. Object's default equals uses reference identity.
When overriding equals, also provide a consistent hashCode: equal objects must have equal hash codes, but unequal objects may collide. ToString is useful for diagnostics and should not casually expose secrets or be treated as a stable serialization format. Records supply implementations of these methods based on their record components, unless overridden.
Answer: LinkedList is a class, not an interface. It implements List and Deque using a doubly linked structure. Access by index requires traversal; insertion and removal at an end, or through an already-positioned iterator, avoid shifting an array's elements.
Finding a middle position is still linear work, and node allocation has memory costs. Thus âalways use LinkedList for middle removalâ is not a sound rule. ArrayList is often suitable for general lists, and ArrayDeque for stack or queue use. LinkedList permits null, is not synchronized, and remains limited by available resources despite not requiring an initial capacity.
Answer: The reference-type grammar covers class types, interface types, type variables, and array types. A type variable such as T in a generic declaration represents a reference type subject to its bounds. Enums and records are kinds of classes, rather than separate peers of the class category.
Arrays are objects, even when their components are primitive values. An interface-typed variable holds a reference to a compatible implementing object, not a standalone interface instance. Null has a special unnamed type and can be assigned to reference-typed variables; it is not an additional ordinary class.
Answer: A commonly shared constant uses static final, such as static final int MAX_RETRIES = 3;. Static makes it class-level; final prevents reassignment. The precise language term constant variable applies to a final primitive or String variable initialized with a constant expression, and does not require static.
Not every static final field is a compile-time constant. A final reference to a mutable collection cannot be reassigned, but its contents may still change. Use immutable values or unmodifiable structures when callers must not mutate the data, and distinguish an unmodifiable container from deeply immutable elements.
Answer: A property is an exposed logical value discovered through accessors or explicit BeanInfo, not simply a private field. Conventional accessors are getName and setName; a primitive boolean property can use isEnabled. A property may be computed, read-only, or write-only.
import java.beans.Introspector;
public class BeanProperty {
public static class Settings {
private boolean enabled;
public boolean isEnabled() { return enabled; }
public void setEnabled(boolean enabled) { this.enabled = enabled; }
}
public static void main(String[] args) throws Exception {
Settings bean = new Settings();
bean.setEnabled(true);
for (var property : Introspector.getBeanInfo(Settings.class, Object.class)
.getPropertyDescriptors()) {
System.out.println(property.getName() + "="
+ property.getReadMethod().invoke(bean));
}
}
}
This prints enabled=true. The java.beans API is in the java.desktop module. Record accessors such as name() do not automatically follow the classic getName convention, although frameworks may support records through their own rules.
Answer: Events let a component notify registered listeners when something changes or an action occurs. A bound property commonly sends PropertyChangeEvent notifications; PropertyChangeSupport helps manage listeners and dispatch those events.
An ordinary setter does not automatically fire an event. The bean must implement that behavior or rely on a framework that supplies it. Listener registration and removal are part of the lifecycle. Event notification is also not inherently asynchronous: PropertyChangeSupport invokes listeners through the firing call, so slow listeners and callbacks need consideration.
Answer: First identify what the question asks. A method name can be a legal Java identifier without matching a JavaBean accessor convention. For example, enabled() can be legal Java while isEnabled() is the conventional primitive-boolean getter.
Do not assume every current certification exam follows wording rules from an old study guide. If an exam-specific claim matters, consult that exam's published objectives. For code review, evaluate compilation and convention-based discovery separately; an import or a private backing field does not make an arbitrary method a bean property accessor.
Answer: With ordinary file-based javac compilation, at most one public top-level class can be declared, and its name must match the source filename. The file may also contain package-access top-level classes. This restriction does not mean only one public class declaration at any nesting depth.
A public class can contain public member classes. Java SE 25 also supports compact source files that implicitly declare a class; their rules should not be confused with an ordinary compilation unit's explicit public top-level declaration. Keeping independent top-level types in separate files is generally clearer.
References: Finalization status, Types and final variables, Bean introspection, and Property-change events.