Introduction: Programing With Java Using Command Prompt

Picture of Programing With Java Using Command Prompt

This instructable will teach you how to: 

1. Install the Java Development Kit.

2. Set system variables to easily be able to compile and execute java files.

3.  Compile and execute a Java file from Command Prompt.  

** This is mainly for Windows 7 and Vista.

Step 1: Download Latest JDK

Picture of Download Latest JDK

1.Follow this link:
2. Click Download JDK under the download Java Standard Edition panel.
3. Choose your operating System and agree to the terms of service. **
** This will  probably be Windows since your using Command Prompt.

Step 2: Setting Path for Command Prompt

Picture of Setting Path for Command Prompt

1. Open the Command Prompt .
2 Type "set Path=C:\Program Files\Java\jdk1.6.0_21\bin" .*
3. Type  " set HomePath= C:\Program Files\Java\ jdk1.6.0_21 *

* If you have a later jdk ( i.e. jdk 1.6.0_22) replace the portion that says jdk1.6.0_21 with it.

** If you don't know which jdk you have go to: start pane( at bottom left corner of you screen)>click run> click browse>Then  go to C:\Program Files\Java

*** Do not type quotation marks in steps 1-3  at command prompt.


Step 3: Creating a Simple Java Program

Picture of Creating a Simple Java Program

Create Program
1. Go to Start pane>All Programs > Accessories> Notepad.exe
2 Copy and paste the following exactly:
public class helloworld
public static void main(String[] args)

System.out.println("Hello World!");

3. a.Save file as: 
     b.Make sure "save as type" under where you typed the file name as "All Files" (as opposed to the default "Text-File").
      c. You want to save your java file where  the Command Prompt  is set to open at.*

*Such as C:\Users\MyUserName 

Step 4: Compiling and Executing the Program

Picture of Compiling and Executing the Program

1.First compile file by going to Command Prompt and typing javac
2.This will create a class file which you can execute by typing java helloworld
3. It should print "Hello World!" to show your done.

Step 5: Learn More

Picture of Learn More

1. The next thing you want to do is get a textbook that will teach you the Java language, precisely.I recommend Programing and Problem Solving with Java
 by Nell B. Dale and  Chip Weems .
2. You can get this from following this link:


NekomonoC (author)2015-11-02

I have a problem with step 4, it just says " 'javac' is not recognized as an internal or external command, operable program or batch file

h_s_m (author)NekomonoC2016-01-20

Same here......

jaki57 (author)NekomonoC2015-12-31

me too

NekomonoC (author)NekomonoC2015-11-02

please help me :(

patilsupriya made it! (author)2015-10-22

Hello guys,

I am new for java. I tried one small java program with the help of this blog.but i am stuck on compiling step and getting error saying file not found.

Please anyone correct me.



www139 (author)2015-10-10

Wonderful! I have been scouring the internet trying to figure this out without screwing stuff up. Thank you for making it so clear.

RubénR8 (author)2015-07-29

Hi, the tutorial has been really helpful, I have some questions, though:

1. Why do we have to type "set Path=C:\Program Files\Java\jdk1.6.0_21\bin" and "set Path=C:\Program Files\Java\jdk1.6.0_21\bin"? I tried just typing either one and it compiled just fine

2. Is there any difference between "set Path=C:\..." and "set PATH=%PATH%;C:\..." (besides the syntax)?

Thanks in advance :)

sudeeps1 (author)2015-05-21

In cmd javac,it takes few sec and there is no error but in cmd java myprogramme,there is a msg shown is-
Error:Could not find or load main class myprogramme

plz tell me how short out this prob??

avinashd (author)2014-09-30

Truely great................. Thats all i want to say

works 100%....

Harrisons (author)avinashd2014-12-16


AatmanS (author)2014-08-25

This works 100% fine. Thanx for adding it on net.

mk12345 (author)2013-10-29

with these we have to take care of the spell and case of the class

About This Instructable




Add instructable to: