ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.1 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt |
| Last Crawled | 2026-04-13 03:48:18 (3 days ago) |
| First Indexed | 2017-10-13 22:56:00 (8 years ago) |
| HTTP Status Code | 200 |
| Meta Title | How to Compile and Run a Java Program Using Command Prompt |
| Meta Description | An easy-to-follow guide to compiling and running your Java code with CMD While many programming environments will allow you to compile and run a program within that environment, you can also compile and run in Command Prompt on Windows or... |
| Meta Canonical | null |
| Boilerpipe Text | Download Article
An easy-to-follow guide to compiling and running your Java code with CMD
Download Article
Compiling and Running
|
Troubleshooting
|
Video
|
Q&A
|
Tips
While many programming environments will allow you to compile and run a program within that environment, you can also compile and run in Command Prompt on Windows or the Terminal on Mac. The process is nearly the same. This wikiHow article teaches you how to compile and run a Java program using the Command Prompt or Terminal.
Things You Should Know
At the command prompt, type "cd" followed by the path your Java program is saved to, then press "Enter."
Type "javac [filename] and press "Enter" to compile the program.
Type "java [filename]" and press "Enter" to run the Java program after it is compiled.
You can create a
Java program
using a simple text editing program like
Notepad
or an independent development environment (IDE) such as Eclipse. It's recommended you save the filename as the name of the Java class. Be sure to add the ".java" file extension to the file.
To ensure that your file is saved as a .java file, be sure to type .java after the file name and select
All Files
from the dropdown extension menu.
Make note of where you saved the file on your system.
If you are unsure how to write a program in Java, check out our tutorial on
how to program in Java
. You can use any Java program to learn how to compile and run a program.
Open Command Prompt or
Terminal
.
Accessing the command line
differs slightly for Mac and Windows.
[1]
Windows:
Click the
Windows Start
menu and type
CMD
. Click the Command Prompt icon.
Mac:
In Finder, press the
Go
tab, select
Applications,
select
Utilities,
then select
Terminal.
Advertisement
Use the command
cd
followed by the directory name to
change folders in the Command Prompt
.
For example, if your program is saved to "C:\Users\Bob\Project\TitanProject," type
cd C:\Users\Bob\Project\TitanProject
and press
Enter
to navigate to that folder.
You can see a list of what is in your current directory by typing
dir
and pressing
Enter
.
Once you are in the correct directory, you can compile the program. To do so, type
javac [filename].java
into the command line and press
Enter
.
[3]
If you have any errors in your program or difficulty compiling, the command prompt will notify you. You'll need to fix the errors before the program can be compiled.
Type
java [filename]
and press
Enter
. Of course, replace "filename" with whatever the name of your file is.
After pressing
Enter
, your program should run. If you receive an error or your program fails to run, you must do some
troubleshooting
.
Advertisement
Set your path
.
If you are running a simple program with all the files in the same directory, you will probably not need to do this. However, if you are running a more complex program with files in multiple directories, you will need to tell the computer where to look for these files.
[4]
Windows:
Type
java -version
into the command prompt and press
Enter
. Based on the version of Java displayed on the first line, type in
{{{1}}}
to the command prompt and press
↵
Enter
. Substitute "jdkX.X.X_XX" with whatever version of Java you have installed.
Be sure you are entering this command while in the directory containing your Java project.
Mac:
Type
/usr/libexec/java_home -v X.X
into the terminal and press
Enter
to ensure Java is installed on your system. Then, type
{{{1}}}
into the terminal and press
Enter
. Restart the terminal afterward.
Search
Add New Question
Question
What would I do if I type in the Java filename.java and it is not running? The code written in Notepad is correct.
Community Answer
It is okay. You have to write for compiling : javac filename.java and for running: just filename.
Question
How can I compile using CMD?
Community Answer
Once you are in the correct directory, you can compile the program by typing "javac filename.java" into the command line and pressing enter.
Question
How can I hack a computer using the command prompt?
Community Answer
You can't without installing other things. CMD is NOT for hacking and should never be used for it.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Video
Thanks
Thanks for submitting a tip for review!
Advertisement
References
About This Article
Article Summary
X
1. Type ″cmd″ into Windows search.
2. Right-click
Command prompt
.
3. Click
Run as administrator
.
4. Type ″cd \path\to\java\program″.
5. Press
Enter
.
6. Type ″javac -filename.java″.
7. Press
Enter
.
8. Type ″java filename.java″.
9. Press
Enter
.
Did this summary help you?
Thanks to all authors for creating a page that has been read 1,158,564 times.
Reader Success Stories
Vaibhav Agrawal
May 16, 2017
"There is not anything specifically good in any wikiHow Article. 'Cause all wikiHow articles are awesome. We
..."
more
Is this article up to date?
wikiHow Tech Help Pro:
Level up your tech skills and stay ahead of the curve
Let's go!
X
For over two decades, we’ve been on a mission: to help everyone in the world learn how to do anything. Our articles are human written and expert endorsed to ensure readers like you get reliable, current information.
Before you get back to learning, we would be grateful if you could take a minute to support wikiHow. Any amount helps. Thank you.
-
- |
| Markdown | [Skip to Content](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#breadcrumb_1)
[Quizzes](https://www.wikihow.com/Quizzes)
- [PRO](https://www.wikihow.com/Pro)
[Courses Hot](https://www.wikihow.com/Course/Explore) [Guides](https://www.wikihow.com/Guides) [Tech Help Pro](https://www.wikihow.com/Tech-Help-Pro) [Expert Videos](https://www.wikihow.com/wikiHow:Videos-wikiHowPro) [About wikiHow Pro](https://www.wikihow.com/Pro) [Upgrade](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#wh-dialog-pro)
- [QUIZZES](https://www.wikihow.com/Quizzes)
[All Quizzes Hot](https://www.wikihow.com/Quizzes) [Love Quizzes](https://www.wikihow.com/Love-Quizzes) [Personality Quizzes](https://www.wikihow.com/Personality-Quizzes) [Trivia Quizzes](https://www.wikihow.com/Trivia-Quizzes) [Taylor Swift Quizzes](https://www.wikihow.com/Taylor-Swift-Quizzes)
- [EDIT](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#wh-dialog-edit)
[Edit this Article](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#wh-dialog-edit)
- [EXPLORE](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[Tech Help Pro](https://www.wikihow.com/Tech-Help-Pro)[About Us](https://www.wikihow.com/wikiHow:About-wikiHow)[Random Article](https://www.wikihow.com/Special:Randomizer)[Quizzes](https://www.wikihow.com/Quizzes)
[Request a New Article](https://www.wikihow.com/Special:RequestTopic)[Community Dashboard](https://www.wikihow.com/Special:CommunityDashboard)[Trending](https://www.wikihow.com/Trending)[Forums](https://www.wikihow.com/Forums)
[Arts and Entertainment](https://www.wikihow.com/Category:Arts-and-Entertainment)[Artwork](https://www.wikihow.com/Category:Artwork)[Books](https://www.wikihow.com/Category:Books)[Movies](https://www.wikihow.com/Category:Movies)
[Computers and Electronics](https://www.wikihow.com/Category:Computers-and-Electronics)[Computers](https://www.wikihow.com/Category:Computers)[Phone Skills](https://www.wikihow.com/Category:Phone-Skills)[Technology Hacks](https://www.wikihow.com/Category:Technology-Hacks)
[Health](https://www.wikihow.com/Category:Health)[Men's Health](https://www.wikihow.com/Category:Men%27s-Health)[Mental Health](https://www.wikihow.com/Category:Psychological-Health)[Women's Health](https://www.wikihow.com/Category:Women%E2%80%99s-Health)
[Relationships](https://www.wikihow.com/Category:Relationships)[Dating](https://www.wikihow.com/Category:Dating)[Love](https://www.wikihow.com/Category:Love)[Relationship Issues](https://www.wikihow.com/Category:Relationship-Issues)
[Hobbies and Crafts](https://www.wikihow.com/Category:Hobbies-and-Crafts)[Crafts](https://www.wikihow.com/Category:Crafts)[Drawing](https://www.wikihow.com/Category:Drawing)[Games](https://www.wikihow.com/Category:Games)
[Education & Communication](https://www.wikihow.com/Category:Education-and-Communications)[Communication Skills](https://www.wikihow.com/Category:Communication-Skills)[Personal Development](https://www.wikihow.com/Category:Personal-Development)[Studying](https://www.wikihow.com/Category:Studying)
[Personal Care and Style](https://www.wikihow.com/Category:Personal-Care-and-Style)[Fashion](https://www.wikihow.com/Category:Fashion)[Hair Care](https://www.wikihow.com/Category:Hair-Care)[Personal Hygiene](https://www.wikihow.com/Category:Personal-Hygiene)
[Quizzes](https://www.wikihow.com/Quizzes) [Love Quizzes](https://www.wikihow.com/Love-Quizzes) [Personality Quizzes](https://www.wikihow.com/Personality-Quizzes) [Fun Games](https://www.wikihow.com/Generators)
[Arts and Entertainment](https://www.wikihow.com/Category:Arts-and-Entertainment)[Finance and Business](https://www.wikihow.com/Category:Finance-and-Business)[Home and Garden](https://www.wikihow.com/Category:Home-and-Garden)[Relationship Quizzes](https://www.wikihow.com/Relationships#Quizzes)
[Cars & Other Vehicles](https://www.wikihow.com/Category:Cars-%26-Other-Vehicles)[Food and Entertaining](https://www.wikihow.com/Category:Food-and-Entertaining)[Personal Care and Style](https://www.wikihow.com/Category:Personal-Care-and-Style)[Sports and Fitness](https://www.wikihow.com/Category:Sports-and-Fitness)
[Computers and Electronics](https://www.wikihow.com/Category:Computers-and-Electronics)[Health](https://www.wikihow.com/Category:Health)[Pets and Animals](https://www.wikihow.com/Category:Pets-and-Animals)[Travel](https://www.wikihow.com/Category:Travel)
[Education & Communication](https://www.wikihow.com/Category:Education-and-Communications)[Hobbies and Crafts](https://www.wikihow.com/Category:Hobbies-and-Crafts)[Philosophy and Religion](https://www.wikihow.com/Category:Philosophy-and-Religion)[Work World](https://www.wikihow.com/Category:Work-World)
[Family Life](https://www.wikihow.com/Category:Family-Life)[Holidays and Traditions](https://www.wikihow.com/Category:Holidays-and-Traditions)[Relationships](https://www.wikihow.com/Category:Relationships)[Youth](https://www.wikihow.com/Category:Youth)
- [LOG IN](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#wh-dialog-login)
### Log in
Social login does not work in incognito and private browsers. Please log in with your username or email to continue.
[Facebook](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[Google](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[wikiHow Account](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#wh-dialog-login)
No account yet? [Create an account](https://www.wikihow.com/Special:UserLogin?type=signup)
- [RANDOM](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
- [Home](https://www.wikihow.com/Main-Page)
- [Random](https://www.wikihow.com/Special:Randomizer)
- [Browse Articles](https://www.wikihow.com/Special:CategoryListing)
- [TrendingNew](https://www.wikihow.com/Trending)
- Quizzes & Games
- [All QuizzesHot](https://www.wikihow.com/Quizzes)
- [Love Quizzes](https://www.wikihow.com/Love-Quizzes)
- [Personality Quizzes](https://www.wikihow.com/Personality-Quizzes)
- [Fun Games](https://www.wikihow.com/Generators)
- [Dating Simulator](https://www.wikihow.com/Dating-Simulator)
- Learn Something New
- [Forums](https://www.wikihow.com/Forum)
- [Courses](https://www.wikihow.com/Course/Explore)
- [Happiness Hub](https://www.wikihow.com/Academy/Shawn-Achor)
- Explore More
- [Support wikiHow](https://www.wikihow.com/Special:Contribute)
- [About wikiHow](https://www.wikihow.com/wikiHow:About-wikiHow)
- [Log in / Sign up](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#wh-dialog-login)
[Terms of Use](https://www.wikihow.com/wikiHow:Terms-of-Use)
[wikiHow is where trusted research and expert knowledge come together. Learn why people **trust wikiHow**](https://www.wikihow.com/wikiHow:Delivering-a-Trustworthy-Experience)
- [Categories](https://www.wikihow.com/Special:CategoryListing "Special:CategoryListing")
- [Computers and Electronics](https://www.wikihow.com/Category:Computers-and-Electronics "Category:Computers and Electronics")
- [Software](https://www.wikihow.com/Category:Software "Category:Software")
- [Programming](https://www.wikihow.com/Category:Programming "Category:Programming")
- [Java](https://www.wikihow.com/Category:Java "Category:Java")
# [A Beginner’s Guide to Compiling & Running Java Programs](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[ Download Article](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
An easy-to-follow guide to compiling and running your Java code with CMD
**Co-authored by** [Yaffet Meshesha](https://www.wikihow.com/Author/Yaffet-Meshesha) and [Travis Boylls](https://www.wikihow.com/Author/Travis-Boylls)
[Last Updated: September 28, 2025](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [Fact Checked](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[ Download Article](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
- [Compiling and Running](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#Compiling-and-Running)
- [Troubleshooting](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#Troubleshooting)
- [Video](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#Video)
- [Q\&A](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#qa_headline)
- [Tips](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#tips)
\|Show more
\|Show less
X
This article was co-authored by [Yaffet Meshesha](https://www.wikihow.com/Author/Yaffet-Meshesha) and by wikiHow staff writer, [Travis Boylls](https://www.wikihow.com/Author/Travis-Boylls). Yaffet Meshesha is a Computer Specialist and the Founder of Techy, a full-service computer pickup, repair, and delivery service. With over eight years of experience, Yaffet specializes in computer repairs and technical support. Techy has been featured on TechCrunch and Time.
This article has been fact-checked, ensuring the accuracy of any cited facts and confirming the authority of its sources.
This article has been viewed 1,158,564 times.
While many programming environments will allow you to compile and run a program within that environment, you can also compile and run in Command Prompt on Windows or the Terminal on Mac. The process is nearly the same. This wikiHow article teaches you how to compile and run a Java program using the Command Prompt or Terminal.
## Things You Should Know
- At the command prompt, type "cd" followed by the path your Java program is saved to, then press "Enter."
- Type "javac \[filename\] and press "Enter" to compile the program.
- Type "java \[filename\]" and press "Enter" to run the Java program after it is compiled.
## Steps
Method 1
Method 1 of 2:
### Compiling and Running
[ Download Article](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
1. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-1-Version-3.jpg)
1
**Save the program.** You can create a [Java program](https://www.wikihow.com/Program-in-Java "Program in Java") using a simple text editing program like [Notepad](https://www.wikihow.com/Use-Notepad "Use Notepad") or an independent development environment (IDE) such as Eclipse. It's recommended you save the filename as the name of the Java class. Be sure to add the ".java" file extension to the file.
- To ensure that your file is saved as a .java file, be sure to type .java after the file name and select **All Files** from the dropdown extension menu.
- Make note of where you saved the file on your system.
- If you are unsure how to write a program in Java, check out our tutorial on [how to program in Java](https://www.wikihow.com/Program-in-Java "Program in Java"). You can use any Java program to learn how to compile and run a program.
2. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-2-Version-4.jpg)
2
**Open Command Prompt or [**Terminal**](https://www.wikihow.com/Open-Terminal-in-Windows "Open Terminal in Windows") [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Windowscmd1.png).** [Accessing the command line](https://www.wikihow.com/Open-the-Command-Prompt-in-Windows "Open the Command Prompt in Windows") differs slightly for Mac and Windows.[\[1\]](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_note-1)X [Expert Source](https://www.wikihow.com/wikiHow:Delivering-a-Trustworthy-Experience) [Yaffet Meshesha Computer Specialist](https://www.wikihow.com/Author/Yaffet-Meshesha) Expert Interview
- **Windows:** Click the **Windows Start** menu and type `CMD`. Click the Command Prompt icon.
- **Mac:** In Finder, press the **Go** tab, select **Applications,** select **Utilities,** then select **Terminal.**
Advertisement
3. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-3-Version-4.jpg)
3
**Check that Java is installed.** Type `java -version` into your command line. If Java is installed, you will see a message stating what version of Java is currently installed.[\[2\]](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_note-2)X [Expert Source](https://www.wikihow.com/wikiHow:Delivering-a-Trustworthy-Experience) [Yaffet Meshesha Computer Specialist](https://www.wikihow.com/Author/Yaffet-Meshesha) Expert Interview
- If not, you may need to [install the Java Development Kit](https://www.wikihow.com/Install-the-Java-Software-Development-Kit "Install the Java Software Development Kit") from their website. It is free and can be found at this link: <https://www.oracle.com/java/technologies/downloads/>.
- If you are not running the latest version of Java, you can [update Java](https://www.wikihow.com/Update-Java "Update Java") in the Java control panel.
4. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-4-Version-4.jpg)
4
**Navigate to the folder your program is saved to.** Use the command **cd** followed by the directory name to [change folders in the Command Prompt](https://www.wikihow.com/Open-a-Folder-in-Cmd "Open a Folder in Cmd").
- For example, if your program is saved to "C:\\Users\\Bob\\Project\\TitanProject," type `cd C:\Users\Bob\Project\TitanProject` and press **Enter** to navigate to that folder.
- You can see a list of what is in your current directory by typing ` dir` and pressing **Enter**.
5. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-5-Version-4.jpg)
5
**Compile the program.** Once you are in the correct directory, you can compile the program. To do so, type ` javac [filename].java` into the command line and press **Enter**.[\[3\]](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_note-3) X Research source
- If you have any errors in your program or difficulty compiling, the command prompt will notify you. You'll need to fix the errors before the program can be compiled.
6. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-6-Version-4.jpg)
6
**Run the program.** Type `java [filename]` and press **Enter**. Of course, replace "filename" with whatever the name of your file is.
- After pressing **Enter**, your program should run. If you receive an error or your program fails to run, you must do some [troubleshooting](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#Troubleshooting).
Method 2
Method 2 of 2:
### Troubleshooting
[ Download Article](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
1. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-7-Version-4.jpg)
1
[**Set your path**](https://www.wikihow.com/Change-the-PATH-Environment-Variable-on-Windows "Change the PATH Environment Variable on Windows")**.** If you are running a simple program with all the files in the same directory, you will probably not need to do this. However, if you are running a more complex program with files in multiple directories, you will need to tell the computer where to look for these files.[\[4\]](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_note-4) X Research source
- **Windows:** Type `java -version` into the command prompt and press **Enter**. Based on the version of Java displayed on the first line, type in `{{{1}}}` to the command prompt and press `↵ Enter`. Substitute "jdkX.X.X\_XX" with whatever version of Java you have installed.
- Be sure you are entering this command while in the directory containing your Java project.
- **Mac:** Type `/usr/libexec/java_home -v X.X` into the terminal and press **Enter** to ensure Java is installed on your system. Then, type `{{{1}}}` into the terminal and press **Enter**. Restart the terminal afterward.
## Community Q\&A
Search
[Add New Question]()
- Question
What would I do if I type in the Java filename.java and it is not running? The code written in Notepad is correct.

Community Answer
It is okay. You have to write for compiling : javac filename.java and for running: just filename.
**Thanks! We're glad this was helpful.**
**Thank you for your feedback.**
If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even \$1 helps us in our mission. [Support wikiHow](https://www.wikihow.com/wikiHow:Contribute)
[Yes](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [No](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[Not Helpful 43](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [Helpful 69](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
- Question
How can I compile using CMD?

Community Answer
Once you are in the correct directory, you can compile the program by typing "javac filename.java" into the command line and pressing enter.
**Thanks! We're glad this was helpful.**
**Thank you for your feedback.**
If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even \$1 helps us in our mission. [Support wikiHow](https://www.wikihow.com/wikiHow:Contribute)
[Yes](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [No](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[Not Helpful 36](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [Helpful 44](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
- Question
How can I hack a computer using the command prompt?

Community Answer
You can't without installing other things. CMD is NOT for hacking and should never be used for it.
**Thanks! We're glad this was helpful.**
**Thank you for your feedback.**
If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even \$1 helps us in our mission. [Support wikiHow](https://www.wikihow.com/wikiHow:Contribute)
[Yes](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [No](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[Not Helpful 62](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [Helpful 49](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[See more answers](https://www.wikihow.com/Questions/Compile-&-Run-Java-Program-Using-Command-Prompt#offset=3)
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
[Submit]()
Advertisement
## Video
## Tips
- Again, it is important that you have the Java JDK downloaded and installed on your computer. The link is here: <http://www.oracle.com/technetwork/java/javase/downloads/index.html>.
Thanks
[Helpful 1](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [Not Helpful 0](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
[Submit](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
Thanks for submitting a tip for review\!
Advertisement
## You Might Also Like
[ How to Compile a Java Program Using an SDK or Online Compiler ](https://www.wikihow.com/Compile-a-Java-Program)
[ How to Check Your Java Version in the Windows Command Line ](https://www.wikihow.com/Check-Your-Java-Version-in-the-Windows-Command-Line)
[ How to Set JAVA\_HOME for JDK & JRE: A Step-by-Step Guide ](https://www.wikihow.com/Set-Java-Home)
[ How to Install the Java Software Development Kit ](https://www.wikihow.com/Install-the-Java-Software-Development-Kit)
[ How to Create Your First Java Program on Ubuntu Linux ](https://www.wikihow.com/Create-Your-First-Java-Program-on-Ubuntu-Linux)
[ How to Run a C Program Using Developer Command Prompt ](https://www.wikihow.com/Run-C-Program-in-Command-Prompt)
[ How to Program in Java ](https://www.wikihow.com/Program-in-Java)
[ How to Run a .Jar Java File ](https://www.wikihow.com/Run-a-.Jar-Java-File)
[ How to Compile and Run Java Programs Using Notepad++ ](https://www.wikihow.com/Compile-and-Run-Java-Program-by-Notepad)
[ How to Install Java in Ubuntu Using Terminal ](https://www.wikihow.com/Install-Java-in-Ubuntu-Using-Terminal)
[ How to Run Ruby Code ](https://www.wikihow.com/Run-Ruby-Code)
[ How to Execute a Batch File from the Command Line (CMD) ](https://www.wikihow.com/Run-a-Batch-File-from-the-Command-Line-on-Windows)
[ How to Compile a C Program ](https://www.wikihow.com/Compile-a-C-Program)
[ How to Install Oracle Java JRE on Ubuntu Linux ](https://www.wikihow.com/Install-Oracle-Java-JRE-on-Ubuntu-Linux)
Advertisement
## References
1. [↑](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_ref-1) Yaffet Meshesha. Computer Specialist. Expert Interview
2. [↑](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_ref-2) Yaffet Meshesha. Computer Specialist. Expert Interview
3. [↑](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_ref-3) <https://www.cs.fsu.edu/~myers/cop3252/howto/cmdline.html>
4. [↑](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_ref-4) <https://www.geeksforgeeks.org/java/how-to-set-java-path-in-windows-and-linux/>
5. <https://stackoverflow.com/questions/15826202/where-is-java-installed-on-mac-os-x>
## About This Article

Co-authored by:
[Yaffet Meshesha](https://www.wikihow.com/Author/Yaffet-Meshesha)
Computer Specialist
This article was co-authored by [Yaffet Meshesha](https://www.wikihow.com/Author/Yaffet-Meshesha) and by wikiHow staff writer, [Travis Boylls](https://www.wikihow.com/Author/Travis-Boylls). Yaffet Meshesha is a Computer Specialist and the Founder of Techy, a full-service computer pickup, repair, and delivery service. With over eight years of experience, Yaffet specializes in computer repairs and technical support. Techy has been featured on TechCrunch and Time. This article has been viewed 1,158,564 times.
How helpful is this?
Co-authors: 29
Updated: September 28, 2025
Views: 1,158,564
Categories: [Java](https://www.wikihow.com/Category:Java "Category:Java")
[Article SummaryX](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#summary_wrapper)
1\. Type ″cmd″ into Windows search.
2. Right-click **Command prompt**.
3. Click **Run as administrator**.
4. Type ″cd \\path\\to\\java\\program″.
5. Press **Enter**.
6. Type ″javac -filename.java″.
7. Press **Enter**.
8. Type ″java filename.java″.
9. Press **Enter**.
Did this summary help you?
Yes
No
[In other languages](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#other_languages)
[Spanish](https://es.wikihow.com/compilar-y-ejecutar-un-programa-Java-usando-el-%22S%C3%ADmbolo-de-sistema%22)
[Portuguese](https://pt.wikihow.com/Compilar-e-Executar-um-Programa-Java-Usando-o-Prompt-de-Comando)
[Italian](https://www.wikihow.it/Compilare-ed-Eseguire-un-Programma-Java-Utilizzando-il-Prompt-dei-Comandi)
[Arabic](https://ar.wikihow.com/%D8%AA%D8%B1%D8%AC%D9%85%D8%A9-%D9%88%D8%AA%D8%B4%D8%BA%D9%8A%D9%84-%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D8%AC-%D8%AC%D8%A7%D9%81%D8%A7-%D8%A8%D8%A7%D8%B3%D8%AA%D8%AE%D8%AF%D8%A7%D9%85-%D8%B3%D8%B7%D8%B1-%D8%A7%D9%84%D8%A3%D9%88%D8%A7%D9%85%D8%B1)
[Thai](https://th.wikihow.com/Compile-%E0%B9%81%E0%B8%A5%E0%B9%89%E0%B8%A7%E0%B9%80%E0%B8%9B%E0%B8%B4%E0%B8%94%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1-Java-%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B9%83%E0%B8%99-Command-Prompt)
[Dutch](https://nl.wikihow.com/Een-Java-programma-compileren-en-uitvoeren-via-de-opdrachtprompt)
[Russian](https://ru.wikihow.com/%D0%BA%D0%BE%D0%BC%D0%BF%D0%B8%D0%BB%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D1%82%D1%8C-%D0%B8-%D0%B7%D0%B0%D0%BF%D1%83%D1%81%D0%BA%D0%B0%D1%82%D1%8C-%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D1%83-Java-%D1%81-%D0%BF%D0%BE%D0%BC%D0%BE%D1%89%D1%8C%D1%8E-%D0%BA%D0%BE%D0%BC%D0%B0%D0%BD%D0%B4%D0%BD%D0%BE%D0%B9-%D1%81%D1%82%D1%80%D0%BE%D0%BA%D0%B8)
[Indonesian](https://id.wikihow.com/Mengompilasi-dan-Menjalankan-Program-Java-dengan-Baris-Perintah)
[Vietnamese](https://www.wikihow.vn/Bi%C3%AAn-d%E1%BB%8Bch-v%C3%A0-th%E1%BB%B1c-thi-Java-b%E1%BA%B1ng-Command-Prompt)
[French](https://fr.wikihow.com/compiler-et-ex%C3%A9cuter-un-programme-Java-en-ligne-de-commande)
[German](https://de.wikihow.com/%C3%9Cber-die-Kommandozeile-Java-Programme-kompilieren-und-ausf%C3%BChren)
[Chinese](https://zh.wikihow.com/%E4%BD%BF%E7%94%A8%E5%91%BD%E4%BB%A4%E6%8F%90%E7%A4%BA%E7%AC%A6%E7%BC%96%E8%AF%91%E5%92%8C%E8%BF%90%E8%A1%8CJava%E7%A8%8B%E5%BA%8F)
[Hindi](https://hi.wikihow.com/%E0%A4%95%E0%A4%AE%E0%A4%BE%E0%A4%82%E0%A4%A1-%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A5%89%E0%A4%AE%E0%A5%8D%E0%A4%AA%E0%A5%8D%E0%A4%9F-%E0%A4%AA%E0%A4%B0-%E0%A4%9C%E0%A4%BE%E0%A4%B5%E0%A4%BE-\(Java\)-%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A5%8B%E0%A4%97%E0%A5%8D%E0%A4%B0%E0%A4%BE%E0%A4%AE-%E0%A4%95%E0%A4%AE%E0%A5%8D%E0%A4%AA%E0%A4%BE%E0%A4%87%E0%A4%B2-\(Compile\)-%E0%A4%95%E0%A4%B0%E0%A5%87%E0%A4%82-%E0%A4%94%E0%A4%B0-%E0%A4%9A%E0%A4%B2%E0%A4%BE%E0%A4%8F%E0%A4%81)
[Turkish](https://www.wikihow.com.tr/Java-Program%C4%B1-Komut-%C4%B0stemi-Kullan%C4%B1larak-Nas%C4%B1l-Derlenir-ve-%C3%87al%C4%B1%C5%9Ft%C4%B1r%C4%B1l%C4%B1r)
[Czech](https://www.wikihow.cz/Jak-kompilace-a-spu%C5%A1t%C4%9Bn%C3%AD-programu-java-pomoc%C3%AD-p%C5%99%C3%ADkazov%C3%A9ho-%C5%99%C3%A1dku)
[Japanese](https://www.wikihow.jp/%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%83%97%E3%83%AD%E3%83%B3%E3%83%97%E3%83%88%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%9FJava%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%81%AE%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%AB%E3%81%A8%E5%AE%9F%E8%A1%8C)
- [Print](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
- [Send fan mail to authors](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
Thanks to all authors for creating a page that has been read 1,158,564 times.
## Reader Success Stories
- 
Vaibhav Agrawal
May 16, 2017
"There is not anything specifically good in any wikiHow Article. 'Cause all wikiHow articles are awesome. We all love this site. Excellent Work."..." [more](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[More reader stories](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [Hide reader stories](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
[Share your story](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
## Is this article up to date?
Yes
No
Advertisement
Cookies make wikiHow better. By continuing to use our site, you agree to our [cookie policy](https://www.wikihow.com/wikiHow:Cookie-Policy).

Co-authored by:
[Yaffet Meshesha](https://www.wikihow.com/Author/Yaffet-Meshesha)
Computer Specialist
Click a star to vote
Co-authors: 29
Updated: September 28, 2025
Views: 1,158,564

Vaibhav Agrawal
May 16, 2017
"There is not anything specifically good in any wikiHow Article. 'Cause all wikiHow articles are awesome. We all love this site. Excellent Work."..." [more](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)

Anonymous
Mar 10, 2017
"I'm working on a Boy Scout Programming merit badge and I needed help with the Java part. I couldn't compile it."..." [more](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)

Ashish Sharma
Mar 21, 2016
"Thanks, wikiHow, this is very informative."

Ibrahim Ali Khan
Aug 3, 2016
"Great article. Thanks guys."
[Share yours\!](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [More success stories](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) [Hide success stories](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
### Quizzes & Games
[ What Kind of Minecraft Player Am I QuizTake Quiz](https://www.wikihow.com/What-Minecraft-Player-Am-I-Quiz)
[ Am I Ready for College QuizTake Quiz](https://www.wikihow.com/College-Readiness-Assessment-Quiz)
[ IQ TestTake Quiz](https://www.wikihow.com/IQ-Test)
[ College Major QuizTake Quiz](https://www.wikihow.com/College-Major-Quiz)
### You Might Also Like
[ How to Compile a Java Program Using an SDK or Online Compiler](https://www.wikihow.com/Compile-a-Java-Program)
[ How to Check Your Java Version in the Windows Command Line](https://www.wikihow.com/Check-Your-Java-Version-in-the-Windows-Command-Line)
[ How to Set JAVA\_HOME for JDK & JRE: A Step-by-Step Guide](https://www.wikihow.com/Set-Java-Home)
[ How to Install the Java Software Development Kit](https://www.wikihow.com/Install-the-Java-Software-Development-Kit)
### Trending Articles
[ Princess Treatment vs Bare Minimum Quiz](https://www.wikihow.com/Relationships/Princess-Treatment-Quiz)
[ Is My Boyfriend Secretly Gay? This Quiz Can Help](https://www.wikihow.com/Relationships/Is-My-Boyfriend-Gay-Quiz)
[ Am I an Alpha, Beta, or Omega Quiz](https://www.wikihow.com/Alpha-Beta-Omega-Test)
[ Who Is My Soulmate Quiz](https://www.wikihow.com/Relationships/Soulmate-Quiz)
[](https://www.wikihow.com/Main-Page)
- [Categories](https://www.wikihow.com/Special:CategoryListing "Special:CategoryListing")
- [Computers and Electronics](https://www.wikihow.com/Category:Computers-and-Electronics "Category:Computers and Electronics")
- [Software](https://www.wikihow.com/Category:Software "Category:Software")
- [Programming](https://www.wikihow.com/Category:Programming "Category:Programming")
- [Java](https://www.wikihow.com/Category:Java "Category:Java")
wikiHow Newsletter
You're all set\!
Helpful how-tos delivered to
your inbox every week\!
[Sign me up\!](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
By signing up you are agreeing to receive emails according to our privacy policy.
- [Home](https://www.wikihow.com/Main-Page "Main Page")
- [About wikiHow](https://www.wikihow.com/About-wikiHow "About wikiHow")
- [Experts](https://www.wikihow.com/Experts)
- [Jobs](https://www.wikihow.com/wikiHow:Jobs "wikiHow:Jobs")
- [Contact Us](https://www.wikihow.com/wikiHow:Contact-Us "wikiHow:Contact Us")
- [Site Map](https://www.wikihow.com/Special:Sitemap "Special:Sitemap")
- [Terms of Use](https://www.wikihow.com/wikiHow:Terms-of-Use "wikiHow:Terms of Use")
- [Privacy Policy](https://www.wikihow.com/wikiHow:Privacy-Policy "wikiHow:Privacy Policy")
- [Do Not Sell or Share My Info](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
- [Not Selling Info](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
- [Contribute](https://www.wikihow.com/wikiHow:Contribute)
- [Privacy & Cookie settings](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
Follow Us
Ă—
wikiHow Tech Help Pro:
Level up your tech skills and stay ahead of the curve
[Let's go\!](https://www.wikihow.com/Tech-Help-Pro)
[X](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
#### Join us in our mission
For over two decades, we’ve been on a mission: to help everyone in the world learn how to do anything. Our articles are human written and expert endorsed to ensure readers like you get reliable, current information. **Before you get back to learning, we would be grateful if you could take a minute to support wikiHow. Any amount helps. Thank you.**
[Let’s do this\!](https://www.wikihow.com/wikiHow:Contribute?utm_source=wikihow&utm_medium=banner&utm_campaign=contribute2&aid=3492799)
\-
\-

475
1
ACCOUNT
2
PAYMENT
3
CONFIRMATION
### ORDER SUMMARY
\$
***
\$
Total Due Today
Please select a payment method:
Processing payment...
1
ACCOUNT
2
PAYMENT
3
CONFIRMATION
### Sign Up
ALREADY HAVE AN ACCOUNT?[LOG IN]()
Continue with
Social login does not work in incognito and private browsers. Please create an account to continue.
[Facebook]()[Google]()
Create an account
or
1
ACCOUNT
2
PAYMENT
3
CONFIRMATION
### Log in
DON'T HAVE AN ACCOUNT?[SIGN UP]()
Social login does not work in incognito and private browsers. Please log in with your username or email to continue.
[Facebook]()[Google]()
or
1
ACCOUNT
2
PAYMENT
3
CONFIRMATION
Finish Account Setup
Please enter an email address to finish setting up your account:
## Save this image in high definition.
Download your high definition file of this image so you can save, print, and keep it for personal use.
### One-time purchase
- Get the HD version of this image.
- Full resolution. Ideal for high-quality prints and personal use.
- Yours to keep for personal use.
By continuing, you agree to our [Terms of Use](https://www.wikihow.com/wikiHow:Terms-of-Use), [Privacy Policy](https://www.wikihow.com/wikiHow:Privacy-Policy), and [license terms for Digital Downloads](https://www.wikihow.com/wikiHow:Terms-of-Use#wikiHow-Digital-Downloads). For personal, non-commercial use only. Questions? Please contact [support@wikiHow.pro](mailto:support@wikiHow.pro).
## Thank You
We've emailed you a copy of your image, and you can also download it below.
[Download HD Image](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
By continuing to use wikiHow, you agree to our
[Terms of Service](https://www.wikihow.com/wikiHow:Terms-of-Use) and [Privacy Policy](https://www.wikihow.com/wikiHow:Privacy-Policy).
wikiHow Pro is intended only for your personal, non-commercial use. wikiHow, Inc. reserves the right to terminate subscriptions to wikiHow Pro at any time and for any reason.
Questions? Please contact [support@wikihow.pro](mailto:support@wikihow.pro).
Something went wrong
[Dismiss]() |
| Readable Markdown | [ Download Article](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
An easy-to-follow guide to compiling and running your Java code with CMD
[ Download Article](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
- [Compiling and Running](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#Compiling-and-Running)
- [Troubleshooting](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#Troubleshooting)
- [Video](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#Video)
- [Q\&A](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#qa_headline)
- [Tips](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#tips)
While many programming environments will allow you to compile and run a program within that environment, you can also compile and run in Command Prompt on Windows or the Terminal on Mac. The process is nearly the same. This wikiHow article teaches you how to compile and run a Java program using the Command Prompt or Terminal.
## Things You Should Know
- At the command prompt, type "cd" followed by the path your Java program is saved to, then press "Enter."
- Type "javac \[filename\] and press "Enter" to compile the program.
- Type "java \[filename\]" and press "Enter" to run the Java program after it is compiled.
1. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-1-Version-3.jpg)
You can create a [Java program](https://www.wikihow.com/Program-in-Java "Program in Java") using a simple text editing program like [Notepad](https://www.wikihow.com/Use-Notepad "Use Notepad") or an independent development environment (IDE) such as Eclipse. It's recommended you save the filename as the name of the Java class. Be sure to add the ".java" file extension to the file.
- To ensure that your file is saved as a .java file, be sure to type .java after the file name and select **All Files** from the dropdown extension menu.
- Make note of where you saved the file on your system.
- If you are unsure how to write a program in Java, check out our tutorial on [how to program in Java](https://www.wikihow.com/Program-in-Java "Program in Java"). You can use any Java program to learn how to compile and run a program.
2. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-2-Version-4.jpg)
**Open Command Prompt or [**Terminal**](https://www.wikihow.com/Open-Terminal-in-Windows "Open Terminal in Windows") [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Windowscmd1.png).** [Accessing the command line](https://www.wikihow.com/Open-the-Command-Prompt-in-Windows "Open the Command Prompt in Windows") differs slightly for Mac and Windows.[\[1\]](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_note-1)
- **Windows:** Click the **Windows Start** menu and type `CMD`. Click the Command Prompt icon.
- **Mac:** In Finder, press the **Go** tab, select **Applications,** select **Utilities,** then select **Terminal.**
Advertisement
3. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-3-Version-4.jpg)
4. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-4-Version-4.jpg)
Use the command **cd** followed by the directory name to [change folders in the Command Prompt](https://www.wikihow.com/Open-a-Folder-in-Cmd "Open a Folder in Cmd").
- For example, if your program is saved to "C:\\Users\\Bob\\Project\\TitanProject," type `cd C:\Users\Bob\Project\TitanProject` and press **Enter** to navigate to that folder.
- You can see a list of what is in your current directory by typing ` dir` and pressing **Enter**.
5. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-5-Version-4.jpg)
Once you are in the correct directory, you can compile the program. To do so, type ` javac [filename].java` into the command line and press **Enter**.[\[3\]](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_note-3)
- If you have any errors in your program or difficulty compiling, the command prompt will notify you. You'll need to fix the errors before the program can be compiled.
6. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-6-Version-4.jpg)
Type `java [filename]` and press **Enter**. Of course, replace "filename" with whatever the name of your file is.
- After pressing **Enter**, your program should run. If you receive an error or your program fails to run, you must do some [troubleshooting](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#Troubleshooting).
1. [](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#/Image:Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-7-Version-4.jpg)
[**Set your path**](https://www.wikihow.com/Change-the-PATH-Environment-Variable-on-Windows "Change the PATH Environment Variable on Windows")**.** If you are running a simple program with all the files in the same directory, you will probably not need to do this. However, if you are running a more complex program with files in multiple directories, you will need to tell the computer where to look for these files.[\[4\]](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#_note-4)
- **Windows:** Type `java -version` into the command prompt and press **Enter**. Based on the version of Java displayed on the first line, type in `{{{1}}}` to the command prompt and press `↵ Enter`. Substitute "jdkX.X.X\_XX" with whatever version of Java you have installed.
- Be sure you are entering this command while in the directory containing your Java project.
- **Mac:** Type `/usr/libexec/java_home -v X.X` into the terminal and press **Enter** to ensure Java is installed on your system. Then, type `{{{1}}}` into the terminal and press **Enter**. Restart the terminal afterward.
Search
[Add New Question]()
- Question
What would I do if I type in the Java filename.java and it is not running? The code written in Notepad is correct.

Community Answer
It is okay. You have to write for compiling : javac filename.java and for running: just filename.
- Question
How can I compile using CMD?

Community Answer
Once you are in the correct directory, you can compile the program by typing "javac filename.java" into the command line and pressing enter.
- Question
How can I hack a computer using the command prompt?

Community Answer
You can't without installing other things. CMD is NOT for hacking and should never be used for it.
[See more answers](https://www.wikihow.com/Questions/Compile-&-Run-Java-Program-Using-Command-Prompt#offset=3)
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
[Submit]()
Advertisement
## Video
- Thanks
Thanks for submitting a tip for review\!
Advertisement
## References
About This Article
[Article SummaryX](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt#summary_wrapper)
1\. Type ″cmd″ into Windows search.
2. Right-click **Command prompt**.
3. Click **Run as administrator**.
4. Type ″cd \\path\\to\\java\\program″.
5. Press **Enter**.
6. Type ″javac -filename.java″.
7. Press **Enter**.
8. Type ″java filename.java″.
9. Press **Enter**.
Did this summary help you?
Thanks to all authors for creating a page that has been read 1,158,564 times.
Reader Success Stories
- 
Vaibhav Agrawal
May 16, 2017
"There is not anything specifically good in any wikiHow Article. 'Cause all wikiHow articles are awesome. We..." [more](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
## Is this article up to date?
wikiHow Tech Help Pro:
Level up your tech skills and stay ahead of the curve
[Let's go\!](https://www.wikihow.com/Tech-Help-Pro)
[X](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt)
For over two decades, we’ve been on a mission: to help everyone in the world learn how to do anything. Our articles are human written and expert endorsed to ensure readers like you get reliable, current information. **Before you get back to learning, we would be grateful if you could take a minute to support wikiHow. Any amount helps. Thank you.**
\-
\-
 |
| Shard | 92 (laksa) |
| Root Hash | 12431216878206919092 |
| Unparsed URL | com,wikihow!www,/Compile-%26-Run-Java-Program-Using-Command-Prompt s443 |