Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Assorted Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Assorted Questions" Watch "Assorted Questions" New topic
Author

Assorted Questions

Jonathan Wentworth
Greenhorn

Joined: Nov 06, 2012
Posts: 3
Please try your best to respond like I just graduated preschool, and almost dropped out due to finding my napping class too difficult.

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?

Thanks!
Waldemar Macijewski
Ranch Hand

Joined: Jun 22, 2012
Posts: 32
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?



Hi.

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.
 
wood burning stoves
 
subject: Assorted Questions
 
Similar Threads
why (String args[]) ??
main thread
why does java compiles successfully ,but doesnot run when theres not any main method
main()
String[] args