A conventional Java command-line entry point is a public static main method that the launcher calls with a String array of command-line arguments.
Your first Java program
Program
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, AITrove!");
}
}Output
Hello, AITrove!Practice
Save as Hello.java. With a JDK installed, compile with javac Hello.java and run with java Hello. Change the message and repeat.
Keep the source name and launched name separate
The source filename matches the public class name in this example: Hello.java contains public class Hello. javac creates Hello.class. The ordinary class launcher receives Hello without a .java or .class suffix; it searches the classpath for compiled code.
A package declaration changes the launched name. A class in a package is launched by its qualified name, and the classpath must point at the root containing that package directory. Running from the wrong directory can therefore fail even when compilation succeeded.
Compilation and execution are separate failure boundaries. A missing javac executable is a toolchain problem. A compiler error is a source/type problem. A class-not-found error is a launch/classpath problem. An exception after main starts is an execution problem. Do not edit the print statement to fix all four.
Change one observable condition
Pass a command-line argument and inspect args.length before reading args[0]. Launching with no arguments supplies an empty array, so an unchecked first-element access fails. That small change introduces an actual input contract without requiring console parsing.
System.out prints text to a stream. It does not return the printed value from main or persist a business record. A test that needs to examine computed results is easier to write when calculation is in a method and printing is kept at the boundary.
Use the JDK setup lesson for compile/run commands and package layout for multi-file applications. This entry-point program performs constant work and allocates only its small output-related state.
Common Mistakes
Check empty inputs and invalid values before applying this operation to application data. State whether a method edits shared state or returns a separate value.
