To ensure that your file is saved as a . java file, be sure to write . 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 of how to write a program in Java, check out our tutorial on how to program in Java. For the purposes of learning how to compile and run a program, though, you can use any sort of Java program.

Windows: Press ⇱ Home, then type cmd. Press ↵ Enter to open the Command Prompt. Mac: In Finder, press the Go tab, select Applications, select Utilities, then select Terminal.

If not, you may need to install the Java Development Kit from their website. It is free and can be found at this link: http://www. oracle. com/technetwork/java/javase/downloads/index. html.

For example, if you were operating in C:\Users\Bob\Project and wanted to get to C:\Users\Bob\Project\TitanProject , enter in cd TitanProject and press ↵ Enter. You can see a list of what is in your current directory by typing dir and pressing ↵ Enter.

For example, if you were operating in C:\Users\Bob\Project and wanted to get to C:\Users\Bob\Project\TitanProject , enter in cd TitanProject and press ↵ Enter. You can see a list of what is in your current directory by typing dir and pressing ↵ Enter.

If you have any errors in your program, or if there is difficultly compiling, the command prompt will notify you. Check out our article about how to fix compiler errors in Java for more help.

After pressing ↵ Enter, your program should run. If you receive an error, or if your program fails to run in any way, refer to the troubleshooting method.

Windows: Type java -version into the command prompt and press ↵ Enter. Based off the version of Java displayed on the first line, type in set path=%path%;C:\Program Files\Java\jdk1. 5. 0_09\bin to the command prompt and press ↵ Enter. Substitute jdk1. 5. 0_09 with whatever version of Java you have installed. Be sure you are entering in this command while in the directory containing your Java project. Mac: Type /usr/libexec/java_home -v 1. 7 into the terminal and press ↵ Enter to ensure Java is installed on your system. Then, type echo export “JAVA_HOME=$(/usr/libexec/java_home)” » ~/. bash_profile into the terminal and press ↵ Enter. Restart the terminal afterwards.

Be sure you are entering in this command while in the directory containing your Java project.

Be sure you are entering in this command while in the directory containing your Java project.