main method
The method the JVM calls first when it starts a program: public static void main(String[] args).
In more detail
It must be public so the JVM can see it and static so it can be called before any object exists. It returns nothing and receives the command-line arguments as an array of strings. Every part of the signature is fixed by the platform, which is part of the ceremony around a small Java program.
Example
public static void main(String[] args) { System.out.println("Hello"); }Related terms
- java command — The command that starts a JVM and runs a program, given a class name, a JAR file with -jar, or a single source file.
- static — A keyword marking a field or method as belonging to the class itself, so it can be used without creating an object.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
Taught in
- The Virtual Machine, The Kit And The Runtime — Modern Java: Virtual Threads & High-Throughput Services
- The Lifecycle Of A Java Program — Modern Java: Virtual Threads & High-Throughput Services
- Spring Boot Auto Configuration — Modern Java: Virtual Threads & High-Throughput Services
- Objects, Nested Classes And Garbage Collection — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Classes, Records And Initialisation Order — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Scope, var And Immutable Objects — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Modules And Concurrency — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep