• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I can't run my first program on command line

 
ken wise
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please HELP me out!
I can't run my first program on command line\command prompt, it keeps giving me the error message below:

'javac' is not recognized as an internal or external command,operation

program or batch files


Below is what i did:

1-I installed notepad++

2-I typed my code into it and saved as C:\ex1

3-I ran my cmd and changed directory to C:\ex1

4-At C:\ex1> I typed "javac Squarer.java" (as seen in the JPG image i sent along)

5-The message i get is -'javac' is not recognized as an internal or external command,operation

program or batch files.-

NB: PLEASE I DON'T KNOW WHERE I WENT WRONG OR WHAT I HAVE TO FIX TO MAKE MY PROGRAM RUN

BECAUSE ALL THE PROGRAMS I RUN ON COMMAND LINE DISPLAY THE SAME ERROR MESSAGE.

Thanks for your HELP!
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ken wise wrote:1-I installed notepad++

thats fine.
ken wise wrote:2-I typed my code into it and saved as C:\ex1

you must save a java file with .java extension . so in your case the file name must be "ex1.java"[example FileName.java]

ken wise wrote:3-I ran my cmd and changed directory to C:\ex1

if ex1 is the folder name, then it is fine.

ken wise wrote:4-At C:\ex1> I typed "javac Squarer.java" (as seen in the JPG image i sent along)

with this command you are asking compiler to comiple/verify your source code

ken wise wrote:5-The message i get is -'javac' is not recognized as an internal or external command,operation

but unfortunately, window cant find your compiler[javac] to execute[assume you are working on window platform] you need to add javac.exe location to the window PATH
to set this, right click on your mycomputer icon on your desktop-->advanced tab--> environment variable ---> click PATH variable in system variable and then edit/add java installation path upto bin directory example: C:\Program Files\Java\jdk1.6.0_16\bin
[or]
just mentioned fully qualified name of the javac in command prompt i.e, "C:\Program Files\Java\jdk1.6.0_16\bin\javac" Squarer.java [here path is surrounded by "" because it contains space(Program Files)]

after successful of compilation , run using "C:\Program Files\Java\jdk1.6.0_16\bin\java" Squarer

or java Squarer [if you add java location into the system path]

hth
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15459
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Please read the installation instructions for the JDK, especially step 4 (Update the PATH variable).

And please DON'T WRITE IN ALL CAPS BECAUSE IT LOOKS LIKE YOU ARE SHOUTING!!
 
Henry Wong
author
Marshal
Pie
Posts: 21446
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you install a JDK?

And if you did, did you follow all the instructions, particularly the one about setting the PATH variable?


[EDIT: Beaten to the answer again.]

Henry
 
Rite Sara
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are getting this error because it could not locate the path where java is installed on your machine.
You have to set classpath for this. Your class path should point to the bin folder of your jdk folder.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15459
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rite Sara wrote:You have to set classpath for this. Your class path should point to the bin folder of your jdk folder.

No, that's wrong.

You have to add the bin directory of your JDK installation to the PATH (not the CLASSPATH). The PATH is what the operating system uses to find programs to execute.

CLASSPATH is for Java itself, this is what Java uses to find Java programs (class files and JAR files) to run. Do not add the bin directory of the JDK to the CLASSPATH, that won't solve the problem.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49865
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add to what Jesper said, don't do anything with your classpath variable.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:To add to what Jesper said, don't do anything with your classpath variable.

To add to what Jesper and Campbell said, PLEASE don't mess with the classpath.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic