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.
This article is in continuation of my previous interview articles like 10 interview questions on Singleton pattern in Java, 10 interview questions answers 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 practicing 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().
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 Swing components are 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 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, 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 database, file or network connection on a click of 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 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) Question around JList like Creating a Jlist component such which should contain all the asset classes like stocks, futures, options and derivatives etc in form of String. But constraint is JList should always be sorted in Ascending order except that all assets which begins with "Electronic trading” appears on top?
This is an excellent java swing interview questions which is based on real world task and focus 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 few swing interview questions which I find interesting. Swing is particular important in Front office area and there is 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