aspose file tools*
The moose likes Beginning Java and the fly likes Really basic question! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Really basic question!" Watch "Really basic question!" New topic
Author

Really basic question!

Siva Sathyendran
Greenhorn

Joined: Aug 04, 2005
Posts: 5
Hello,
I have finally got around to start learning Java and have downloaded j2sdk1.4.2_08 from the Sun website. Its in the following directory: C:\j2sdk1.4.2_08
As is customary, I have created the HelloWorld program and tried to compile it from the command prompt.
If I put the full path in ie: c:\j2sdk1.4.2_08\bin , then it compiles ok and runs ok (using the javac and java commands), BUT I have tried to set the path permanently (as advised in a number of websites). I am running Windows XP and added the Path variable in the 'user variables' in Control Panel/System/Advanced/Enviromental variables/User Variables. (There was no Path variable in the list initially), but when I try to compile in DOS get the message "1 error, cannot read".
I then tried adding in System variables (there was already Path listed there) and this too did not work.
I have deleted these 2 entries in User/System variables and when I type path after the C:\prompt in DOS still see the j2sdk1.4.2_08 path at the end of other listings in DOS. I also see 2 semi-colons after the last entry in Path. before the j2sdk path begins.
How do I set the path permanently, given that I have tried all the above.
I must add that when I type 'dir' in DOS I can see my saved HelloWorld file.
Thanks in advance....
Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
Hey Siva,

