Daniel Voigt
1 min readFeb 18, 2021

--

Just void main() would not be possible in Java because :

1.) Every function needs a return type. Even in Golang this is the case, main just eludes the fact and uses helper functions like `Exit`

2.) For the function arguments the same reasoning goes. Go uses helper functions to access command line arguments while in Java those parameters are passed as an argument to your main function

2a.) Here I would argue in Javas favor. Why do you need to remember those special helpers in Go when main could be like any other function just marked as the entry point?

3.) As you said Java is OOP based. The main function lies within an Object which results in the `public static`.

public so the JVM can actually 'see' your main method and execute it, static because your main is not bound to an instantiation of the containing object.

It's not worse/better than other programing paradigms, it's just one of many to choose from.

I'm neither a fan of Java nor the biggest fan of OOP but there are reasons why things are the way they are.

Hope this clears it up. Have a good one.

Also there are a lot of reasons why a contained JVM is so useful instead of compiling to machine code. From portability to security there are a lot of reasons why, you can easily research. Look at Android alone.

--

--

Daniel Voigt
Daniel Voigt

Written by Daniel Voigt

Software developer, language enthusiast and Jazz musician.

Responses (1)