🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 92 (from laksa114)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
3 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt
Last Crawled2026-04-13 03:48:18 (3 days ago)
First Indexed2017-10-13 22:56:00 (8 years ago)
HTTP Status Code200
Meta TitleHow to Compile and Run a Java Program Using Command Prompt
Meta DescriptionAn 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 Canonicalnull
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) [![PDF download](https://www.wikihow.com/extensions/wikihow/socialstamp/images/icon-pdf.svg) 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) [![PDF download](https://www.wikihow.com/extensions/wikihow/socialstamp/images/icon-pdf.svg) 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 [![PDF download](https://www.wikihow.com/extensions/wikihow/socialstamp/images/icon-pdf.svg) Download Article](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) 1. [![Step 1 Save the program.](https://www.wikihow.com/images/thumb/1/1b/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-1-Version-3.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-1-Version-3.jpg)](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. [![Step 2 Open Command Prompt...](https://www.wikihow.com/images/thumb/e/ee/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-2-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-2-Version-4.jpg)](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") [![Windows cmd](https://www.wikihow.com/images/6/66/Windowscmd1.png)](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](https://www.wikihow.com/images/thumb/4/41/Yaffet_Meshesha.png/-crop-100-100-100px-Yaffet_Meshesha.png)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. [![Step 3 Check that Java is installed.](https://www.wikihow.com/images/thumb/c/cd/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-3-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-3-Version-4.jpg)](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](https://www.wikihow.com/images/thumb/4/41/Yaffet_Meshesha.png/-crop-100-100-100px-Yaffet_Meshesha.png)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. [![Step 4 Navigate to the folder your program is saved to.](https://www.wikihow.com/images/thumb/4/4a/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-4-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-4-Version-4.jpg)](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. [![Step 5 Compile the program.](https://www.wikihow.com/images/thumb/5/5d/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-5-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-5-Version-4.jpg)](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. [![Step 6 Run the program.](https://www.wikihow.com/images/thumb/7/71/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-6-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-6-Version-4.jpg)](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 [![PDF download](https://www.wikihow.com/extensions/wikihow/socialstamp/images/icon-pdf.svg) Download Article](https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-Prompt) 1. [![Step 1 Set your path...](https://www.wikihow.com/images/thumb/5/52/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-7-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-7-Version-4.jpg)](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](https://www.wikihow.com/images/thumb/f/f5/CommunityAvatar4.png/-crop-104-104-104px-CommunityAvatar4.png) 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](https://www.wikihow.com/images/thumb/f/f5/CommunityAvatar4.png/-crop-104-104-104px-CommunityAvatar4.png) 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](https://www.wikihow.com/images/thumb/f/f5/CommunityAvatar4.png/-crop-104-104-104px-CommunityAvatar4.png) 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 [![Compile a Java Program](https://www.wikihow.com/images/thumb/3/3d/Compile-a-Java-Program-Step-10.jpg/-crop-342-184-245px-Compile-a-Java-Program-Step-10.jpg.webp) How to Compile a Java Program Using an SDK or Online Compiler ![](https://www.wikihow.com/images/thumb/3/3d/Compile-a-Java-Program-Step-10.jpg/-crop-342-184-245px-Compile-a-Java-Program-Step-10.jpg)](https://www.wikihow.com/Compile-a-Java-Program) [![Check Your Java Version in the Windows Command Line](https://www.wikihow.com/images/thumb/e/ef/Check-Your-Java-Version-in-the-Windows-Command-Line-Step-15-Version-2.jpg/-crop-342-184-245px-Check-Your-Java-Version-in-the-Windows-Command-Line-Step-15-Version-2.jpg.webp) How to Check Your Java Version in the Windows Command Line ![](https://www.wikihow.com/images/thumb/e/ef/Check-Your-Java-Version-in-the-Windows-Command-Line-Step-15-Version-2.jpg/-crop-342-184-245px-Check-Your-Java-Version-in-the-Windows-Command-Line-Step-15-Version-2.jpg)](https://www.wikihow.com/Check-Your-Java-Version-in-the-Windows-Command-Line) [![Set Java Home](https://www.wikihow.com/images/thumb/0/03/Set-Java-Home-Step-21-Version-3.jpg/-crop-342-184-245px-Set-Java-Home-Step-21-Version-3.jpg.webp) How to Set JAVA\_HOME for JDK & JRE: A Step-by-Step Guide ![](https://www.wikihow.com/images/thumb/0/03/Set-Java-Home-Step-21-Version-3.jpg/-crop-342-184-245px-Set-Java-Home-Step-21-Version-3.jpg)](https://www.wikihow.com/Set-Java-Home) [![Install the Java Software Development Kit](https://www.wikihow.com/images/thumb/0/0f/Install-the-Java-Software-Development-Kit-Step-40-Version-4.jpg/-crop-342-184-245px-Install-the-Java-Software-Development-Kit-Step-40-Version-4.jpg.webp) How to Install the Java Software Development Kit ![](https://www.wikihow.com/images/thumb/0/0f/Install-the-Java-Software-Development-Kit-Step-40-Version-4.jpg/-crop-342-184-245px-Install-the-Java-Software-Development-Kit-Step-40-Version-4.jpg)](https://www.wikihow.com/Install-the-Java-Software-Development-Kit) [![Create Your First Java Program on Ubuntu Linux](https://www.wikihow.com/images/thumb/7/7c/1955436-9.jpg/-crop-342-184-245px-1955436-9.jpg.webp) How to Create Your First Java Program on Ubuntu Linux ![](https://www.wikihow.com/images/thumb/7/7c/1955436-9.jpg/-crop-342-184-245px-1955436-9.jpg)](https://www.wikihow.com/Create-Your-First-Java-Program-on-Ubuntu-Linux) [![Run C Program in Command Prompt](https://www.wikihow.com/images/thumb/9/9c/Run-C-Program-in-Command-Prompt-Step-12.jpg/-crop-342-184-245px-Run-C-Program-in-Command-Prompt-Step-12.jpg.webp) How to Run a C Program Using Developer Command Prompt ![](https://www.wikihow.com/images/thumb/9/9c/Run-C-Program-in-Command-Prompt-Step-12.jpg/-crop-342-184-245px-Run-C-Program-in-Command-Prompt-Step-12.jpg)](https://www.wikihow.com/Run-C-Program-in-Command-Prompt) [![Program in Java](https://www.wikihow.com/images/thumb/5/5b/10381-10.jpg/-crop-342-184-247px-10381-10.jpg.webp) How to Program in Java ![](https://www.wikihow.com/images/thumb/5/5b/10381-10.jpg/-crop-342-184-247px-10381-10.jpg)](https://www.wikihow.com/Program-in-Java) [![Run a .Jar Java File](https://www.wikihow.com/images/thumb/6/68/Run-a-.Jar-Java-File-Step-10.jpg/-crop-342-184-245px-Run-a-.Jar-Java-File-Step-10.jpg.webp) How to Run a .Jar Java File ![](https://www.wikihow.com/images/thumb/6/68/Run-a-.Jar-Java-File-Step-10.jpg/-crop-342-184-245px-Run-a-.Jar-Java-File-Step-10.jpg)](https://www.wikihow.com/Run-a-.Jar-Java-File) [![Compile and Run Java Program by Notepad](https://www.wikihow.com/images/thumb/5/54/Compile-and-Run-Java-Program-by-Notepad-Step-30.jpg/-crop-342-184-245px-Compile-and-Run-Java-Program-by-Notepad-Step-30.jpg.webp) How to Compile and Run Java Programs Using Notepad++ ![](https://www.wikihow.com/images/thumb/5/54/Compile-and-Run-Java-Program-by-Notepad-Step-30.jpg/-crop-342-184-245px-Compile-and-Run-Java-Program-by-Notepad-Step-30.jpg)](https://www.wikihow.com/Compile-and-Run-Java-Program-by-Notepad) [![Install Java in Ubuntu Using Terminal](https://www.wikihow.com/images/thumb/4/48/Install-Java-in-Ubuntu-Using-Terminal-Step-22.jpg/-crop-342-184-245px-Install-Java-in-Ubuntu-Using-Terminal-Step-22.jpg.webp) How to Install Java in Ubuntu Using Terminal ![](https://www.wikihow.com/images/thumb/4/48/Install-Java-in-Ubuntu-Using-Terminal-Step-22.jpg/-crop-342-184-245px-Install-Java-in-Ubuntu-Using-Terminal-Step-22.jpg)](https://www.wikihow.com/Install-Java-in-Ubuntu-Using-Terminal) [![Run Ruby Code](https://www.wikihow.com/images/thumb/a/a6/Run-Ruby-Code-Step-13.jpg/-crop-342-184-245px-Run-Ruby-Code-Step-13.jpg.webp) How to Run Ruby Code ![](https://www.wikihow.com/images/thumb/a/a6/Run-Ruby-Code-Step-13.jpg/-crop-342-184-245px-Run-Ruby-Code-Step-13.jpg)](https://www.wikihow.com/Run-Ruby-Code) [![Run a Batch File from the Command Line on Windows](https://www.wikihow.com/images/thumb/2/22/Run-a-Batch-File-from-the-Command-Line-on-Windows-Step-12-Version-2.jpg/-crop-342-184-241px-Run-a-Batch-File-from-the-Command-Line-on-Windows-Step-12-Version-2.jpg.webp) How to Execute a Batch File from the Command Line (CMD) ![](https://www.wikihow.com/images/thumb/2/22/Run-a-Batch-File-from-the-Command-Line-on-Windows-Step-12-Version-2.jpg/-crop-342-184-241px-Run-a-Batch-File-from-the-Command-Line-on-Windows-Step-12-Version-2.jpg)](https://www.wikihow.com/Run-a-Batch-File-from-the-Command-Line-on-Windows) [![Compile a C Program](https://www.wikihow.com/images/thumb/1/15/Compile-a-C-Program-Step-25.jpg/-crop-342-184-245px-Compile-a-C-Program-Step-25.jpg.webp) How to Compile a C Program ![](https://www.wikihow.com/images/thumb/1/15/Compile-a-C-Program-Step-25.jpg/-crop-342-184-245px-Compile-a-C-Program-Step-25.jpg)](https://www.wikihow.com/Compile-a-C-Program) [![Install Oracle Java JRE on Ubuntu Linux](https://www.wikihow.com/images/thumb/e/e7/Install-Oracle-Java-JRE-on-Ubuntu-Linux-Step-24.jpg/-crop-342-184-245px-Install-Oracle-Java-JRE-on-Ubuntu-Linux-Step-24.jpg.webp) How to Install Oracle Java JRE on Ubuntu Linux ![](https://www.wikihow.com/images/thumb/e/e7/Install-Oracle-Java-JRE-on-Ubuntu-Linux-Step-24.jpg/-crop-342-184-245px-Install-Oracle-Java-JRE-on-Ubuntu-Linux-Step-24.jpg)](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 ![Yaffet Meshesha](https://www.wikihow.com/images/thumb/4/41/Yaffet_Meshesha.png/-crop-100-100-100px-Yaffet_Meshesha.png) 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](https://www.wikihow.com/images/thumb/0/0a/CommunityAvatar1.png/-crop-72-72-72px-CommunityAvatar1.png) 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). ![Yaffet Meshesha](https://www.wikihow.com/images/thumb/4/41/Yaffet_Meshesha.png/-crop-100-100-100px-Yaffet_Meshesha.png) 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](https://www.wikihow.com/images/thumb/0/0a/CommunityAvatar1.png/-crop-72-72-72px-CommunityAvatar1.png) 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](https://www.wikihow.com/images/thumb/f/f5/CommunityAvatar4.png/-crop-72-72-72px-CommunityAvatar4.png) 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](https://www.wikihow.com/images/thumb/b/b0/CommunityAvatar2.png/-crop-72-72-72px-CommunityAvatar2.png) Ashish Sharma Mar 21, 2016 "Thanks, wikiHow, this is very informative." ![Ibrahim Ali Khan](https://www.wikihow.com/images/thumb/f/f2/CommunityAvatar3.png/-crop-72-72-72px-CommunityAvatar3.png) 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 Quiz](https://www.wikihow.com/images/thumb/f/fe/Draw-Minecraft-Step-6-preview-Version-3.jpg/-crop-127-140-127px-Draw-Minecraft-Step-6-preview-Version-3.jpg.webp) What Kind of Minecraft Player Am I Quiz![](https://www.wikihow.com/images/thumb/f/fe/Draw-Minecraft-Step-6-preview-Version-3.jpg/-crop-127-140-127px-Draw-Minecraft-Step-6-preview-Version-3.jpg)Take Quiz](https://www.wikihow.com/What-Minecraft-Player-Am-I-Quiz) [![Am I Ready for College Quiz](https://www.wikihow.com/images/thumb/4/47/College_readiness_assessment_quiz.png/-crop-127-140-127px-College_readiness_assessment_quiz.png.webp) Am I Ready for College Quiz![](https://www.wikihow.com/images/thumb/4/47/College_readiness_assessment_quiz.png/-crop-127-140-127px-College_readiness_assessment_quiz.png)Take Quiz](https://www.wikihow.com/College-Readiness-Assessment-Quiz) [![IQ Test](https://www.wikihow.com/images/thumb/5/5d/Iq_test.png/-crop-127-140-127px-Iq_test.png.webp) IQ Test![](https://www.wikihow.com/images/thumb/5/5d/Iq_test.png/-crop-127-140-127px-Iq_test.png)Take Quiz](https://www.wikihow.com/IQ-Test) [![College Major Quiz](https://www.wikihow.com/images/thumb/5/58/College_major_quiz_image.png/-crop-127-140-127px-College_major_quiz_image.png.webp) College Major Quiz![](https://www.wikihow.com/images/thumb/5/58/College_major_quiz_image.png/-crop-127-140-127px-College_major_quiz_image.png)Take Quiz](https://www.wikihow.com/College-Major-Quiz) ### You Might Also Like [![Compile a Java Program](https://www.wikihow.com/images/thumb/3/3d/Compile-a-Java-Program-Step-10.jpg/-crop-127-140-127px-Compile-a-Java-Program-Step-10.jpg.webp) How to Compile a Java Program Using an SDK or Online Compiler![](https://www.wikihow.com/images/thumb/3/3d/Compile-a-Java-Program-Step-10.jpg/-crop-127-140-127px-Compile-a-Java-Program-Step-10.jpg)](https://www.wikihow.com/Compile-a-Java-Program) [![Check Your Java Version in the Windows Command Line](https://www.wikihow.com/images/thumb/e/ef/Check-Your-Java-Version-in-the-Windows-Command-Line-Step-15-Version-2.jpg/-crop-127-140-127px-Check-Your-Java-Version-in-the-Windows-Command-Line-Step-15-Version-2.jpg.webp) How to Check Your Java Version in the Windows Command Line![](https://www.wikihow.com/images/thumb/e/ef/Check-Your-Java-Version-in-the-Windows-Command-Line-Step-15-Version-2.jpg/-crop-127-140-127px-Check-Your-Java-Version-in-the-Windows-Command-Line-Step-15-Version-2.jpg)](https://www.wikihow.com/Check-Your-Java-Version-in-the-Windows-Command-Line) [![Set Java Home](https://www.wikihow.com/images/thumb/0/03/Set-Java-Home-Step-21-Version-3.jpg/-crop-127-140-127px-Set-Java-Home-Step-21-Version-3.jpg.webp) How to Set JAVA\_HOME for JDK & JRE: A Step-by-Step Guide![](https://www.wikihow.com/images/thumb/0/03/Set-Java-Home-Step-21-Version-3.jpg/-crop-127-140-127px-Set-Java-Home-Step-21-Version-3.jpg)](https://www.wikihow.com/Set-Java-Home) [![Install the Java Software Development Kit](https://www.wikihow.com/images/thumb/0/0f/Install-the-Java-Software-Development-Kit-Step-40-Version-4.jpg/-crop-127-140-127px-Install-the-Java-Software-Development-Kit-Step-40-Version-4.jpg.webp) How to Install the Java Software Development Kit![](https://www.wikihow.com/images/thumb/0/0f/Install-the-Java-Software-Development-Kit-Step-40-Version-4.jpg/-crop-127-140-127px-Install-the-Java-Software-Development-Kit-Step-40-Version-4.jpg)](https://www.wikihow.com/Install-the-Java-Software-Development-Kit) ### Trending Articles [![Princess Treatment vs Bare Minimum Quiz](https://www.wikihow.com/images/thumb/c/c9/Treat-Your-Girlfriend-Like-a-Princess-Step-1-Version-4.jpg/-crop-127-140-127px-Treat-Your-Girlfriend-Like-a-Princess-Step-1-Version-4.jpg.webp) Princess Treatment vs Bare Minimum Quiz![](https://www.wikihow.com/images/thumb/c/c9/Treat-Your-Girlfriend-Like-a-Princess-Step-1-Version-4.jpg/-crop-127-140-127px-Treat-Your-Girlfriend-Like-a-Princess-Step-1-Version-4.jpg)](https://www.wikihow.com/Relationships/Princess-Treatment-Quiz) [![Is My Boyfriend Secretly Gay? This Quiz Can Help](https://www.wikihow.com/images/thumb/8/84/Tell-if-Your-Boyfriend-Is-Gay-Step-2.jpg/-crop-127-140-127px-Tell-if-Your-Boyfriend-Is-Gay-Step-2.jpg.webp) Is My Boyfriend Secretly Gay? This Quiz Can Help![](https://www.wikihow.com/images/thumb/8/84/Tell-if-Your-Boyfriend-Is-Gay-Step-2.jpg/-crop-127-140-127px-Tell-if-Your-Boyfriend-Is-Gay-Step-2.jpg)](https://www.wikihow.com/Relationships/Is-My-Boyfriend-Gay-Quiz) [![Am I an Alpha, Beta, or Omega Quiz](https://www.wikihow.com/images/thumb/4/4b/Quiz_-_alpha_omega.jpg/-crop-127-140-127px-Quiz_-_alpha_omega.jpg.webp) Am I an Alpha, Beta, or Omega Quiz![](https://www.wikihow.com/images/thumb/4/4b/Quiz_-_alpha_omega.jpg/-crop-127-140-127px-Quiz_-_alpha_omega.jpg)](https://www.wikihow.com/Alpha-Beta-Omega-Test) [![Who Is My Soulmate Quiz](https://www.wikihow.com/images/thumb/a/ae/Soulmate_quiz_pic.png/-crop-127-140-127px-Soulmate_quiz_pic.png.webp) Who Is My Soulmate Quiz![](https://www.wikihow.com/images/thumb/a/ae/Soulmate_quiz_pic.png/-crop-127-140-127px-Soulmate_quiz_pic.png)](https://www.wikihow.com/Relationships/Soulmate-Quiz) [![wikiHow](https://www.wikihow.com/skins/owl/images/wikihow_logo_intl.png)](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) \- \- ![](https://sb.scorecardresearch.com/p?c1=2&c2=8003466&cv=3.9.1&cj=1) 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
[![PDF download](https://www.wikihow.com/extensions/wikihow/socialstamp/images/icon-pdf.svg) 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 [![PDF download](https://www.wikihow.com/extensions/wikihow/socialstamp/images/icon-pdf.svg) 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. [![Step 1 Save the program.](https://www.wikihow.com/images/thumb/1/1b/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-1-Version-3.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-1-Version-3.jpg)](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. [![Step 2 Open Command Prompt...](https://www.wikihow.com/images/thumb/e/ee/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-2-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-2-Version-4.jpg)](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") [![Windows cmd](https://www.wikihow.com/images/6/66/Windowscmd1.png)](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. [![Step 3 Check that Java is installed.](https://www.wikihow.com/images/thumb/c/cd/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-3-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-3-Version-4.jpg)](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. [![Step 4 Navigate to the folder your program is saved to.](https://www.wikihow.com/images/thumb/4/4a/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-4-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-4-Version-4.jpg)](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. [![Step 5 Compile the program.](https://www.wikihow.com/images/thumb/5/5d/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-5-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-5-Version-4.jpg)](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. [![Step 6 Run the program.](https://www.wikihow.com/images/thumb/7/71/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-6-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-6-Version-4.jpg)](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. [![Step 1 Set your path...](https://www.wikihow.com/images/thumb/5/52/Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-7-Version-4.jpg/v4-460px-Compile-%26-Run-Java-Program-Using-Command-Prompt-Step-7-Version-4.jpg)](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](https://www.wikihow.com/images/thumb/f/f5/CommunityAvatar4.png/-crop-104-104-104px-CommunityAvatar4.png) 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](https://www.wikihow.com/images/thumb/f/f5/CommunityAvatar4.png/-crop-104-104-104px-CommunityAvatar4.png) 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](https://www.wikihow.com/images/thumb/f/f5/CommunityAvatar4.png/-crop-104-104-104px-CommunityAvatar4.png) 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](https://www.wikihow.com/images/thumb/0/0a/CommunityAvatar1.png/-crop-72-72-72px-CommunityAvatar1.png) 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.** \- \- ![](https://sb.scorecardresearch.com/p?c1=2&c2=8003466&cv=3.9.1&cj=1)
Shard92 (laksa)
Root Hash12431216878206919092
Unparsed URLcom,wikihow!www,/Compile-%26-Run-Java-Program-Using-Command-Prompt s443