You need to compile and run your Java program.
# compile the java class (HelloWorld.java)
javac HelloWorld.java
# run the compiled java class (HelloWorld.class)
java HelloWorld
Hellow World!
From Java 11 you can directly do
java HelloWorld.java
Hello, World!
To specify the output directory (for the .class
file), -d
can be used. i.e:
javac HelloWorld.java -d out/
It is cumbersome to use several tools for the various development tasks.
Use an Integrated Development Environment (IDE), which combines editing, testing, compiling, running, debugging, and package management.
You want to try out Java expressions and APIs quickly, without having to create a file with
public class X {
public static void main(String[] args) {
// …
}
}
every time.
Use JShell, Java’s REPL (Read-Evaluate-Print-Loop) interpreter.
Starting with Java 11, JShell is included as a standard part of Java
You need to keep your class files in a common directory, or you’re wrestling with CLASSPATH.
Set CLASSPATH to the list of directories and/or JAR files that contain the classes you want.
You’re getting an exception stack trace at runtime, but most of the important parts don’t have line numbers.
Be sure you have compiled with debugging enabled.