Compile and launch a class
What you will learn
The Java compiler and launcher perform different jobs. javac creates compiled classes; java starts a JVM and invokes the chosen entry point. Keep source files and generated class files conceptually separate.
public class Main { public static void main(String[] args) { System.out.println("Launch successful"); }}Expected output:
Launch successfulThe conventional Main entry point is called by the launcher.
How it works
From the directory containing Main.java, use javac --release 21 Main.java, then java -cp . Main. The dot explicitly identifies the current directory as the classpath. --release selects the language/API target for compilation; it does not install a runtime. These commands assume an unnamed package and a compatible JDK.
public class Main { public static void main(String[] args) { System.out.println("Revision two"); }}Expected output:
Revision twoRecompilation updates the generated class file to reflect the edited source.
Common mistakes
After editing a source file, running java Main alone may execute an older compiled class. Compile again and verify the exit status before launching.
Try it yourself
Make two revisions to a greeting, compile each, and confirm the corresponding output changes.
These are local Java practice tasks, not automatically graded ByteMind exercises. Use a patched JDK; no network or third-party dependency is needed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Compile and launch a class — knowledge check
Check your understanding of compile and launch a class.
What does -cp . select?
Why recompile after editing Main.java?