Question: I am trying to learn Java now and this is the hello world program and it already have started to baffle me. I am used to python and I found [this](http://qatar.cmu.edu/~dfossati/15-121-spring12/resources/Java4Python.pdf) tutorial (ebook) simple and concise for programmers who have python background. 

Hello world program in Java from the book:

```
public class Hello {

public static void main (String[] args) {

     System.out.println("Hello World!");
}
}

```

As the book says, the equivalent code for this in python is:

```
class Hello(object):
  @staticmethod
  def main(args):
     print "Hello World!"

```

I completely understand the python code. However, I have a problem with Java code and I want to be clear before I proceed further so that I get the root knowledge of language in my brain.

The book says (as copied from book):

> 
> ...we have one parameter. The name of the parameter is args however,
>  because everything in Java must have a type we also have to tell the
>  compiler that the value of args is an array of strings. For the moment
>  You can just think of an array as being the same thing as a list in
>  Python. The practical benefitt of declaring that the method main must
>  accept one parameter and the parameter must be a an array of strings
>  is that if you call main somewhere else in your code and and pass it
>  an array of integers or even a single string, the compiler will flag
>  it as an error.
> 
> 
> 

This does not make any sense to me. Why can I not pass anything since my function doesn't require anything? What happens if I just pass (String args).

Since I am completely newbie to Java, please bear with me.

Answer: 
Every program has an entry point/starting point from where its execution would start. Java searches for a specific method signature it will start from in a class to run your application which is the 'main' method.

```
public static void main(String args[]);

```

This must be implemented in order for you to start your program ( in a class you want to start off from). And because of this rule/restriction we must pass array of strings ( which are similar to list of strings in Python) as arguments.

Now for the second part, if your program does not require any parameters at startup, dont pass any. You will get args as an empty String array in main method. The following line would print out the length of arguments passed to your main method.

```
System.out.println("Length of arguments = " + args.length);

```

You might also want to look at [Sun's Java guide for starters](http://docs.oracle.com/javase/tutorial/java/index.html).
I hope this answers your question.
First of all, note that the main method is called by the JVM to start the program and passed the command line arguments. It can be called by Java code, but this is very rarely done.

Anyway, this is the signature of the method:

```
public static void main (String[] args)

```

It says that it requires a parameter that is an array of Strings. If you call it like this:

```
main(new String[1]); 

```

or this:

```
main(methodThatReturnsAStringArray()); 

```

it will work. But these will cause a compiler error:

```
main(new int[0]); 
main("test"); 

```

Because the type of the parameter in the call does not match the type the method signature requires. You *can* pass a null pointer:

```
main(null); 

```

Because arrays are a reference type, and `null` is a valid value for all reference types. But then the method will have to test for that case, otherwise it will throw a `NullPointerException` when it tries to access the array.

Another thing you can do is overloading, by declaring *another* method:

```
public static void main (String args)

```

So when you call

```
main("test");

```

the compiler would determine that there is a method with a matching signature and call that.

Basically, the point of all this is that many programmer errors are caught by the compiler rather than at runtime (where they may only be discovered in some special circumstances if it's a rarely executed code path).