Public static void main (String[] args); How can I understand this in layman terms?

It might help to think of the main method as the fuse (or entry point) of the program. When Java programs are run, they can be passed arguments, similar to when you call a function. It's a little like ordering a burger, and handing a ticket through the window that contains some more details. The arguments that are passed to the program are accessible from within the program using the "args" array you see in the main method.

So if you typed "java -jar myProgam.jar Ryu Ken M.Bison" the args variable would be an array of strings you could use in your program that looked like ["Ryu", "Ken", "M.Bison"]

You said you were confused on the void return type. A return type is what one function in a Java program returns an object or primitive chunk of data to a caller that is calling it from elsewhere in the program. So if I call "Math.sqrt(16)" in a program it will return a double. To continue the sort of absurd metaphor from before, the return type is what the Kitchen makes and hands back out of the window.

The main method is the start of the program though, it isn't an order. It is literally some one coming in and opening the kitchen for the day. In a way it answers to no one because it is the initiator of everything else. You could change the return type to int or String but when the JRE tries to run your program it is told to search for a method named main with a void data type and won't find it.

The static keyword can be a little tricky. Since a function is something that generally done to an instance of an object. like myBike.pedal(3), a Static method is a method than be called on the class (the idea of an object) doesn't have to be on an instance. So a static method example might be Bike.getNumberOfWheels(). I don't have to make an instance of bike to call that. Nothing comes before or after the Main method, Alpha and Omega, all that Jazz. So there's nothing that could make an instance of an object before it. So the only way it can be called is by making it Static.

/r/javahelp Thread Parent