Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

How can I made my simple java program an executable program using the promt.

Basically I already made my program say hello world ,but it just say it when I am in the command promt ,I want to export my program that my frinds can open it by giving it double click. I know I can use eclipse but I want to know how to doe with the command promt.

2 Answers

Hi Dairon,

you can make a folder on your desktop and put your NameOfYourProgramm.java inside it.

If you are on widdows you can use Notepad to create little preogramms and save them as java files. (Save as .... change .txt to .java and give the file the same name as your main class)

When you are in cmd/terminal you should navigate in this folder (cd folder) and type "javac NameOfYourProgramm.java".

After this your javac (java compiler) will create a NameOfYourProgramm.class file inside your folder. So .java is your sourcecode and .class is your new executable programm (mashine code).

If you´re still inside of your folder, you can type "java NameOfYourProgramm" and your programm will run in cmd or terminal.

You can easyly copy and paste your folder whereever you want. Or you can simply give the .java file to your friend and they compile (using javac) it by themself.

If you get the "javac not found error" your JDK(Java Development Kit) has to be installed. YouTube it and you will get a bunch of great tutorials :)

I hope it might help :)

Grigorij

Thanks Grigorij