31 Java Interview Questions and Answers

Compiled By Unknown - No Comments
313. Question: Under what conditions is an object's finalize() method invoked by the garbage collector?
Answer : The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable

314. Question: How are this() and super() used with constructors?
Answer : this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor

315. Question: What is the relationship between a method's throws clause and the exceptions that can be thrown during the method's execution?
Answer : A method's throws clause must declare any checked exceptions that are not caught within the body of the method

316. Question: What is the difference between the JDK 1.02 event model and the event-delegation model introduced with JDK 1.1?
Answer : The JDK 1.02 event model uses an event inheritance or bubbling approach. In this model, components are required to handle their own events. If they do not handle a particular event, the event is inherited by (or bubbled up to) the component's container. The container then either handles the event or it is bubbled up to its container and so on, until the highest-level container has been tried. In the event-delegation model, specific objects are designated as event handlers for GUI components. These objects implement event-listener interfaces. The event-delegation model is more efficient than the event-inheritance model because it eliminates the processing required to support the bubbling of unhand led events

317. Question: How is it possible for two String objects with identical values not to be equal under the == operator?
Answer : The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory

318. Question: Why are the methods of the Math class static?
Answer : So they can be invoked as if they are a mathematical code library

319. Question: What Checkbox method allows you to tell if a Checkbox is checked?
Answer : getState()

320. Question: What state is a thread in when it is executing?
Answer : An executing thread is in the running state

321. Question: What are the legal operands of the instance of operator?
Answer : The left operand is an object reference or null value and the right operand is a class, interface, or array type

322. Question: How are the elements of a GridLayout organized?
Answer : The elements of a GridBad layout are of equal size and are laid out using the squares of a grid

323. Question: What an I/O filter?
Answer : An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another

324. Question: If an object is garbage collected, can it become reachable again?
Answer : Once an object is garbage collected, it ceases to exist.It can no longer become reachable again

325. Question: What is the Set interface?
Answer : The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements

326. Question: What classes of exceptions may be thrown by a throw statement?
Answer : A throw statement may throw any expression that may be assigned to the Throwable type

327. Question: What are E and PI?
Answer : E is the base of the natural logarithm and PI is mathematical value pi

328. Question: Are true and false keywords?
Answer : The values true and false are not keywords

329. Question: What is a void return type?
Answer : A void return type indicates that a method does not return a value

330. Question: What is the purpose of the enableEvents() method?
Answer : The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods

331. Question: What is the difference between the File and RandomAccessFile classes?
Answer : The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file

332. Question: What happens when you add a double value to a String?
Answer : The result is a String object

333. Question: What is your platform's default character encoding?
Answer : If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1.

334. Question: Which package is always imported by default?
Answer : The java.lang package is always imported by default

335. Question: What interface must an object implement before it can be written to a stream as an object?
Answer : An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object

336. Question: How are this and super used?
Answer : this is used to refer to the current object instance. super is used to refer to the variables and methods of the superclass of the current object instance

337. Question: What is the purpose of garbage collection?
Answer : The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and reused

338. Question: What is a compilation unit?
Answer : A compilation unit is a Java source code file

339. Question: What interface is extended by AWT event listeners?
Answer : All AWT event listeners extend the java.util.EventListener interface

340. Question: What restrictions are placed on method overriding?
Answer : Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method

341. Question: How can a dead thread be restarted?
Answer : A dead thread cannot be restarted

342. Question: What happens if an exception is not caught?
Answer : An uncaught exception results in the uncaughtException() method of the thread's ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown

343. Question: What is a layout manager?
Answer : A layout manager is an object that is used to organize components in a container



Tags:

No Comment to " 31 Java Interview Questions and Answers "