27 Java Interview Questions and Answers part 2

Compiled By Unknown - No Comments
199. Question: Does garbage collection guarantee that a program will not run out of memory?
Answer : Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection

200. Question: What restrictions are placed on the location of a package statement within a source code file?
Answer : A package statement must appear as the first line in a source code file (excluding blank lines and comments)

201. Question: Can an object's finalize() method be invoked while it is reachable?
Answer : 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

202. Question: What is the immediate superclass of the Applet class?
Answer : Panel

203. Question: What is the difference between preemptive scheduling and time slicing?
Answer : 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 priority and other factors

204. Question: Name three Component subclasses that support painting.
Answer : The Canvas, Frame, Panel, and Applet classes support painting

205. Question: What is the immediate superclass of the Dialog class?
Answer : Window

206. Question: What is clipping?
Answer : Clipping is the process of confining paint operations to a limited area or shape

207. Question: What is a native method?
Answer : A native method is a method that is implemented in a language other than Java

208. Question: Can a for statement loop indefinitely?
Answer : Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ;

209. Question: What are order of precedence and associativity, and how are they used?
Answer : Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left

210. Question: When a thread blocks on I/O, what state does it enter?
Answer : A thread enters the waiting state when it blocks on I/O

211. Question: To what value is a variable of the String type automatically initialized?
Answer : The default value of an String type is null

212. Question: What is the catch or declare rule for method declarations?
Answer : If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause

213. Question: What is the difference between a MenuItem and a CheckboxMenuItem?
Answer : The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked

214. Question: What is a task's priority and how is it used in scheduling?
Answer : A task's priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks

215. Question: What class is the top of the AWT event hierarchy?
Answer : The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy

216. Question: When a thread is created and started, what is its initial state?
Answer : A thread is in the ready state after it has been created and started

217. Question: Can an anonymous class be declared as implementing an interface and extending a class?
Answer : An anonymous class may implement an interface or extend a superclass, but may not be declared to do both

218. Question: What is the range of the short type?
Answer : The range of the short type is -(2^15) to 2^15 - 1

219. Question: What is the range of the char type?
Answer : The range of the char type is 0 to 2^16 - 1

220. Question: In which package are most of the AWT events that support the event-delegation model defined?
Answer : Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package

221. Question: What is the immediate superclass of Menu?
Answer : MenuItem

222. Question: What is the purpose of finalization?
Answer : The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected

223. Question: Which class is the immediate superclass of the MenuComponent class.
Answer : Object

224. Question: What invokes a thread's run() method?
Answer : After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed

225. Question: What is the difference between the Boolean & operator and the && operator?
Answer : If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped



Tags:

No Comment to " 27 Java Interview Questions and Answers part 2 "