This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes why public static void main(String args[]) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why public static void main(String args[])" Watch "why public static void main(String args[])" New topic

why public static void main(String args[])

John Chong

Joined: Jan 18, 2001
Posts: 16
May I know why the word static? And is args[] used to capture command line input like javac kkk?
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
static is a keyword in the java language, and it is also a modifier. When a method or variable is declared static, it means that it can be used throughout the whole class without instantiating an object. If it isn't static, then you must create an object to invoke the non-static method or non-static variable. You are correct about args[]. For instance say I had a program called Go. When I use the command java Go one two
arg[0]= one , arg[1]= two.
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
static is not used to catch anything its an access modifier which tells that inside this method you don't need to create any instance of an object to execute it. As for a parameter it takes an array of strings because you might pass certain arguments to your program to let it know what to do. Special conditions that you might think of.

Val SCJP <BR>going for SCJD
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4351

Static is a modifier but not an access modifier. When a member is static it means that no matter how many instances of the class you have, there is only instance of the static member which they all share.

Visit my download page
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: why public static void main(String args[])
It's not a secret anymore!