Opening the reading…
Opening the reading…
PROGRAMMING FUNDAMENTALS › JAVA FUNDAMENTALS
Create a file named Main.java with this complete program. The statement inside main is included so the first run produces visible output.
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}The JVM does not begin by executing whichever line appears first in the file. It looks inside the class for the exact entry point public static void main(String[] args). That method is where this program starts. System.out.println("Hello, Java!"); is the instruction that produces the visible text after the JVM has entered main.
Each part of the method declaration has to be spelled and capitalized as shown. Main is the class containing the entry point, String is capitalized, and args is the parameter name in this source. The JVM recognizes the complete method declaration, not just a method named main with an approximately similar shape.
Which part of Main.java is the entry point where the JVM starts executing this program?
Checkpoints are not graded. They are here so you catch yourself before the quiz does — stuck, ask the tutor on the right.
The source declares public class Main, so the file must be named Main.java. Both the class name and the filename are case-sensitive. Main.java matches Main exactly, while main.java changes the uppercase M and does not satisfy the required name.
| SOURCE FILENAME | DECLARATION | RESULT |
|---|---|---|
| Main.java | public class Main | The required match |
| main.java | public class Main | The filename has the wrong case |
| Hello.java | public class Main | The filename has the wrong class name |
This matching rule lets the Java toolchain locate the public class described by the source file. If you save the code as main.java or Hello.java, the source still declares Main, but the filename does not match that declaration. Rename the file to Main.java before compiling it.
Compiling turns the Java source into a class file. From the directory containing Main.java, the JDK command javac receives the source filename, including its .java extension.
javac Main.javaA successful compilation creates Main.class. This is compiled output, not the source you edit. Compilation checks and translates the code so the JVM can launch the class.
java MainThe java command receives the class name Main, not a filename. Do not add .java or .class to this command. The JVM uses Main to locate Main.class, enters its public static void main(String[] args) method, and the println statement displays Hello, Java!.
Enter the two commands, in order, that compile Main.java and then run the compiled class.
Checkpoints are not graded. They are here so you catch yourself before the quiz does — stuck, ask the tutor on the right.
The successful flow depends on three exact names: Main.java is the source file, Main is the public class and run name, and main is the entry-point method. Changing the case or adding the wrong extension changes what the tools search for.
| COMMAND | WHAT THE TOOL RECEIVES | RESULT |
|---|---|---|
| javac Main.java | A source filename | Compiles Main.java and creates Main.class |
| java Main | A class name | Launches Main.class |
| java Main.java | A name with a source extension | Does not follow the compile-then-run command form |
| java Main.class | A name with a compiled-file extension | Does not follow the class-name form |
For example, java main asks the JVM for a class named main, but the class in this program is named Main. Java treats those names as different because capitalization matters. Similarly, javac Main is missing the source filename extension, and java Main.java gives the run command a source filename instead of the compiled class name.
The entry point is also case-sensitive. If main is changed to Main, or if String is changed to string, the method is no longer the exact entry point the JVM searches for. The source may still look close to the working version, but the JVM cannot start it through the required method.
The complete successful run uses this source in Main.java:
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}Then use the commands in this order:
javac Main.java
java MainThe first command produces Main.class. The second command launches that class, the JVM enters main, and the terminal displays exactly this output:
Hello, Java!