10 Java Swing Interview Questions And Answers


1) What is Event-Dispatcher-Thread (EDT) in Swing?

The Event Dispatcher Thread or EDT is a special thread in Swing and AWT. The Event-Driven Thread is used to render pictures and listen for occasions in Swing. You gets an advantage point if you are able to spotlight that time-ingesting operation like connecting to database, starting a document, or connecting to community must no longer be finished on EDT thread because it can cause freezing GUI due to blocking off and time-eating nature of those operations alternatively they have to be achieved on separate thread and EDT can just be used to spawn those thread on a button click or mouse click on.

2) Does Swing is thread-safe? What do you suggest by way of swing isn't thread-secure?

This swing interview query is getting very popular these days. Though it is pretty basic many builders don't understand thread-safety difficulty in Swing. Since Swing components aren't thread-safe it approach you can't replace these components in any thread apart from Event-Dispatcher-Thread.

If you do so you will see surprising behavior e.G. Freezing GUI because of the impasse of incorrect values and so forth. Some time interviewer will even ask what are thread-safe strategies in the Swing API? Those are the strategies which can be effectively known as from any thread and there are only multiple them e.G. Repaint() and revalidate(). See this text for extra dialogue on Swing and thread-safety.

3) What are differences among Swing and AWT?

One of the traditional Java swing interview questions and ordinarily asked on phone interviews. There are more than one differences among Swing and AWT:

  • The AWT issue are taken into consideration to be heavyweight whilst Swing factor are taken into consideration lightweights
  • The Swing GUI has pluggable look and experience.
  • The AWT is platform established i.E. The equal GUI will look distinctive on distinct structures due to the fact they use local additives e.G. A Frame will appearance exclusive on Windows and Linux in case you pick native components. On the other hand, Swing additives are developed in Java and are platform based. It also offer steady GUIs across platform e.G. In case you run NetBeans which is created in Java on Linux or Windows you will see consistency in GUI.

4) Why Swing components are called lightweight additives?

Another popular Java swing interview query, I wager the oldest that generally comes as a observe-up to the sooner question based in your solution supplied. Since the AWT components are associated with native display useful resource they may be known as heavyweight thing even as Swing components use the display aid of an ancestor as an alternative of getting their own and that is why referred to as light-weight or lighter issue. See here for greater AWT base Interview Questions in Java.

5) What is the difference between invokeAndWait and invokeLater?

This swing interview query is requested differently at exceptional factors. Some time interviewer asks how do you update swing element from a thread aside from EDT instead of directly asking the difference among invokeAndWait() and invokeLater() method of Swing API.

6) Write code for JTable with custom cellular editor and custom cellular renderer?

Now comes the more difficult a part of Swing interviews, questions requested on this a part of Swing interviews is in general about writing code and checking developer's experience of API and GUI improvement and information of the important thing concept of swing code and many others.

7) How do you cope with starting of the database, report, or community connection on a click of a button?

This one is one of the easy Java swing interview questions. The interviewer is inquisitive about whether or not you understand the simple precept of Java GUI development or not. The solution is, you have to not try this operation in EDT thread instead spawn a new thread from ActionListener or button and disable the button until operation gets completed to avoid resubmitting the request.

8) Write code to print following format (particularly targeted on GridBag layout)?

After JTable, the second favourite topic of the swing interviewers is GridBagLayout. The GridBagLayout inside the swing is maximum effective however on the same time, maximum complicated format and a clear reduce experience and expertise around GridBagLayout is desired for growing Swing GUI for trading structures.

9) Prediction of the output of code?

This is some other category of Swing interview questions asked in IB whether they'll give you code and requested what would be the output, how will the GUI seem like. This sort of question is primarily based upon how nicely you apprehend and visualize the code.

10) The query around JList is like Creating a JList component such which have to include all of the asset instructions like Stocks, Futures, Options, and FX and so forth within the form of String. But constraint is that the JList should always be taken care of within the ascending order besides that all belongings which begin with "Electronic trading" appears on pinnacle?

This is an super Java Swing interview questions which are primarily based at the actual-international venture and makes a speciality of JList element, Sorting, and customizing JList model. For sorting, you may use comparable in Java and by customizing the JList model you could display content material as asked. Once you effectively answer this query there can be a few observe up on customizing the shade of cell and so forth which can be executed by means of customizing renderer.

Writtern on Pak24tv

Related Blogs