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: 
As you know, Python uses "duck typing": it doesn't matter what type something is, only what it can do. As a result, you never need to declare types for your variables.

In Java, that's not true: every variable has a declared type, and the compiler enforces that type. Trying to store, for example, a `String` reference in an `int`-declared variable will produce a compile-time error. Proponents of duck typing claim that this decreases flexibility, but strong-typing enthusiasts point out that compile-time errors are easier to fix than run-time bugs.

But the same is true of your method arguments. Since your method requires an argument of type `String[]`, it must be provided an argument of type `String[]`. Nothing else will do.

Fortunately, since it's the `main` method, the Java interpreter takes care of passing in an argument: specifically, an array of the command-line args with which your program was executed. If you'd like to ignore it, feel free. Your program will run just fine without paying attention to the argument, but it's invalid if one isn't passed in.

(By the way, if this were any method but the `main` method, you'd be free to declare it with whatever argument types you'd like, including no arguments at all. But since the Java interpreter will be passing in an array of the command line arguments, this particular method must be prepared to accept them.)
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).