• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

I can't run my first program on command line

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79967
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To add to what Jesper said, don't do anything with your classpath variable.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic