This question already has an answer here:
New programmer here, in terms of actually using an editor and running it. I have created a simple program that states this.
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
}
}
I have already set the path to "C:\Program Files\Java\jdk1.8.0_151\bin\".(current version"1.8.0_151
"). In the cmd input, "java" and "javac" work until I attempt to find a file name either "HelloWorld.java" or "HelloWorld". How do I get cmd to find and run my java file? Thank you!
you compile with javac eg:
you run the compiled byte code using java. You need to place yourself in the directory containing the compiled bytecode eg
I did the following steps with your code and it worked:
HelloWorld.java
is savedjava -version
(this should print information about your installed java version)javac HelloWorld.java
HelloWorld.class
java HelloWorld
.class
extenstiondir
instead ofls
on Windows to see the files in the current directorypackage
name specified?One way to try it:
Open
C:\Temp
(or create if not exists)Create new file called
HelloWorld.java
Open
cmd
Type
cd /d C:\Temp
Type
javac HelloWorld.java
Type
java HelloWorld