I'm trying to print "Hello World" from a Java program, but I am a little confused with the main method:
public static void main(String[] args)
and
public static void main(String args[])
Both these functions perform the same task. How does this happen?
I know the function of String but not of the args.
In Java:
String args[]
is exactly equivalent to:
String[] args
You are defining a method named "main" which is public
(anyone can call it), static
(it's a class method, not an instance method), and returns void
(does not return anything), and takes a parameter named args
that is a String
array.
In Java you can declare a String array as:
String[] args
or
String args[]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With