File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Basic help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Basic help" Watch "Basic help" New topic
Author

Basic help

Julie Nelson
Greenhorn

Joined: Nov 24, 2008
Posts: 13
I'm trying to run the basic "Hello, world!" java file but keep getting errors. My first question is, does it matter if I have both J2SE Development Kit 5.0 and Java 1.6.0.70 since I'll be specifying the file path in the command prompt?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Welcome to JavaRanch

Please give more details of the errors; does the compiler run, does the code compile, and if so, does it run?

I think you are making life unnecessarily difficult for yourself setting the PATH from the command line; set the path permanently (there are links from the common problems page) and you won't need to do it until you upgrade your Java installation.
You ought not to have any difficulty having two versions installed; you are simply using whichever appears first in your PATH and ignoring the other.
Julie Nelson
Greenhorn

Joined: Nov 24, 2008
Posts: 13
Well, I have the file saved on my desktop as Hello.java and when I type "javac Hello.java" I get an error saying, "Javac is not recognized as an internal or external command..." To my understanding that error message is saying it's not recognizing the path where the file is saved, correct? If so I don't get it since I'm clearly stating the path in the command prompt. And does it matter if when I click on the properties of my saved file the type of file says, "jGRASP Java file"?


C:\Documents and Settings\Juliet>cd desktop

C:\Documents and Settings\Juliet\Desktop>javac Hello.java
'javac' is not recognized as an internal or external command,
operable program or batch file.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

To my understanding that error message is saying it's not recognizing the path where the file is saved, correct? If so I don't get it since I'm clearly stating the path in the command prompt.


No. It's not complaining about the java file. It's windows complaining that "javac" (the java compiler) is not found in the path specified.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Julie Nelson
Greenhorn

Joined: Nov 24, 2008
Posts: 13
So if the javac is in a different path how do I get it to work with a file that's in another path? Do I type both paths, combined in one line, for it to register?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

Originally posted by Julie Nelson:
So if the javac is in a different path how do I get it to work with a file that's in another path? Do I type both paths, combined in one line, for it to register?



Well, that's one way to do it. Another way is to add it to Window's PATH -- just like with all the other programs you installed on Windows.

Henry
Julie Nelson
Greenhorn

Joined: Nov 24, 2008
Posts: 13
Let's say I have my javac in drive C:\Program Files\Java\jdk1.5.0\bin (and javac is in the bin file) but I have my Hello.java saved under C:\Documents and Settings\Juliet\Desktop...if my current path says, "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\QuickTime\QTSystem\" then I just add the C:\Program Files\Java\jdk1.5.0\bin to it? Or do I delete the part of the path that says, "\QuickTime\QTSystem\ and replace that with "\Java\jdk1.5.0\bin ?
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Just add a ";" at the end of your path and then tell the computer where you have the bin directory installed on your machine. Do NOT delete the rest of your path variable or other things may stop working.


SCJA
~Currently preparing for SCJP6
Julie Nelson
Greenhorn

Joined: Nov 24, 2008
Posts: 13
So my beginning path was this:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\QuickTime\QTSystem\


Then all I do is add what's below:
;C:\Program Files\Java\jdk1.5.0\bin


So the end result will look like the following?

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Java\jdk1.5.0\bin
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Yes, that's exactly right. After setting this, you will need to open a new Command Prompt window for this to take effect.

If you would rather use the Java 1.6 version, then specify that location instead of the Java 1.5 path. (The PATH is checked from left to right, and your system will use the first one that works.)


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Julie Nelson
Greenhorn

Joined: Nov 24, 2008
Posts: 13
So now that I have the path updated I am to open the command prompt. Currently my command prompt is directed to C:\Documents and Settings\Juliet.

Am I supposed to change that so it points to the direction of the Hello.java file, which would be C:\Documents and Settings\Juliet\Desktop (since I saved the file to my desktop) and once that's set will I type in the "javac.Hello.java"?
Julie Nelson
Greenhorn

Joined: Nov 24, 2008
Posts: 13
Nevermind that last question. It worked! Thank you all for your help, I really appreciate it!!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Well done sorting it out. Suggest you create a "java" folder somewhere convenient; you will end up with hundreds of .java files all over your desktop otherwise.
 
jQuery in Action, 2nd edition
 
subject: Basic help
 
Similar Threads
What is JT400 jar?
getAttribute with Object Conversion
How to run a program contained in a jar file
How Save File in Directory and path of the file in database using Struts 2.0 and Ejb 3.0
Java Test?