Java File - The Java Entry Point
You might have noticed the main method within this class. This is a special method that is called automatically when your Java file is run. So, it is known as the "entry point" of your program, because you need to start all your logic there in order for it to run. However, only the one main method within the class that has the same name as the file (HelloWorld here) will be executed automatically.
Additionally, this method must have the parameter "args", with the type String[]. As we covered in the Concepts to Know section, String[] is a string array type. When your program is run, Java passes any command line arguments into this parameter. For example, if you run this command:
Then args will look like this:
This might be useful for some projects, but is generally not needed. You always have to include the args parameter in your main method, but you don't ever have to use it.
Required Keywords
The final requirement for the main method is that it must be prefaced by these 3 keywords: public, static, and void. This will be a quick explanation of each of these. These represent more complex topics that we will cover in the following sections.
public
The public keyword means that the method can be called from anywhere, not just from code that's within the class itself. This is necessary for the main method because it must be accessible to the Java Virtual Machine (JVM) in order to run your program.
static
The static keyword means that the method belongs to the class, rather than just one instance of the class. This is required because, when the JVM runs your program, it is not going to make a new instance of your class, it will just call the main method directly.
void
The void keyword means that the method does not return a value; it just executes the code within itself. This is appropriate for the main method because it is not meant to return anything to the JVM; it simply serves as the entry point for your program.
ByteBrawl
0