What value does readLine() return when it has reached the end of a file?

The readLine() method returns null when it has reached the end of a file. In Java, the readLine() method is typically associated with reading data from a BufferedReader or a similar class that reads characters from a stream. When readLine() reaches the end of a file, it returns null. Here’s a simple example using BufferedReader: java import java.io.BufferedReader; import … Read more

Name three Component subclasses that support painting.

The Canvas, Frame, Panel, and Applet classes support painting. In Core Java, three Component subclasses that support painting are: javax.swing.JPanel: JPanel is a lightweight container that is often used to group other components and provide a space for custom painting. java.awt.Canvas: Canvas is a component that allows for custom graphics drawing. You can subclass Canvas and override its paint method … Read more

What is the difference between preemptive scheduling and time slicing

Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on … Read more

What is the immediate superclss of the Applet class

Panel. In Core Java, the immediate superclass of the Applet class is the Panel class. The Applet class extends the Panel class, which, in turn, extends the Container class, and the Container class extends the Component class. Therefore, the class hierarchy looks like this: Object > Component > Container > Panel > Applet So, the … Read more

Can an object’s finalize() method be invoked while it is reachable

An object’s finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object’s finalize() method may be invoked by other objects. No, an object’s finalize() method cannot be invoked while the object is reachable. The finalize() method in Java is called by the garbage collector before reclaiming the memory occupied by an … Read more