1. Open Windows Explorer by right clicking on the Start button.
2. Right-click on My Computer.
3. Select Properties.
4. Select the Advanced Tab.
5. Click on the Environment Variables button.
6. In System Variables click the New button.
7. In the Variable Name enter JAVA_HOME
8. In the Variable Value enter C:\j2sdk1.4.2_08
9. Click OK
10. If you have a PATH variable in the system area select it and hit the edit button.
(If you don't have a PATH variable in the system area click new and enter PATH in the Variable NAME and no semi-colon in the next step.)
11. Add at the end of the Variable VALUE ;%JAVA_HOME%\bin
12. Click OK
13. Click OK

The above steps will get you access to the java, javac, etc. executables. You still should get a variable setup so that you can access the classes you create. To do that, do the following:
13. Create a new System Environment Variable (like above) named CLASSPATH.
14. Enter . for the Variable Value (you may want to add directories later to this value as you build more projects).
15. Hit OK

You probably set the path variable correctly before, but if you had a DOS window open while you were setting them - you have to close it and reopen it before it will pull in the new variable information.

I hope this helps.
Anand Bala
Greenhorn

Joined: Jan 19, 2004
Posts: 8
Right click "MyComputor" --> Properties
select "Advavced" tab
click "Environment Variables"

Then Under System variables

* append the Path varibale with this "C:\j2sdk1.4.2_08\bin;"
* append the CLASSPATH with this "C:\j2sdk1.4.2_08\lib;"
and put a "." at the bigining of the CLASSPATH
eg: CLASSPATH = .;C:\j2sdk1.4.2_08\lib;

Try this. Should work.
Siva Sathyendran
Greenhorn

Joined: Aug 04, 2005
Posts: 5
Hello,
Thanks for taking the trouble to post the replies. I am afraid that both the methods did not work. Any ideas?
Mahesh x Bogadi
Ranch Hand

Joined: Jul 06, 2004
Posts: 51
I suggest to use an IDE like Eclipse.
Where the IDE detect the java installation set required variables.

When you are comfortable with java you can always know how to set CLASSPATH etc.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
I am afraid that both the methods did not work. Any ideas?

"did not work" is not very specific.

Did you reboot after changing the system environment PATH? What happens when you type
javac
(nothing else)
??

Did you remove the PATH stuff from the User Variables?

I would have put the
%JAVA_HOME%\bin;
at the beginning of the path rather than at the end of the path because I've seen interference from MicroSoft stuff when I put it at the end.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Siva Sathyendran
Greenhorn

Joined: Aug 04, 2005
Posts: 5
Sorry I did not make myself very clear in my earlier reply.
Yes, I have re-booted after making the changes in System Variables.
Yes, I have removed 'Path' from User variables.
Yes, Javac (on its own) comes up with a list of possible switches etc.
Yes, I have added %JAVA_HOME%\bin to the beginning of 'Path' in the system varables, re-booted and tried again (although I have read that the re-boot
is not necessary in Windows XP).

Still, when I compile get the following error:
=====================================================
C:\Documents and Settings\Sathy>javac HelloWorld.java
error: cannot read: HelloWorld.java
1 error
======================================================

When I compile using the full path (each time) ie:
C:\j2sdk1.4.2_08\bin the compilation is fine.
Also, when I type in 'path' in DOS this is what I get:

=======================================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Sathy>path
PATH=C:\j2sdk1.4.2_08\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbe
m;C:\Program Files\ATI Technologies\ATI Control Panel;C:\PROGRA~1\COMMON~1\SONIC
S~1

C:\Documents and Settings\Sathy>
=======================================================================

As you can see everthing seems ok, but I still cannot compile.
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

What are you using to write your HelloWorld.java source file? This may sound unbelievably simple, but if you're using notepad.exe, be careful how you save your file. If you don't change the "Save As Type" option from "Text Documents" to "All Files", notepad will tack on an extra suffix to your file, saving it as "HelloWorld.java.txt" (which, for obvious reasons, won't work for the compiler).

Hope this helps...
Siva Sathyendran
Greenhorn

Joined: Aug 04, 2005
Posts: 5
Yes, I am saving the file in the correct format. As I posted earlier, javac does compile when I use the full path each time and runs ok.
I have now downloaded the latest version of the SDK (1.5.0_04) and changed the system variables to reflect this, but I still cannot get it to compile. (Same error message as before).
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Mahesh Bogadi:
I suggest to use an IDE like Eclipse.
Where the IDE detect the java installation set required variables.

When you are comfortable with java you can always know how to set CLASSPATH etc.


I suggest NOT using an IDE. It will only add significantly to the learning curve. In my opinion, setting the PATH is much simpler. You also don't need to worry about setting the CLASSPATH at this point. You can learn about that later.

Layne


Java API Documentation
The Java Tutorial
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Siva Sathyendran:
Yes, I am saving the file in the correct format. As I posted earlier, javac does compile when I use the full path each time and runs ok.
I have now downloaded the latest version of the SDK (1.5.0_04) and changed the system variables to reflect this, but I still cannot get it to compile. (Same error message as before).


The error message you get indicates that it is running the Java compiler just fine, but it cannot find the HelloWorld.java file that you saved. Your PATH variable seems to be set correctly. This is verified by the output from the "path" command. So what are you using to edit HelloWorld.java? And where did you save it? (Perhaps you should show us the output from running the "dir" command.) Also, you said that it compiles fine when you use the full path. Did you try to run it after compiling this way? Can you show us what happens?

Layne
Siva Sathyendran
Greenhorn

Joined: Aug 04, 2005
Posts: 5
OK here goes.....
First of all I checked the path:
=================================================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Sathy>path
PATH=C:\Program Files\java\jdk1.5.0_04\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WIN
DOWS\System32\Wbem;C:\Program Files\ATI Technologies\ATI Control Panel;C:\PROGRA
~1\COMMON~1\SONICS~1

C:\Documents and Settings\Sathy>
=========================================================================
Then I tried to compile without using the full path:

==========================================================

C:\Documents and Settings\Sathy>javac HelloWorldApp.java
error: cannot read: HelloWorldApp.java
1 error

C:\Documents and Settings\Sathy>
===========================================================
Next I compiled using the full path:

=================================================================

C:\Documents and Settings\Sathy>cd c:\Program Files\java\jdk1.5.0_04\bin

C:\Program Files\Java\jdk1.5.0_04\bin>javac HelloWorldApp.java

C:\Program Files\Java\jdk1.5.0_04\bin>
==================================================================

And last of all I ran the compiled file:

===============================================

C:\Program Files\Java\jdk1.5.0_04\bin>java HelloWorldApp
Hello World!

C:\Program Files\Java\jdk1.5.0_04\bin>
================================================

As you can see, it works perfectly with the full path in....
I'm wondering if its something to do with XP and the system variables ?

Thanks again for all the help and advice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Really basic question!