Java syntax equivalent to Python syntax?
Question: So, if you have ever looked on my page you might have found that I'm a Grade
10 student that's just started his computer science course in high school.
Yaay! :)

The language that we are learning is Java, something which in my opinion, is
very different from Python (at least so far). However, there's one thing that
I have noticed when starting a Java program. Sorry if the syntax is off or
wrong.

    
    
    public static void main(String [] args){
        String school = "A beautiful school";
        System.out.print(school);
    }
    

Is this equivalent to Python's:

    
    
    if __name__ == "__main__":
        school = "A beautiful school"
        print(school)
    

I've asked my teacher about this but didn't seem to get an answer that I
completely understand. I also took a look at this
[question](http://stackoverflow.com/questions/2390063/what-does-public-static-
void-mean-in-java), but it seemed as if it only answered the different
keywords `public`, `static`, `void`, (which I only slightly understand as of
now).

So does `public static void main` act the same as `if __name__ == "__main__"`?
If not, what's the difference between the two? Thanks in advance!


Answer: When you do `if __name__ == "__main__":` you are checking to see if you are in
`main` already.

It's different because the entire python script is considered to be "main" in
the way that `public static void main` is considered to be "main" in java.

When you run a python file, it starts from the very top and works its way down
looking for executable statements (it bypasses declarations such as function
`def`initions and `class`es).

When you run a java class it looks for the `main` method and starts from
there.

The reason for having this `if __name__ == "__main__":` is so that it _only_
executes when you run the python file directly.

As you will learn soon, python files can also be considered as "modules" to be
included from other python scripts. In such cases you would not want this
'main' logic to be implicitly executed.

Much like you almost never invoked a classes `main` when importing it as part
of a larger app in java.

