Saturday, March 28, 2020

10 Awt Swing Interview Questions Answers Inward Java

AWT and Swing Interview Questions are locomote of whatever Java interviews which involves GUI evolution work. Since AWT(Abstract Windows Toolkit) together with Swing offers most pop Java GUI solutions, Yes, JavaFX  has withal lot of path to encompass inwards damage of popularity together with usability of Swing. In Investment banking, where Java rules on server side application development, Swing was heavily used inwards GUI evolution brace of years back. Now trends is shifting towards C# for GUI evolution due to brace of reasons e.g. expert Swing developers are non slow to last constitute every bit compared to C# developers. By the agency at that spot are withal many evolution piece of work is going on Swing. One of the argue Swing developers are high inwards demand is because Swing is chop-chop becoming a niche technology. This is surprising because  Swing is locomote of Java, but given steep learning bend of Swing to master copy dissimilar layouts together with components e.g. JTable or JList , I tend to believe it. In this article nosotros volition encounter around expert Swing Interview questions for practice. Questions similar InvokeLater vs InvokeAndWait are classic, which is e'er worth preparing.


Swing together with AWT Interview Questions Answers

Here is my listing of 10 useful Swing together with AWT Interview questions inwards Java. As per my experience, Swing interview questions comes mainly from iii parts : Swing API, Swing thread-safety issues together with questions related to layout managers.





Question 1: What is EDT thread inwards Swing?
connecting to database or opening network connectedness inwards Event Dispatcher thread or EDT thread. If y'all create that, it may Pb to frozen or hung GUI. This query leads to several other questions inwards Java, e.g. If y'all tin non opened upward database connectedness inwards EDT thread than how volition y'all opened upward db connectedness amongst push clitoris click etc. good this tin last done past times spawning a novel thread from push clitoris click together with opening db connectedness there.

Question 2: What is departure betwixt invokeAndWait together with invokeLater inwards Java?
Answer : This is 1 of my favourite Swing query inwards Java Interviews. Knowledge of invokeAndWait together with invokeLater is must for a expert Swing developer because Swing is non thread-safe together with at same fourth dimension y'all tin non perform fourth dimension consuming line of piece of work inwards EDT thread, every bit discussed inwards get-go Swing interview question. InvokeAndWait together with InvokeLater method allows to enqueue line of piece of work for EDT thread to perform, InvokeAndWait is a blocking method inwards Java together with does it synchronously together with invokeLater does it asynchronously. Since GUI tin exclusively last updated inwards Event dispatcher thread, if y'all demand to exhibit progress of whatever task, y'all tin job these 2 methods. See my post service Difference betwixt invokeAndWait together with invokeLater inwards Java for to a greater extent than detailed reply of this Swing question.

Question 3: What is departure betwixt Swing together with AWT inwards Java
Answer : One of the most often asked AWT together with Swing Interview question. One reply of this query is that, Swing is a considered every bit lite weight together with AWT is considered every bit heavy weight. Another departure betwixt AWT together with Swing is that, Swing offers uniform expect together with experience across platform piece expect together with experience of AWT GUI application are platform subject because AWT to a greater extent than often than non job native components e.g. a AWT windows volition expect dissimilar inwards DOS together with Windows operating system.

Question 4: What is departure betwixt pigment together with repaint inwards Java Swing?
Answer : This tin last a tough Java question if y'all are non familiar amongst Swing API. Well, this is similar to start() together with run() method of thread class. As calling start() method volition eventually calls run() method of Runnable interface, Calling repaint() volition telephone holler upward paint() method inwards Swing. Since icon tin exclusively last done inwards EDT thread, repaint() only seat a pigment asking inwards EDT Queue, afterward EDT thread may combine several repaint asking to 1 together with tin perform repainting. repaint() is a non a blocking method inwards Java together with returns quickly.

Question 5: What is departure betwixt BorderLayout together with GridLayout ?
Answer : This is 1 of interesting Swing interview question. BorderLayout together with GridLayout are 2 widely used LayoutManager from Swing API, old arranges components inwards predefined seat e.g. NORTH, SOUTH, EAST and WEST piece afterward arranges components 1 after other until at that spot is infinite together with wraps them afterwards. This Swing query becomes to a greater extent than hard when Interviewer asked to write code to implement a layout e.g. drawing a layout together with enquire y'all to implement every bit discussed inwards Top 10 Swing interview questions inwards Java.

Question 6: How to alter a push clitoris from enable to disable after click ?
Answer : When push clitoris is clicked an activeness effect is fired which tin last captured past times implementing ActionListener interface together with actionPerformed(ActionEvent ae) method. You tin together with then telephone holler upward button.setEnable(false) to disable this button.

Question 7: Why Swing is called lite weight ?
Answer :  Most of Swing element are inherited shape JComponent together with doesn't required a native peer together with that's why they are referred every bit lite weight component. lite weight element implement expect together with experience inwards Java rather than using expect together with experience of native element together with that's why Swing's expect together with experience remains same across platform.

Question 8: Is Swing Thread rubber inwards Java ?
Answer : This is 1 of the tricky question inwards Java Swing together with AWT. No, Swing is non thread-safe inwards Java. Swing components are non thread-safe they tin non last modified from multiple threads. All swing components are designed to last updated past times using Event dispatcher thread or EDT thread. See How to write thread-safe code inwards Java to know to a greater extent than virtually thread-safety.  By the agency y'all tin job invokeAndWait together with invokeLater to safely update swing components every bit discussed inwards previous Swing interview question.

Question 9: Which method of Swing are thread-safe?
Answer : This AWT together with Swing query is asked every bit follow-up of previous Swing interview question. Only brace of methods similar repaint() together with revalidate() are thread-safe inwards Swing, i.e. they tin last called from multiple threads without additional synchronization inwards Java.

Question 10: What is departure betwixt Container together with Component ?
Answer : Main departure betwixt Container together with Component is that old tin concord other components e.g. JFrame which is used every bit container to concord other components e.g. JButton. This is rather a uncomplicated Swing query together with to a greater extent than often than non asked inwards telephonic or upto 2 years experienced programmers.

That's on this listing of Swing Interview questions together with answers inwards Java. Despite reducing popularity together with losing contest amongst C#, Swing is a slap-up GUI applied scientific discipline together with 1 of the most preferred technology  for implementing thick clients inwards Java. Especially inwards finance together with insurance domain, where customer application demand to piece of work amongst high book of data, Java Swing is the solution. Good Swing developers are hard to honor together with that's why good paid inwards this industry.

Further Reading
Java Swing (GUI) Programming: From Beginner to Expert
Difference betwixt String together with StringBuffer inwards Java

No comments:

Post a Comment