Top 10 Java Swing interview questions answers asked in Investment banks

Java Swing is heavily used in developing trading application front end. Doesn’t matter whether its front office or middle office you will find swing GUI everywhere. Swing GUI is used to developed Order entry system, order monitoring GUI and for other tools which trader or operations can use on different trade life cycle. Due to it’s heavily usage there are lot of requirements of java swing developer in IB. In this post we will see some java swing interview questions asked in various interview. These swing interview questions are based on my experience as well as collected from friends and colleagues. So if you are going for any java swing development job interview you can use these java swing interview questions for practice, answers of swing question are also given.

swing interview questions answers in javaThis article is in continuation of my previous interview articles like 10 interview questions on Singleton pattern in Java, 10 interview questions answer on Serialization in Java and 15 java threading interview question answers and.If you haven’t read them already you may find them useful for your job interview or practice purpose

Swing Interview questions answers

Let’s start with simple questions and then moving on to complex and little harder one, normally that’s how it goes in swing interview as well.

1) What is Event-Driven-Thread (EDT) in Swing?
Event-Driven-Thread or EDT is a special thread in Swing and AWT. Event-Driven Thread is used to draw graphics and listen for events in Swing. You will get a bonus point if you able to highlight that time consuming operations like connecting to database, opening a file or connecting to network should not be done on EDT thread because it could lead to freezing GUI because of blocking and time consuming nature of these operations instead they should be done on separate thread and EDT can just be used to spawn those thread on a button click or mouse click.

2) Does Swing is thread-safe? What do you mean by swing is not thread-safe?
This swing interview questions is getting very popular now days. Though it’s pretty basic many developer doesn't understand thread-safety issue in Swing. Since Swing components are not thread-safe it means you can not update these components in any thread other than Event-Driven-Thread. If you do so you will get unexpected behavior. Some time interviewer will also ask what are thread-safe methods in swing which can be safely called from any thread only few like repaint() and revalidate(). See this article for a detailed answer.

3) What are differences between Swing and AWT?
One of the classic java swing interview questions and mostly asked on phone interviews. There is couple of differences between swing and AWT:

1) AWT component are considered to be heavyweight while Swing component are lightweights
2) Swing has plug-gable look and feel.
3) AWT is platform depended same GUI will look different on different platform while Swing is developed in Java and is platform dependent.

4) Why are Swing components called lightweight component?
Another popular java swing interview question, I guess the oldest that is generally comes as followup of earlier question based on your answer provided. AWT components are associated with  native screen resource and called heavyweight component while Swing components is uses the screen resource of an ancestor instead of having there own and that's why called lightweight or lighter component.

5) What is the difference between invokeAndWait and invokeLater?
This swing interview question is asked differently at different point. some time interviewer ask how do you update swing component from a thread other than EDT, for such kind of scenario we use SwingUtilities.invokeAndWait(Runnable r) and SwingUtilities.invokeLetter(Runnable r) though there are quite a few differences between these two, major one is invokeAndWait is a blocking call and wait until GUI updates while invokeLater is a non blocking asynchronous call. In my opinion these question has its own value and every swing developer should be familiar with these questions or concept not just for interview point of view but on application perspective. you can read more on my post  How InvokeAndWait and InvokeLater works in Swing

6) Write code for JTable with custom cell editor and custom cell renderer?
Now comes harder part of swing interviews, questions asked in this part of Swing interview is mostly about writing code and checking developer’s capability of API familiarity, the key concept of swing code etc.

JTable is one of favorite topic of all Swing interviews and most popular questions on swing interviews are from JTable why? Because here interviewer will directly asked you to write code another reason is JTable heavily used in all Electronic trading GUI. GUI used for online stock trading uses JTable to show data in tabular format so an in depth knowledge of JTable is required to work on online trading GUI developed in Swing. While this question is just an example questions around JTable are mostly centered around updating table, how do you handle large volume of data in table, using customize cell renderer and editor, sorting table data based on any column etc. so just make sure you have done quite a few handsone exercise on JTable before appearing for any java swing interview in IB.

