Saturday 31 January 2015

Java Swing - Java Interview Questions (Part4)

31. What class is at the top of the AWT event hierarchy?
java.awt.AWTEvent is that class which is at the top of the AWT event hierarchy. if they say java.awt.Event, they haven't deal with swing or AWT in a while.

32. Explain how to render an HTML page using only Swing?
HTML page is bassically render the page using the JEditorPane or JTextPane and set it with the HTMLEditorKit, and load it that the use of swing in HTML pages.

33. How would you detect a keypress in a JComboBox?
"KeyListner in a JComboBox" is the abssically tyoe of the trick . many programmer is said thet: "add the  keyListner in a JComboBox ". But its main use in the  " add the  keyListner in a JComboBox as a editor component.

34. Why should the implementation of any Swing callback (like a listener) execute quickly?
Any swing callback execute quickly should be implementation Because callbacks are invoked by the event dispatch thread which will be blocked processing other events for as long as our method takes to execute.

35. In what context should the value of Swing components be updated directly?
Any ther context is not thread safe. But in  callback methods , Swing components should be updated directly only in the context.In callback methods invoked from the event dispatch thread.

36. Why would you use SwingUtilities.invokeAndWait or SwingUtilities.invokeLater?
I want to update a Swing component but I'm not in a callback. If I want the update to happen immediately or perhaps for a progress bar component, then I'd use invokeAndWait. If I don't care when the update occurs, I'd use invokeLater.

37. If your UI seems to freeze periodically, what might be a likely reason?
A callback implementation like ActionListener.actionPerformed or MouseListener.mouseClicked is taking a long time to execute thereby blocking the event dispatch thread from processing other UI events.

38. Which Swing methods are thread-safe?
The only thread-safe methods are following here :
> Repaint(),
> Revalidate(), and
> Invalidate()

39. Why won't the JVM terminate when I close all the application windows?
The AWT event dispatcher thread is not a daemon thread. You must explicitly call System.exit to terminate the JVM.

40. What is double buffering ?
Double buffering is the process of use of two buffers rather than one to temporarily hold data being moved to and from an I/O device. Double buffering increases data transfer speed because one buffer can be filled while the other is being emptied.
More Questions & Answers :-

No comments:

Post a Comment