โ๏ธMain Method
Last updated
Last updated
A method defines an action that an object can perform. Think of it like a verb, just like objects can jump, sleep, etc.
Within a method's curly brackets is where you write the code for the action. This could be setting or retrieving variable values, performing calculations, printing outputs, etc.
When calling a method on an object, you use the dot notation (objectName.methodName). This tells the object to carry out what's defined in that method
The main() method is the heart and soul of a Java program โค๏ธ. It is the entry point that kickstarts a Java application's execution.
๐ Where to Find main()
The main() method resides inside a class and must be declared as:
๐๏ธ Understanding the Syntax
public - main() is accessible from outside the class
static - main() can be called without creating an instance of the class
void - main() does not return anything
String[] args - main() accepts a string array as parameter for command line arguments
โถ๏ธ Starting the Execution
The Java runtime calls the main() method to run your application. Code inside main() gets executed line by line.
๐ค Passing Inputs to main()
The args parameter of main() can be used to pass inputs and configure the application at runtime.
๐ Using main()
Typically, main() will:
Create objects
Call other methods