CORE JAVA INTERVIEW QUESTIONS 4

CORE JAVA INTERVIEW QUESTIONS

201. What is the relationship between the Canvas class and the Graphics class?

         A Canvas object provides access to a Graphics object via its paint() method.

202. What are the high-level thread states?
  
         The high-level thread states are ready, running, waiting, and dead.

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

         The read() method returns -1 when it has reached the end of a file.

204. How are the elements of a BorderLayout organized?

        The elements of a BorderLayout are organized at the borders (North, South, East, and               West) and the center of a container.

205. 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.

206. 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.

207. 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.

208. How are the elements of a CardLayout organized?

         The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.

209. What is the purpose of the File class?

         The File class is used to create objects that provide access to the files and directories of a          local file system.

210. Can an exception be rethrown?

         Yes, an exception can be rethrown.

211. Which Math method is used to calculate the absolute value of a number?

         The abs() method is used to calculate absolute values.

 212. Which class is the immediate superclass of the Container class?

          Component.

213. How can the Checkbox class be used to create a radio button?

         By associating Checkbox objects with a CheckboxGroup.

214. What happens when you invoke a thread's interrupt method while it is sleeping or waiting?
         When a task's interrupt() method is executed, the task enters the ready state. The next 
         time the task enters the running state, an InterruptedException is thrown.

215. What is the difference between a Choice and a List?

         A Choice is displayed in a compact form that requires you to pull it down to see the list of          available choices. Only one item may be selected from a Choice.

         A List may be displayed in such a way that several List items are visible. A List supports            the selection of one or more List items.

216. What class of exceptions are generated by the Java run-time system?

         The Java runtime system generates RuntimeException and Error exceptions.

217. What class allows you to read objects directly from a stream?

         The ObjectInputStream class supports the reading of objects from input streams.

218. What Checkbox method allows you to tell if a Checkbox is checked?
         getState().

219. What is a compilation unit?

         A compilation unit is a Java source code file.

220. What interface is extended by AWT event listeners?
  
         All AWT event listeners extend the java.util.EventListener interface.

221. How can a dead thread be restarted?

         A dead thread cannot be restarted.

222. What is a layout manager?

         A layout manager is an object that is used to organize components in a container.

223. What is JFC

         JFC stands for Java Foundation Classes. The Java Foundation Classes (JFC) are a set of                Java class libraries provided as part of Java 2 Platform, Standard Edition (J2SE) to                      support building graphics user interface (GUI) and graphics functionality for client                      applications that will run on popular platforms such as Microsoft Windows, Linux, and              Mac OSX.

224. What is AWT?

         AWT stands for Abstract Window Toolkit. AWT enables programmers to develop Java                applications with GUI components, such as windows, and buttons. The Java Virtual                      Machine (JVM) is responsible for translating the AWT calls into the appropriate calls to              the host operating system.

225. What are the differences between Swing and AWT?

          AWT is heavy-weight components, but Swing is light-weight components. AWT is OS                   dependent because it uses native components, But Swing components are OS                               independent. We can change the look and feel in Swing which is not possible in AWT.  

          Swing takes less memory compared to AWT. For drawing AWT uses screen rendering               where Swing uses double buffering.

226. What are heavyweight components?

         A heavyweight component is one that is associated with its own native screen resource

227. What is lightweight component?

         A lightweight component is one that "borrows" the screen resource of an ancestor                      which means it has no native resource of its own -- so it's "lighter".

228. What is an event?
 
         Changing the state of an object is called an event.

229. What is an event handler?

         An event handler is a part of a computer program created to tell the program how to act          in response to a specific event.

230. What is a layout manager?

         A layout manager is an object that is used to organize components in a container.

231. Which containers use a border Layout as their default layout?

         The window, Frame and Dialog classes use a border layout as their default layout.

232. What is the preferred size of a component?

        The preferred size of a component is the minimum component size that will allow the                 component to display normally.

233. What method is used to specify a container's layout?

         The setLayout method is used to specify a container's layout.

234. Which containers use a FlowLayout as their default layout?

         The Panel and Applet classes use the FlowLayout as their default layout.

235. Which method of the Component class is used to set the position and size of a component?

         SetBounds