I\'m just beginning to write programs in Java. What does the following Java code mean?
public static void main(String[] args)
What
The String[] args
parameter is an array of Strings passed as parameters when you are running your application through command line in the OS.
So, imagine you have compiled and packaged a myApp.jar
Java application. You can run your app by double clicking it in the OS, of course, but you could also run it using command line way, like (in Linux, for example):
user@computer:~$ java -jar myApp.jar
When you call your application passing some parameters, like:
user@computer:~$ java -jar myApp.jar update notify
The java -jar
command will pass your Strings update
and notify
to your public static void main()
method.
You can then do something like:
System.out.println(args[0]); //Which will print 'update'
System.out.println(args[1]); //Which will print 'notify'