Back to: Java (Clone)
How to run a Java program from the command line
To run a Java program, Java must be installed (JDK) and JDK install directory should be
set to “Environment Variable”.
How to Set JDK Path : Set JDK Path
Now type your java code on “notepad” and save it with dot(.) java extension:
Code:
ExampleClass.java
class ExampleClass{ public static void main(String args[]){ System.out.println("Hello World"); } }
Let’s run the program on “command line”:
First see whether Java is installed and the version installed
Command: java -version
Now we will go to the directory of our computer’s folder that has saved our Java program.
Command : “Cd C: \ Users \ Sourav \ Desktop \ java_code”
Now compile the java program:
Command: “javac exampleclass.java”
Lastly the Java program was run with the command “java ExampleClass” and found our results were “Hello World”
Command:
java ExampleClass