This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Jonathan Wentworth wrote:
1). What's the purpose of javax.swingUtilities.invokeLater()?
2). Why does java need a main method? Why does it take String args? How come you can make classes without a main method if it's so necessary?
1. The purpose of static methods invokeLater(Runnable obj) and invokeAndWait(Runnable obj) is to initialize GUI on the event dispatching thread. Event dispatching thread - is a separate thread created when user interacts with one of your applications components. The difference between invokeLater(Runnable obj) and invokeAndWait(Runnable obj) is that invokeLater(Runnable obj) return immediately, and invokeAndWait(Runnable obj) waits until obj.run() returns. The run() method is an entry point for the thread.
2. Well like in any other programming languages, every program needs to have it's own "entry point" to start. JVM needs to know what to execute first when your program starts? right? So that's what main method is for. The array of String objects simply represents any command line arguments which may be "passed" to your program when it starts, like java myprogram somearguments. Not every class needs to have it's own main method, you can make hundreds of classes, but eventually one of them will need to be your "main" class which has a main method defined.
P.S By any means I'm no expert, so you may need to wait for a better answer, but you can find such information easily by yourself in javadocs.