aspose file tools*
The moose likes Beginning Java and the fly likes Is this the place to ask installation questions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is this the place to ask installation questions?" Watch "Is this the place to ask installation questions?" New topic
Author

Is this the place to ask installation questions?

Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Hi everyone!
I took a java course last year and, of course, have forgotten almost every bit of it. Well, I'm inspired to hit the books once again and see if I can rekindle some of the old java-magic in my brain. My problem is that I can't get the PATH and CLASSPATH issues resolved on my Win XP Pro computer. (different computer than the one I had when I took the class)
Here's my steps so far:
1) downloaded and installed j2sdk1.4.2_04. Installed in the C directory. Javac and all other executables are in the "bin" sub-directory.
2) Wrote a "Hello World" program in Notepad - saved as "hello.java" - there is no .txt extension (good!). The file is also in the "bin" subdirectory.
3)According to my Course Technology textbook (by Joyce Farrell) - I set the path and classpath this way:
Control Panel --> System --> Advanced --> Enviromental Variables....there was already a PATH command. I added "C:\J2SDK1.4.2_04\BIN;.;" to the end of the PATH. I have since moved this to the beginning of that line - to no avail.
4) Again, according to the Farrell textbook, I clicked "new" and added a CLASSPATH command with this "C:\J2SDK1.4.2_04\BIN;.;" I then re-started my system.
I opened the command prompt screen and changed the directory to root C. At the C prompt, I type "javac hello.java" and the error message is this:
"error: cannot read: hello java
1 error"
ARGH!!! I've tried this 37 ways in the last day and half. I get the same error message no matter what I try - even if I remove the hello.java file from the "bin"! And because I keep getting the same error message, I'm inclined to think it's got something to do with my settings in PATH and CLASSPATH - or maybe system incompatibility.
Can anyone help me? It's threatening my sanity!
Thanks in advance!
Michelle D (and please forgive me if this post is in the wrong forum!)
Antoine Waugh
Ranch Hand

Joined: Jan 24, 2004
Posts: 66
heya,
well the error message your getting:
"error: cannot read: hello java
1 error"
refers to the hello.java file itself, not the javac command. (If your interested the error if javac is not regognised is: javac is not regognized as an internal or external command.. etc)
is it possible your not in the same directory as your hello.java file?
cd c:\whatever...\bin\
javac hello.java
java hello
-twans


B.C.S.T, SCJP, Hero
Antoine Waugh
Ranch Hand

Joined: Jan 24, 2004
Posts: 66
out of curiosity, if your in the cmd and type:
cd C:\J2SDK1.4.2_04\BIN
then javac hello.java
does it compile?
-t1s
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Originally posted by Antoine Waugh:
is it possible your not in the same directory as your hello.java file?
cd c:\whatever...\bin\
javac hello.java
java hello
-twans[/QB]

Antoine -
I thought that was the whole idea of setting the PATH in the Environmental Variables. I also tried specifying the path at the DOS prompt, like this:
C> \j2sdk1.4.2_04\bin\javac hello.java
and got the same error message. The file is definitely in the "bin" sub-directory of the j2sdk1.4.2_04 folder on my C drive. Should it (the bin directory or the java file itself) be someplace else?
If I can't get the thing running, I certainly don't hold out much hope for rekindling the programming part of my brain. (sigh).
Thanks for any help!
Michelle D.
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Originally posted by Antoine Waugh:
out of curiosity, if your in the cmd and type:
cd C:\J2SDK1.4.2_04\BIN
then javac hello.java
does it compile?
-t1s

You read my mind. See my other reply (above).
Antoine Waugh
Ranch Hand

Joined: Jan 24, 2004
Posts: 66
this may be a stupid quetion, but is your class name the same as the files name?
unline c and other languages that create an executable.. java insists that there is ONE public class per file, and that class name (case sensitive) is the filename
so you MUST have
class Hello
{
}
for it to be called Hello.java
otherwise there will be an error..
and if in your c:\java....\bin directory, and you type 'dir' is hello.java listed?
-t1s
[ April 21, 2004: Message edited by: Antoine Waugh ]
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Originally posted by Antoine Waugh:
this may be a stupid quetion, but is your class name the same as the files name?
unline c and other languages that create an executable.. java insists that there is ONE public class per file, and that class name (case sensitive) is the filename
so you MUST have
class Hello
{
}
for it to be called Hello.java
otherwise there will be an error..
and if in your c:\java....\bin directory, and you type 'dir' is hello.java listed?
-t1s
[ April 21, 2004: Message edited by: Antoine Waugh ]

