Advanced Java Questions and Answer for Interview
81. What is the difference between a Window and a Frame?
The Frame
class extends Window
to define a main application window that can have a menu bar.
82. Which class is extended by all other classes?
The Object
class is extended by all other classes.
83. Can an object be garbage collected while it is still reachable?
A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.
84. Is the ternary operator written x : y ? z or x ? y : z ?
It is written x ? y : z
.
85. What is the difference between the Font and FontMetrics classes?
The FontMetrics
class is used to define implementation-specific properties, such as ascent and descent, of a Font
object.
86. How is rounding performed under integer division?
The fractional part of the result is truncated. This is known as rounding toward zero.
87. What happens when a thread cannot acquire a lock on an object?
If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.
88. What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
The Reader/Writer
class hierarchy is character-oriented, and the InputStream/OutputStream
class hierarchy is byte-oriented.
89. What classes of exceptions may be caught by a catch clause?
A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.
90. If a class is declared without any access modifiers, where may the class be accessed?
A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.
Advanced Java Questions and Answer for Interview