• 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

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

 
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
This is my first time at javaranch.com and I am pretty new with java. I installed Java JDK 6 Update 16 under C:ProgramsFiles\Java\ on my computer (windows xp). Of course, I had to try the simple Hello World program. I set up my PATH variable on
System Properties->Advanced->Environment Variables->CLASSPATH=C:\Program Files\Java\jdk1.6.0_16\bin; I then tried to compile hello.java which is

public class hello {

public static void main (String[] args) {

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

using javac hello.java but it gave an error that says: 'javac' is not recognized as an internal or external command, operable program or batch file. I then tried to move the program inside the bin, compile it and it didn't give me an error. However, I couldn't find the hello.exe program to run. I then tried to break the program (take the quotation mark ") to see if the compiler will complain about it and it sure did give me a compile error on command prompt. I've also tried closing cmd window and even restarted my computer but still no luck. I've tried searching online about and it points to the PATH variable but I think I've set my path correctly.
If anyone ran into this problem or know of any other things I can try, please let me know.


Thanks,
LostSoul
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John:

PATH and CLASSPATH are two different environment variables. PATH is where Windows looks for your executable file (javac). CLASSPATH is where Java looks for your classes and jar files.

John.
 
Marshal
Posts: 79959
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

If you managed to get a compiler error when you took the quote mark out, you would appear to have set up your PATH correctly.
The javac command doesn't produce an .exe file. You get a .class file and (if it contains a main method) execute that main method with the command

java hello

Not .class.

I suggest next time you open your command line you execute these two commands

mkdir java
cd java

Now you have a folder to put all your java work into. Put your "hello World" files into that directory. Now using the cd java instruction whenever you open a command prompt will take you into that folder. You can obviously use a different name, make subfolders, etc. Now try java hello in that folder.

By the way: the convention is for class names to start with a capital letter.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,
Thanks a bunch for the pointer. I thought about it this morning and did a little lookup on PATH and CLASSPATH. I was setting the wrong environment variable. I needed to set PATH to the write address.
I made a directory using the commands you mentioned on your reponse. I am not totally familiar with command prompt keyword yet but I will look into more of this and use command line to write small program before I switch to gui base compiler (ie eclipse).

Regards,
lostsoul
 
Campbell Ritchie
Marshal
Posts: 79959
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avoid Eclipse and other IDEs until you are a lot more experienced. You have enough to learn with Java without burdening yourself with learning the IDE too.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Richie,
I have another quick question. In C++, I can use #include whenever I used a class within a class. I am wondering what is the equivalent of this in JAVA.

Thanks,
lostsoul
 
Good night. Drive safely. Here's a tiny ad for the road:
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