move the quote to the end of the args[0] "C:\Program Files\Java\jdk1.8.0_161\bin\javac.exe" MyFirstProgram.java Java is a compiled language and not interpreted, so there is no actual IDE - but maybe a Java-pro knows one. There are some websites, where you can play around with classes... Answer from izaakstern on reddit.com
🌐
Reddit
reddit.com › r/javahelp › running java in command prompt?
r/javahelp on Reddit: Running Java in Command Prompt?
February 2, 2021 -

Second Edit: May have fixed the Environment Variables to work with JAVA_HOME. Minor change to what was printed but was able to run the file like so:

C:\Users\Test>cd Documents\MyFirstProgramFolder

C:\Users\Test\Documents\MyFirstProgramFolder>java MyFirstProgram
We did it! Again! Number 3!

Again, making sure I was in the right directory was the first issue, but now I may have the Environment Variables fixed. I hope at least. Thank you again everyone.

Edit: Have my issue mostly solved. I am able to compile and run the code. cd-ing to the correct directory seemed to be the issue in the command prompt and that is all I really need for now. Thank you to everyone who took the time try to help me!

Hello! I am new to learning Java but have been stuck on a single issue for the past day and a half. I have recently started reading Head First Java to try and teach myself Java. I took a single programming class that was taught in Java 3-4 years ago. All of the programming experience I have has always been in some sort of IDE. In Head First Java they want you to work through the command line after writing code. I have been entirely unsuccessful at setting up Java to work through the command prompt. I have now tried to download 2-3 different JDK's, followed 2-3 tutorials on how to just get "Hello World" to print, and followed a guide on how to set up the Java Environment. None have been successful and I am frequently met with the below errors/issues when I try to parse together my understanding trying to fix the issue. I would really like to learn how to actually do things without the need of an IDE. Any help at all would be greatly appreciated! So the question summed up, is more or less where am I going wrong for setting up the Java environment, or JVM?

In the Command Prompt:

C:\Users\Test>"C:\Program Files\Java\jdk1.8.0_161\bin"\Javac MyFirstProgram.java

javac: file not found: MyFirstProgram.java

Usage: javac <options> <source files>

use -help for a list of possible options

In Windows Powershell:

PS C:\Users\Test\Documents\MyFirstProgramFolder> "C:\Program Files\Java\jdk1.8.0_161\bin"\javac MyFirstProgram.java

At line:1 char:41

+ "C:\Program Files\Java\jdk1.8.0_161\bin"\javac MyFirstProgram.java

+ ~~~~~~

Unexpected token '\javac' in expression or statement.

+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException

+ FullyQualifiedErrorId : UnexpectedToken

Below are some of the websites I have tried:

https://www.instructables.com/How-to-Make-Your-First-Computer-Program/ - This instructables link is what I just used to receive the above responses.

https://www.tutorialspoint.com/java/java_environment_setup.htm

https://www.geeksforgeeks.org/setting-environment-java/

The Code:

class MyFirstProgram {

