View Full Version : SDK Question
09-08-2002, 02:05 AM
I recently downloaded SDK 1.4.1 from java.sun.com. I've read a couple tutorials on how to use it.
Write your code into (in my case) notepad. Save it as HelloWorld.java to the bin directory of j2sdk1.4.1. Open dos, navigate to the j2sdk1.4.1 bin folder, and type in javac HelloWorld.java.
I've found a problem with this, if it is correct. (Or a problem on my computer anyway)
When I'm in the C:\ I see j2sdk1.4.1, yes. I then type cd j2sdk1.4.1 and hit enter. It gives me an invalid directory error. I have tried to move HelloWorld.java to a different directory, but javac is not a 'recognizable' command. I've also tried to rename j2sdk1.4.1, and it gives me an error, that some programs may not funtion properly if the directory is renamed.
My question is how do I compile and run a .java file?
09-08-2002, 03:25 AM
Ahh can see I'm not the only one learning java :) We could learn from each others threads here :D
The SDK never worked for me either, so I got the jdk1.1.8 This works perfectly for me. You put your .java file into the bin directory, didn't seem to work if I put it in a directory in the bin directory (ie jdk1.1.8\bin\test)
I also found a better site. Teaches you more of what you're coding than assuming you know everything
I used the HelloWorld tutorial from there and it worked :) The java.sun only worked after I took public off the first line
09-08-2002, 04:13 AM
I downloaded JDK1.1.8, and read the instructions on javacoffeebreak.com.
I edited my autoexec.bat to include the path of jdk1.1.8 bin and restarted my computer.
I'm afraid to say that it did not help. I created a HelloWorld.java file, saved it into the bin, and tried to access it with cd jdk1.1.8, but it gives me an invalid directory error for some reason.
I don't know what I'm doing wrong.
09-08-2002, 04:31 AM
are you going to C:\WINDOWS\jdk1.1.8 or C:\jdk1.1.8? The last one is correct.
09-08-2002, 10:06 AM
maybe a problem with long file names?
09-09-2002, 01:22 PM
For what it's worth:
Here's what I do and it works for me:
* Write my .java file and save it to a folder located at c:\javafiles
* Open a dos window and at the prompt I type: PATH = c:\jdk1.3.1\bin
* Navigate to the directory of the .java files (c:\javafiles)
* At the prompt type: javac whatevername.java
Everything works for me with this method.
09-09-2002, 09:41 PM
Thanks for all your replies.
Yes, I am using the C:\ and NOT C:\WINDOWS\ jdk1.1.8 is located in C:\ not C:\WINDOWS (or not for me anyways)
I think you might be right, and that I cannot use jdk1.1.8 on my Windows XP (Home Edition :( ) If this is true, it is quite sad that Windows would come out with a computer like this. All I can do is wait until I earn up enough money and get a custom windows 98 and Linux Mandrake.
I tried your method, and sorry to say, but it does not work. What it does (after I type path = C:\jdk1.1.8) is nothing. It stays in the same directory, and gives me no message. No error message, or anything...nothing.
If anyone else is running on windows XP (Home Edition) and has somehow gotten this to work (If you have, congratulations! :thumbsup: ), please help me.
09-10-2002, 11:41 AM
My guess is XP doesn't like the .1.2.43..126.96.36.199 in the directory name. Try this. Navigate to the directory and rename it to javaDev.
This should allow you to run the javac command from the bin directory. Just cd to c:\javaDev\bin
If that doesn't work try modifying the PATH variable like this.
From the command prompt type:
set PATH = %PATH%;c:\javaDev\bin
Then javac should work from anywhere on your machine. If, again, that doesn't work. Go to the top of a really tall building, with your computer. Open a window (not windows, just a window) and throw your computer (with windows) out the window. While your computer is falling, make sure to scream "Die Bill Gates Die!". It may not fix your java problem, but I think you'll feel better. :D
09-10-2002, 09:23 PM
thanks! It worked! I went into ms dos, navigated to C:\javadev\bin, and typed javac helloworld.java. It created a HelloWorld.class file in my bin directory.
Now I have 2 more easy questions if you don't mind.
1.) Is it possible to put my java files in a different directory and compile them there? If so, how?
2.) How do I view/run my compiled program? (In this case, helloworld.java - I want to see it say 'Hello, World!' just to have the satisfaction of knowing I'm a java programmer (Not a very good one, yet))
Thanks everyone for all your help!
09-11-2002, 12:16 AM
To see the compiled file, go to the bin directory, then type
09-11-2002, 09:19 PM
I went into dos, and typed: cd C:\javadev\bin. This took me to my java dev bin. I maded sure that HelloWorld.java and HelloWorld.class were in my bin. I typed java HelloWorld.class, and it gave me the error: Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class.
Then I tried java HelloWorldApp (because that's what you typed).class, and it gave me the same error.
I checked to make sure that the code was right, and it was. I looked up the same tutorial on time, copied and pasted it, and it still gave me the same error.
btw, sorry for being such of a "Newbie", but I really REALLY want to learn Java.
09-11-2002, 11:00 PM
Don't worry about it I've not got past the hello world script myself as I've not had time. I only did the hello world script last week. I have no idea why it won't work on your pc either. I'm just as confused as you
09-11-2002, 11:47 PM
I'll probably just continue in the tutorial then...
I'm learning C++ at school, and I just downloaded the compiler, so I can learn Java and C++ at the same time! Hey, School is actually useful! lol! Well, best of luck to you. (and me for that matter)
09-12-2002, 06:00 PM
Just a note, the java command to run a java class file does not need the .class extension. In fact it won't work with it.
To run a java class file simply type
I beleive if you type java myClassFile.class it looks for a file in the package (ie directory) class.
Also, to run the commands from anywher (in Windows) simply got to your dos a type the following
09-12-2002, 06:56 PM
So after you set the path, you don't have to go to the bin directory all the time in dos? you can just type java HelloWorldApp at C:\WINDOWS?
09-13-2002, 12:31 AM
Yes, once your environmental variable PATH includes a link to the java folder, you can access all the applications (javac, java, javadoc, etc) from anywhere on the system. It's like creating a file association in Windows where all .htm files will lauch IE.
It's a neat little trick in Wondows.