Top 48 Java Swing Interview Questions
Q1. What Is A Convertor?
Converter is basically an utility that converts distance measurements among metric and U.S gadgets.
Q2. What Is The Difference Between Jfc & Wfc?
JFC supports robust and portable person interfaces. The Swing classes are robust, well suited with AWT, and provide you with a awesome deal of manipulate over a person interface. Since supply code is available, it's miles especially easy to extend the JFC to do precisely what you want it to do. But the wide variety of 1/3party controls written for Swing is still extraordinarily small.
WFC runs most effective at the Windows (32bit) user interface, and uses Microsoft extensions to Java for occasion dealing with and ActiveX integration. Because ActiveX components are to be had to WFC programs, there are theoretically extra controls available for WFC than for JFC. In exercise, however, most ActiveX vendors do not actively support WFC, so the wide variety of controls available for WFC is probably smaller than for JFC. The WFC programming model is carefully aligned with the Windows platform.
Q3. What Is An Event Handler In Swing?
An event handler is part of a pc application created to inform the program the way to act in reaction to a particular occasion.
Q4. What Are The Advantages Of The Event-delegation Model Over The Event-inheritance Model?
Event-delegation version has advantages over occasion-inheritance version. A)Event delegation version allows event managing with the aid of items apart from the ones that generate the activities. This permits a clean separation between a aspect's layout and its use. B)It performs lots higher in programs where many events are generated. This overall performance improvement is because of occasion-delegation version does not have to be again and again method unhandled events as is the case of the occasion-inheritance.
Q5. Which Method Is Used By The Applet To Recognize The Height And Width?
GetParameters()
Method is used by the applet to recognize the peak and width.
Q6. What Are Types Of Applets?
There are exclusive styles of applets. That are described as :
Trusted Applets.
Untrusted applets.
Trusted Applets : are applets with predefined security.
Untrusted Applets : are applets with none protection.
Q7. What Is An Event And What Are The Models Available For Event Handling?
Changing the nation of an object is referred to as an occasion. An occasion is an event item that describes a nation of trade. In different words, occasion takes place when an motion is generated, like pressing a key on keyboard, clicking mouse, and so on. There exceptional types of fashions for dealing with occasions are event-inheritance version and occasion-delegation version
Q8. What Is Difference Between Swing And Jsf?
The key difference is that JSF runs on server, It wishes a server like Tomcat or WebLogic or WebSphere. It displays HTML to the customer. But Swing program is a stand on my own software.
Q9. What Does Realized Mean?
Realized mean essentially is issue, Which has been painted on screen or that is prepared to be painted. Realization can take area through invoking any of these strategies. Which are following as :
SetVisible(actual).
Show() .
Pack().
Q10. What Is The Difference Between A Window And A Frame?
The Frame class extends Window to define a chief software window that could have a menu bar. A window can be model.
Q11. Why Should Any Swing Call Back Implementation Execute Quickly?
Callbacks are invoked by using the event dispatch thread. Event dispatch thread blocks processing of different events so long as call lower back technique executes.
Q12. When Should The Method Invokelater() Be Used?
This technique is used to make sure that Swing additives are updated thru the occasiondispatching thread.
Q13. How Are The Elements Of A Borderlayout Organized?
The Elements of a BorderLayout are prepared on the borders(North, South, East and West) and the middle of a field.
Q14. What Is Clipping?
Clipping is the manner of confining paint operations to a constrained region or form.
Q15. What Method Is Used To Specify A Container's Layout?
The setLayout() technique is used to specify a field's format.
Q16. What Is The Difference Between A Menuitem And A Checkboxmenuitem?
The CheckboxMenuItem elegance extends the MenuItem magnificence to guide a menu item that may be checked or unchecked.
Q17. Give Us The Name Of The List Layoutmanagers In Java?
List is right here :
Flow Layout Manager
Grid Layout Manager
Box Layout Manager
Border Layout Manager
Card Layout Manager
GridBag Layout Manager.
Q18. Which Containers Use A Flowlayout As Their Default Layout?
The Panel and Applet lessons use the FlowLayout as their default layout.
Q19. What Is Jfc?
JFC stands for Java Foundation Classes. The Java Foundation Classes (JFC) are a set of Java class libraries furnished as a part of Java 2 Platform, Standard Edition (J2SE) to support building pictures consumer interface (GUI) and pix capability for consumer packages in an effort to run on popular structures such as Microsoft Windows, Linux, and Mac OSX.
Q20. Why Does Jcomponent Class Have Add() And Remove() Methods But Component Class Does Not?
JComponent is a subclass of Container and may include different additives and JComponents.
Q21. What Is The Default Layout For A Contentpane In Jfc?
The Defaulf Layout for the ConteutPane in JFC is that :
BorderLayout.
Q22. What Is An Event In Swing?
Changing the state of an item is called an event.
Q23. What Is An Applet?
Applet is a java application that runs inner a web browser.
Q24. What Is The Preferred Size Of A Component?
The favored length of a thing is the minimal factor size in an effort to allow the aspect to display usually.
Q25. How Are The Elements Of A Gridbaglayout Organized?
The Elements of a GridBagLayout are prepared according to a grid. However,the factors are of different sizes and might occupy more than row or column of the grid. In addition, the rows and columns can also have diff sizes.
Q26. What Is The Relationship Between The Canvas Class And The Graphics Class?
A Canvas object offers get admission to to a photographs item thru its paint() method.
Q27. What Is The Purpose Of The Enableevents() Method?
The enableEvents() method is used to allow an occasion for a particular object.Normally, an event is enabled whilst a listener is added to an object for a particular event. The enableEvents() method is used by gadgets that handle occasions by overriding their occasiondispatch strategies.
Q28. Which Method Is Used For Setting Security In Applets?
SetSecurityManager()
Method is used for placing security in applets .
Q29. What Is Double Buffering?
Double buffering is the process of use of buffers rather than one to quickly preserve statistics being moved to and from an I/O device. Double buffering increases facts trfer velocity because one buffer may be stuffed at the same time as the alternative is being emptied.
Q30. Which Method Of The Component Class Is Used To Set The Position And Size Of A Component?
SetBounds
Method of the Component magnificence is used to set the location and length of a thing.
Q31. What Is The Diff Between Choice And The List?
The distinction are :
A Choice is displayed in a compact from that requires we to pull ot down tosee the list of to be had preference, Oly one item can be decided on from a Choice.
A List may be dsplyaed in the sort of way that numerous List gadgets are seen. A List helps the choice of the only or greater List items .
Q32. What Is Awt?
AWT stands for Abstract Window Toolkit. AWT allows programmers to expand Java applications with GUI additives, together with windows, and buttons. The Java Virtual Machine (JVM) is accountable for trlating the AWT calls into the precise calls to the host running device.
Q33. What Are The Differences Between Swing And Awt?
AWT is heavy-weight additives, but Swing is light-weight additives. AWT is OS dependent because it makes use of local components, But Swing components are OS independent. We can alternate the appearance and sense in Swing which isn't always viable in AWT. Swing takes much less reminiscence as compared to AWT. For drawing AWT makes use of display screen rendering where Swing uses double buffering.
Q34. Which Is The Super Class Of All Event Classes?
The java.Awt.AWTEvent class is the very bestlevel class in the AWT occasionclass hierarchy.
Q35. What Is The Difference Between Applications And Applets?
Application ought to be run explicitly within Java Virtual Machine while applet loads and runs itself mechanically in a java-enabled browser. Application starts execution with its fundamental method while applet starts execution with its init method. Application can run without or with graphical consumer interface whereas applet have to run within a graphical consumer interface. In order to run an applet we want a java enabled web browser or an appletviewer.
Q36. Which Containers Use A Border Layout As Their Default Layout In Swing?
The window, Frame and Dialog classes use a border format as their default layout.
Q37. What's Java Swing?
Swing is a GUI toolkit for Java. It is one a part of the Java Foundation Classes (JFC). Swing includes graphical person interface (GUI) widgets such as text boxes, buttons, split-panes, and tables.
Swing widgets provide extra sophisticated GUI additives than the sooner Abstract Window Toolkit. Since they're written in pure Java, they run the same on all platforms, unlike the AWT which is tied to the underlying platform's windowing system. Swing helps pluggable appearance and sense – now not via the use of the local platform's centers, however through more or less emulating them. This me you can get any supported appearance and experience on any platform. The drawback of light-weight additives is slower execution. The benefit is uniform conduct on all systems.
Q38. How The Canvas Class And The Graphics Class Are Related?
A Canvas object provides access to a Graphics item through its paint() approach.
Q39. What Is The What Is The Difference Between Invokeandwait() And Invokelater()??
InvokeAndWait() method in swing is synchronous. It blocks till Runnable mission is complete. InvokeLater() method in swing is asynchronous. It posts an motion event to the event queue and returns immediately. It will not look forward to the challenge to complete.
Q40. What Is A Layout Manager?
A layout manager is an item this is used to organize additives in a container.
Q41. When We Should Go For Codebase In Applet?
If the applet class isn't always inside the identical directory, codebase is used.
Q42. What Is The Lifecycle Of An Applet?
Init( ) technique - referred to as when an applet is first loaded
begin( ) method - called whenever an applet is started
paint( ) method - referred to as when the applet is minimized or maximized
forestall( ) approach - called whilst the browser movements off the applet's page
wreck( ) method - known as when the browser is completed with the applet
Q43. Difference Between Paint() And Paintcomponent()?
The Key point is that the paint() technique invokes 3 techniques within the following order :
PaintComponent()
paintBorder()
paintChildren()
As a trendy rule, in Swing, we ought to be overriding the paintComponent method except we recognize what we are doing paintComponent() paints best element (panel) however paint() paints component and all its kids.
Q44. What Is The Difference Between Awt And Swt?
SWT : SWT is stands for Standard Widget Toolkit, It is a totally unbiased Graphical User Interface (GUI) toolkit from IBM. They created it for the introduction of Eclipse Integrated Development Environment (IDE).AWT is from Sun Microsystems.
Q45. What Is The Difference Between A Canvas And A Scroll Pane?
Canvas is a part. ScrollPane is a field.
Canvas is a rectangular region in which the utility can draw or lure input occasions. ScrollPane implements horizontal and vertical scrolling.
Q46. What Is The Relationship Between Clipping And Repainting?
When a window is repainted by way of the AWT portray thread, it units the clipping areas to the place of the window that requires repainting.
Q47. What Are Heavyweight Components?
A heavyweight issue is one this is related to its own local display screen resource (generally called a peer).
Q48. What Is Lightweight Component?
A lightweight element is one that "borrows" the display useful resource of an ancestor (which me it has no native resource of its personal -- so it's "lighter").

