Review JavaBeans concepts, javac output paths, enums and literals, CharSequence, Throwable, JMX list subclasses, and DOM versus SAX parsing.
Answer: A component model defines conventions for reusable units and how tools or containers discover and connect them. JavaBeans is one Java example, with conventions for properties, events, methods, and introspection. Other frameworks define different component lifecycles and dependency mechanisms.
There is no single rule that every Java component must follow. Distinguish JavaBeans from a Spring-managed bean, a Jakarta Enterprise Bean, or a Java module rather than treating the names as synonyms.
Answer: Use javac's -d option, for example javac -d out src/com/example/App.java. The compiler places output under the appropriate package hierarchy. Run the packaged class using the matching class path, such as java -cp out com.example.App.
The -d option controls output, not where dependencies are found. Class-path and module-path options serve separate purposes.
Answer: An enum gives the choices a distinct type, preventing accidental substitution of unrelated integer or String constants. It can define fields, methods, and constructors, and integrates with switch, EnumSet, and EnumMap. Its constants are the declared instances; callers cannot construct new enum values with new.
Enums can contain mutable fields, so type-safe constants do not automatically make every part of the instance immutable. Avoid persisting ordinal as a stable external identifier.
Answer: They are true and false, written in lowercase. Java does not use 0 and 1 as boolean values, and numeric expressions are not automatically conditions. Boolean is the wrapper reference type; it can also be null, which fails if unboxed.
Answer: Examples include integer 31, long 31L, floating-point 2.5, float 2.5f, character 'Y', String "Java", boolean true, and null. Text blocks are another form of String literal.
A literal is source notation for a value. A variable holding a value is not itself a literal, and null is usable with reference types rather than primitive types.
Answer: String, StringBuilder, StringBuffer, and CharBuffer are examples; custom classes can implement it too. The interface describes readable sequences of char values through operations such as length, charAt, and subSequence.
Implementations differ in mutability and equality. CharSequence does not impose one universal content-based equals contract. Its length counts UTF-16 code units, which can differ from the count of Unicode code points.
Answer: Names do not determine whether a Java type is an interface or class. Throwable is the superclass of Error and Exception and provides state and behavior for messages, causes, stack traces, and suppressed exceptions. The language requires thrown values to be Throwable-compatible.
Serializable and Comparable happen to be interfaces; their spelling establishes no general rule. Avoid inventing an unsupported JVM-performance explanation for this naming choice.
Answer: The API lists the JMX types AttributeList, RoleList, and RoleUnresolvedList. This is a list of known platform subclasses, not a restriction on application subclasses. ArrayList is not final, so application code can extend it subject to normal Java rules.
For a domain collection, composition around a List often gives clearer control over invariants than exposing every inherited ArrayList mutator.
Answer: Byte is a signed 8-bit integral type from -128 through 127. Char is unsigned 16-bit from 0 through 65535 and represents a UTF-16 code unit. Bytes often represent encoded or binary data; decoding a byte sequence into text requires a charset, not simply casting each byte to char.
A Unicode code point outside the basic multilingual plane uses two char values in UTF-16. See the related byte output lesson.
Answer: DOM builds an in-memory tree that supports navigation and modification. SAX reports parsing events to callbacks and can process large inputs without retaining the whole document tree. SAX handlers can still consume much memory if the application accumulates their data.
Neither is universally faster. Choose based on access patterns, document size, and required edits. Configure external resource handling for the input trust model. This example parses a fixed, in-memory document using DOM with external access disabled.
import java.io.StringReader;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import org.xml.sax.InputSource;
public class DomNames {
public static void main(String[] args) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
String xml = "<items><item>Java</item></items>";
var document = factory.newDocumentBuilder().parse(
new InputSource(new StringReader(xml)));
System.out.println(document.getDocumentElement().getTagName());
System.out.println(document.getElementsByTagName("item").item(0).getTextContent());
}
}
References: Java SE 25 Language Specification, Introspector, CharSequence, Throwable, ArrayList, DocumentBuilderFactory, SAXParserFactory.