Core Java
core1HelloWorld
- Path
- pkg1core/core1HelloWorld.java
- Package
- pkg1core
- Study order
- 0
- Run
- Single-file source launch
- Command
- java pkg1core/core1HelloWorld.java
- Lesson
- Back to the chapter
There is no in-browser runner. This is the file from the curriculum, unchanged.
1package pkg1core;2 3/*4 * core1HelloWorld.java5 * ----------------6 * The classic first program. Demonstrates the minimal structure of a Java app.7 *8 * EXPLANATION:9 * - Every Java application starts in `public static void main(String[] args)`.10 * - `public` : the JVM must be able to call it from outside the class.11 * - `static` : no object needs to exist to call it.12 * - `void` : main returns nothing.13 * - `String[] args` : command-line arguments.14 *15 * RUN: java core1HelloWorld.java (single-file launch)16 * or: javac core1HelloWorld.java && java core1HelloWorld17 */18public class core1HelloWorld {19 public static void main(String[] args) {20 System.out.println("Hello, JavaMastery!");21 22 // Command-line args demo: try `java core1HelloWorld.java Alice`23 if (args.length > 0) {24 System.out.println("Hello, " + args[0] + "!");25 } else {26 System.out.println("(Tip: pass your name as an argument.)");27 }28 }29}