    public static void main(String[] args) {
            System.out.println("Hello, World");
    }
}
Top answer
1 of 6
2
move the quote to the end of the args[0] "C:\Program Files\Java\jdk1.8.0_161\bin\javac.exe" MyFirstProgram.java Java is a compiled language and not interpreted, so there is no actual IDE - but maybe a Java-pro knows one. There are some websites, where you can play around with classes...
2 of 6
2
First, I would add C:\Program Files\Java\jdk1.8.0_161\bin to your system PATH environment variable - this will allow you to use the Java commands without including the entire path: Right click Computer Click the properties On the left pane select Advanced System Settings Select Environment Variables Under the System Variables, Select PATH and click edit,and then click new and add path as C:\ProgramFiles\Java\jdk1.8.0_161\bin (depending on your installation path)and finally click ok (credit to https://stackoverflow.com/questions/32241179/setting-up-enviromental-variables-in-windows-10-to-use-java-and-javac for putting in the steps so I didn't have to) Once done, you should be able to use javac MyFirstProgram.java instead of putting the entire path in for javac and mucking about with quotes :) Note: you will need to restart the command prompt for the path update to take effect :) Second, in your examples above your error is file not found for the command prompt, and your folder is different than the one showing for powershell ( C:\Users\Test for command prompt and C:\Users\Test\Documents\MyFirstProgramFolder for powershell) so I'm guessing the error was due to MyFirstProgram.java not being in the folder the command prompt was in. So if you are in C:\Users\Test\Documents\MyFirstProgramFolder (assuming this is the location of your java file) and did the Path fix above, you can just use javac MyFirstProgram.java or "C:\Program Files\Java\jdk1.8.0_161\bin\javac.exe" MyFirstProgram.java if you didn't modify the path. Edit to add: both of those commands should work in powershell as well depending on whether you set the PATH variable or not assuming you are in the folder containing MyFirstProgram.java.
🌐
W3Schools
w3schools.com › java › java_getstarted.asp
Java Getting Started
Save the code in Notepad as "Main.java". Open Command Prompt (cmd.exe), navigate to the directory where you saved your file, and type "javac Main.java":
Top answer
1 of 13
274

Source: javaindos.

Let's say your file is in C:\mywork\

Run Command Prompt

CopyC:\> cd \mywork

This makes C:\mywork the current directory.

CopyC:\mywork> dir

This displays the directory contents. You should see filenamehere.java among the files.

CopyC:\mywork> set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin

This tells the system where to find JDK programs.

CopyC:\mywork> javac filenamehere.java

This runs javac.exe, the compiler. You should see nothing but the next system prompt...

CopyC:\mywork> dir

javac has created the filenamehere.class file. You should see filenamehere.java and filenamehere.class among the files.

CopyC:\mywork> java filenamehere

This runs the Java interpreter. You should then see your program output.

If the system cannot find javac, check the set path command. If javac runs but you get errors, check your Java text. If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command. Java is case-sensitive!

2 of 13
121

To complete the answer :

  1. The Java File

    CopyTheJavaFile.java
    
  2. Compile the Java File to a *.class file

    Copyjavac TheJavaFile.java
    
    • This will create a TheJavaFile.class file
  3. Execution of the Java File

    Copyjava TheJavaFile
    
  4. Creation of an executable *.jar file

    • You've got two options here -

      1. With an external manifest file :

        • Create the manifest file say - MANIFEST.mf

        • The MANIFEST file is nothing but an explicit entry of the Main Class

        • jar -cvfm TheJavaFile.jar MANIFEST.mf TheJavaFile.class

      2. Executable by Entry Point:

        • jar -cvfe TheJavaFile.jar <MainClass> TheJavaFile.class
  5. To run the Jar File

    Copyjava -jar TheJavaFile.jar
    
🌐
Princeton CS
introcs.cs.princeton.edu › java › 15inout › windows-cmd.html
Java and the Windows Command Prompt
This document instructs you on how to use the Windows Command Prompt with Java.
🌐
Oracle
java.com › en › download › help › windows_manual_download.html
How do I manually download and install Java for my Windows computer?
Use these simple instructions to manually download and install Java (also known as Java Runtime Environment or JRE) for your Windows computer
🌐
Super User
superuser.com › questions › 1738872 › how-to-detect-java-by-cmd-after-installing-it-without-restarting-the-pc-in-win
command line - How to detect java by cmd, after installing it, without restarting the PC in windows 10 - Super User
August 24, 2022 - I did test (with installed java) both scripts on windows 10, what return do you get when you enter reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f *jre* in cmd.
Find elsewhere
🌐
Oracle
java.com › en › download › manual.jsp
Download Java
» What is Java » Remove older versions » Security » Support » Other help · This download is for end users who need Java for running applications on desktops or laptops. Java 8 integrates with your operating system to run separately installed Java applications.
🌐
Programiz
programiz.com › java-programming › online-compiler
Online Java Compiler - Programiz
// Online Java Compiler // Use this editor to write, compile and run your Java code online class Main { public static void main(String[] args) { System.out.println("Start small.
🌐
Coderanch
coderanch.com › t › 543630 › java › opening-cmd-writing
opening a new cmd and writing to it (Java in General forum at Coderanch)
You can use the Runtime class and execute any command. An example: This will execute the command, but not make you able to read output and write new commands. But the call returns a Process that you could use... Another way is to use the java.lang.ProcessBuilder.
🌐
Quora
quora.com › How-do-I-run-a-Java-program-in-CMD
How to run a Java program in CMD - Quora
Answer (1 of 2): Open the command prompt and type ‘javaThe java command usage should be displayed. Check Working of javac Open the command prompt and type ‘javac’ The javac command usage should be displayed. If while executing java or javac, we get the command 'javac' is not recognized ...
🌐
Quora
quora.com › How-can-I-type-run-Java-code-using-CMD-Window-R
How to type, & run Java code using CMD (Window+R) - Quora
Answer: You can type java program in note pad and compile in cmd. 1.you have to save the java program with .Java extension in some folder. 2.Open cmd change the directory to where the file has been stored. 3.Then,type javac filename.java,if the program has error that will be shown or else noth...
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows-server › administration › windows-commands › cmd
cmd | Microsoft Learn
The cmd command-shell environment is defined by variables that determine the behavior of the command shell and the operating system. You can define the behavior of the command-shell environment or the entire operating system environment by using ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-open-command-prompt-insert-commands
Java Program to Open the Command Prompt and Insert Commands - GeeksforGeeks
April 22, 2025 - It is done by passing "cmd" command to exec() method. Example: Java · // Java program to illustrate // open cmd prompt class Geeks { public static void main(String[] args) { try { // Just one line and you are done !
🌐
Oracle
java.com › en › download › help › version_manual.html
How to find Java version in Windows or Mac - Manual method
The Java Runtime (JRE) that you download from java.com or oracle.com contains a plugin to run Java content from your browser. In order to use the command line tools, you will need to download the Java Development Kit (JDK). The JRE and JDK are separate and can coexist on your system.
🌐
Sololearn
sololearn.com › en › Discuss › 2859299 › java-file-not-found-in-cmd-solved
Java file not found in cmd [SOLVED]
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Oracle
java.com › en › download › help › log_files.html
Java software installation log files
Verify that Java software is saved on the Desktop. Open Windows Command Prompt window. Windows XP: Click Start -> Run -> Type: cmd Windows Vista and Windows 7: Click Start -> Type: cmd in the Start Search field.
🌐
TestMu AI
community.testmuai.com › ask a question
How to run a Java program via CMD on Windows? - Ask a Question - TestMu AI (formerly LambdaTest) Community
March 12, 2025 - How can I run a Java program from the command line on Windows? I’m trying to execute the following Java program from the command line in Windows: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class CopyFile { public static void main(String[] args) { InputStream inStream = null; OutputStream outStream = null; try { File afi...
🌐
Sololearn
sololearn.com › en › Discuss › 296196 › java-path-not-in-cmd
Java Path Not in CMD | Sololearn: Learn to code for FREE!
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.