No, not a stupid question. I've checked that several times. The program reads....
"public class hello...." (in lower-case, also)
and the file is named "hello.java" It is saved in the "bin" sub-directory.
The file shows up when I check the j2sdk1.4.2_04 directory at the command prompt.
(small piles of pulled-out hair surrounding my computer chair...)
Thanks again!
Michelle D.
Greg T Robertson
Ranch Hand

Joined: Nov 18, 2003
Posts: 91
Have you tried setting your path & classpath explicitly at the prompt and then trying it? e.g. at a command prompt
set PATH=C:\J2SDK1.4.2_04\BIN
set CLASSPATH=
and then do a javac -classpath C:\J2SDK1.4.2_04\BIN hello.java
and then trying to compile?
You could also look to see if there are any other javac.exe on your machine besides the one you think you are using.
(note that setting these things at the command prompt will make them only valid for the time during which that command windows is open which makes it much easier to try different settings)
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Hi Greg,
I have tried what you suggested - but am going to try it again. I've just uninstalled the whole shebang and am going to re-install and re-write the hello world program.
I'll also check for that additional javac now before I reinstall anything.
Thanks for your input. I'll report back any results.

Michelle D.
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Hi!
Well, yay! First success! I reinstalled everything and re-wrote the hello.java program. Then, I went straight to the command prompt and changed my directory all the way to c:\j2sdk1.4.2_04\bin. When I achieved this (which surprised the daylights outta me!), I typed "javac hello.java" at the prompt. NO ERROR MESSAGE! Whoohooo!
I then typed "java hello" and my program ran! YIPPEEE!! Thanks you guys!
But - that's just the battle - not the war. I want to set the path in the environmental variables. I'll check back as that progresses (hopefully more success!
THANKS GUYS! More later!
Michelle D.
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Hi guys!
Ok, I went in to control panel --> system --> advanced --> enviromental variables and added the java directory (j2sdk1.4.2_04) to the existing path command. I also added the CLASSPATH command. I get the previous error message....
Soooo, at least I have figured out how to compile a program - but I would DEARLY love to know why I can't add the PATH and CLASSPATH and get it to compile.
I did find a javac.exe attached to another program (DREAMWEAVER MX). However, that path is NOT specified in the environmental variables area.
There's also something called javac.exe-28d787113.pf in a WINDOWS\Prefetch directory. Anyone ever heard anything like that.
Arg! And thanks a bunch!
Michelle D.
Tobias Hess
Ranch Hand

Joined: Apr 06, 2004
Posts: 55
Ok, I went in to control panel --> system --> advanced --> enviromental variables and added the java directory (j2sdk1.4.2_04) to the existing path command. I also added the CLASSPATH command. I get the previous error message....
Make sure your in the same directory as the .java file. Make dir to verify it. Then, the error could not be the same as you've described above.
The enviroment variables are _not_ to tell the compiler where your source files (hello.java) are. Those can be anywhere you want them, for instance in c:>\work _but_ you have to be in the same directory, or give a full path name.
Let's say your actual directory is c:\ , and those hello.java is in c:\work. You can compile it from where you are, with javac c:\work\hello.java
If it still doesn't work, give us all the commands you enter including all error messages you get - copy it out of the console window and paste it in here.
HTH,
Tobias
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Hi Tobias,
Check my original message. I SWEAR that those are all the steps and that is the EXACT wording of the error message. The file is in the "bin' sub-directory, as is the JAVAC executable.
Does it have something to do with the fact that I'm working on a Windows XP Professional machine? I'm grasping at straws here...
I've tried moving the file around and still got the same error message. I tried DELETING the .java file and got the same message. Cross my heart and hope to die....It's puzzling, isn't it?!
Thanks for your thoughts!
Michelle D.
Tobias Hess
Ranch Hand

Joined: Apr 06, 2004
Posts: 55
Check my original message.
Ok, here we go.
Wrote a "Hello World" program in Notepad - saved as "hello.java" - there is no .txt extension (good!). The file is also in the "bin" subdirectory.
Thus, the file hello.java is in the jdk\bin directory.
I opened the command prompt screen and changed the directory to root C. At the C prompt, I type "javac hello.java" and the error message is this:
"error: cannot read: hello java
1 error"

Your actual directory is root C. It's exactly the error I described above.
Please, post a complete log of your console session. I'm sure we can figure it out.
Tobias
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Hi Tobias!
I'm sorry to be dense - please define log and also console (session).
However, if you're referring to what I'm doing at the DOS window, which is at this prompt when I open it: "C:\Documents and Settings\Michelle>"
If I'm trying to compile without changing the environmental variables, I change directory all the way down to "bin" sub-directory like this:
cd c:\j2sdkk1.4.2_04\bin and press ENTER....
Then I type "javac hello.java" and the file compiles.
Then I type "java hello" and the program runs. YEAH!
However, if I'm trying to see if I've set the PATH and CLASSPATH environmental variables correctly, I type this at the DOS prompt:
C:\Docs and Settings\Michelle>cd c:\
Which gives me the root C directory, and I type "javac hello.java" and get the error message. PHEW!
Should I send you what I'm doing in the environmental variables? Because it's the only place I can think of that's generating this problem.
Thanks in advance for your help.
Michelle D.
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Hi Tobias,
I also see what you mean about the file not needing to be in the "bin" directory along with the javac executable. I could still SWEAR that when I took the java class last year, the Nutty Professor had us saving files at the root level in a "java" folder and in the DOS window, we would simply change directory to C.
I'm confused. I'm still in my pajamas. It's been a long day....
Thanks!
Michelle D.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Hey Michelle,
I'll take a stab at trying to explain this....
First the PATH variable: This tells your OS where to look for executables when requesting them from the command line. For example, in every Windows XP Pro path you will have something along the lines of:
c:\$system_root%\system32
If you were to remove this from your PATH then when you type a command like ping the system wouldn't be able to find it unless you were in c:\windows\system32 subdirectory. So...when you set the JAVA_HOME\bin in your PATH all that is doing is telling the system where to find those executables when you type them in at the command line.
Now, the CLASSPATH: The classpath in java tells the compiler and the VM where to find llibraries it needs to compile and run Java code. IT DOES NOT TELL THE COMPILER/VM WHERE YOUR .java FILE IS. So if you have a subdir called c:\projects and in the folder you have a file called hello.java, you MUST be in that folder to compile and execute that code. The only other way is to explicitly tell the compiler/vm where that file is. So if you weren't in that directory you could do this command:
javac c:\projects\hello.java
Since the current JDK/JVM already know where it's own core libraries are, you should never have to specify the classpath for compiling/running simple java programs. A hello.java file only relies on core JVM libraries. On the other hand, if you ever use 3rd party libaraies (typically JAR files) in your code, then you must specify the classpath so that the compiler/VM know where to find those additional libraries.
I hope this makes some sense and I haven't confused you even more. In a nutshell, you shouldn't have to worry about the classpath at all right now and the PATH is only for being able to execute java.exe and javac.exe from any directory at the command prompt on your system.


GenRocket - Experts at Building Test Data
Tobias Hess
Ranch Hand

Joined: Apr 06, 2004
Posts: 55
I'm sorry to be dense - please define log and also console (session).
You're not, those words are badly chosen. Console means dosbox in Windows terms. With log I mean all the text that apperas in your dosbox from start to end of whatever you do.
I could still SWEAR that when I took the java class last year, the Nutty Professor had us saving files at the root level in a "java" folder and in the DOS window, we would simply change directory to C.
I believe that. It could be set up that way. It just doesn't make sense to do it, so don't bother. Make a directory of your choice, cd to it, edit your source file and compile it from there.
Good luck with learning java (again),
Tobias
Michelle Suschinsky
Greenhorn

Joined: May 03, 2003
Posts: 12
Tobias and Gregg,
Thanks so much for your help and explanations. I've printed out most of what I've learned here today so that I can re-read and digest. I see what you mean (Tobias) about making my directory at the root level and leaving it at that.
My teacher last year was certainly a programming genius - the problem was that the rest of the class was NOT. Also, the school provided the computers where all the java and other programs (Oracle databases and etc) had been previously installed, so fat chance on learning how to do that as part of the course. I understand that they were trying to save time, but a morning of being led through it back then would have saved me a boatload of confusion today.
I thank EVERYONE for their time and thoughts and responses! It's nice to know there's a friendly corner of the world where one can come to get a few questions answered and explained. I'm sure you'll be hearing from me again (possibly tonight )
Michelle
[ April 21, 2004: Message edited by: Michelle Suschinsky ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

My teacher last year was certainly a programming genius
Interesting statement. Are you sure about that? The guy did have you putting your source code in the JAVA_HOME\bin directory.
Don't mistake knowing the material for genius.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Is this the place to ask installation questions?