7) Write code to print following layout (mainly focused on GridBag layout)?
After JTable second favorite topic of swing interviewer is GridBagLayout. GridBagLayout in swing is most powerful but at same time most complex layout and a clear cut experience and expertise around GridBagLayout is desired for developing Swing GUI for trading systems. No matter whether you are developing GUI for equities trading, futures or options trading or forex trading you always required GridBagLayout. Swing interview question on GridBagLayout will be mostly on writing code for a particular layout just like an example shown here. In which six buttons A, B, C, D, E and F are organized in certain fashion.

8) How do you handle opening of the database, file or network connection on a click of a button?
This one is one of the easy java swing interview question. Interviewer is interested on whether you know the basic principle of Java GUI development or not. answer is you should not do 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 request. Only condition is that your GUI should always be responsive no matter what happens on network connection or database connection because these operations usually take time.

9) Prediction of the output of code?
This is another category of Swing interview questions asked in IB whether they will give you code and asked what would be the output , how will the GUI look like. This type of question is based upon how well you understand and visualize the code. Whether you are familiar with default layout manager of various component classes or not e.g. default layout of JFrame is BorderLayout. So do some practice of these kinds of java Swing interview questions as well?

10) The question around JList like Creating a Jlist component such which should contain all the asset classes like stocks, futures, options and derivatives etc in the form of String. But constraint is JList should always be sorted in Ascending order except that all assets which begin with "Electronic trading” appears on top?
This is an excellent java swing interview questions which are based on real-world task and focuses on JList component, Sorting, and customizing JList model. For sorting, you can use comparable in Java and by customizing the JList model you can display content as requested. Once you successfully answer this question there may be some followup on customizing the color of cell etc which can be done by customizing renderer.

These are just a few swing interview questions which I find interesting. Swing is particularly important in Front office area and there is a lot of demand of good Swing developers in Wall Street firms. If you have good skills on FIX Protocol + Core Java + Swing you would be most sought after in electronic trading domain. Anyway, this list is no means complete so please share any interesting java swing interview questions you have faced.

My Previous interview articles


Anonymous said...

EDT != Event Driven Thread
EDT == Event Dispatch Thread

Tavi said...

I believe its called Event Dispatch Thread... (

Anyway... nice list of sweetpoints :)

Javin @ stringbuffer vs Stringbuilder said...

my bad Tavi and Anonymous , its indeed called Event Dispatcher Thread.

Prabhu said...

Indeed these interview questions on Swing is much better than the other source available on Internet. I just think number of questions are little less but quality is awesome. Few more JFC Swing interview questions from my collection:

1) Why can't you call paint() method directly instead of calling repaint() method?

2) What is clipping? How do you create animation using Clipping in Canvas?

3) How do you sort JTable based upon Colum?
4) When do you use JOptionPane in Swing?
5) What is difference between Container and Component in Swing?
6) How do you make a Swing application to run as Java web start?
7) What is JNLP file?
8) Is Swing Single Threaded?
9) Tell me 5 Swing components you have used?
10) Which Swing GUI Designer have you used?
11) How do you create layout for Swing components?
12) Difference between BorderLayout, FlowLayout, CardLayout and BoxLayout in Swing?
13) is Swing part of Java Development kit?
14) Which JAR contains Swing code ?
15) How do you write your own Swing component like Ticker?
16) Can you create 3D effect using Swing component

Let me know if you have answers of these Swing questions.

Virat said...

Can you please share some AWT Interview questions and some Java FX Interview question. I know little bit of Swing and AWT and learning Java FX. There is not many Java FX or AWT interview question available, Please share with answers. Thanks

Anonymous said...

Couple of Swing questions for experienced and Senior Java Developers, mostly 4 to 6 years experieced :

1) Is Swing is thread-safe? (No)
2) Can we modify TableModel in thread which loads data from database? (No)
3) What is SwingWorker? How does it work? It works on worker pattern and used to perform time consuming task in worker thread. It also manages to update EDT when task is done.
4) How do you find if current thread is Event Dispatcher Thread? (SwingUtilities.isEventDispatcherThread()) method

Post a Comment