Java Get Started
Every Java application has a class containing a main method, which is the entry point of the program. The method signature `public static void main(String[] args)` is fixed and must be written exactly this way.
Java is a strongly typed, compiled language: source code (.java) is compiled to bytecode (.class), which the JVM then interprets or JIT-compiles into machine instructions.
public class Main {
public static void main(String[] args) {
// code goes here
}
}Anatomy of a Java program
A Java file contains at least one class. The class containing main() is where execution starts. Statements end with semicolons and blocks use curly braces.
Compiling and running
Save your file as ClassName.java (must match the public class name), compile with javac, then run with java.
public class Main {
public static void main(String[] args) {
System.out.println("My First Java Program");
}
}My First Java ProgramThe main method is the entry point of every Java application.
Key points
- Every Java app needs a main method.
- The file name must match the public class name.
- Statements end with semicolons.
- Java is case-sensitive.
