• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assorted Questions

 
Jonathan Wentworth
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic