PDA

View Full Version : Can't run simple Java HelloWorldApp.java


agfre44_9873
05-12-2009, 10:14 PM
I installed jdk1.6.0_13. Program files->Java. Inside the java directory I have jdk1.6.0_13 folder, jr6 folder, and HelloWorldApp.java. I reinstalled jdk6 about six times already. I'm new to this. I am following the directions from http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html.
At the following link...
http://java.sun.com/javase/6/webnotes/install/jdk/install-windows.html I am using the path on step four...
C:> "\Program Files\Java\jdk1.6.0_<version>\bin\javac" MyClass.java.

Now, I don't know if Sun microsoft wantds me to include the double qoutes or not, so I try it without both...

The following is from cmd...


C:\Documents and Settings\charles>cd c:\

C:\>cd Program Files

C:\Program Files>cd java

C:\Program Files\Java>dir
Volume in drive C has no label.
Volume Serial Number is 0C53-36D7

Directory of C:\Program Files\Java

05/10/2009 07:50 AM <DIR> .
05/10/2009 07:50 AM <DIR> ..
05/10/2009 07:48 AM 74 apth.txt
05/10/2009 07:50 AM 1,410 error.txt
05/10/2009 07:46 AM 1,910 HelloWorldApp.java
05/10/2009 07:41 AM <DIR> jdk1.6.0_13
05/10/2009 07:18 AM <DIR> jre6
3 File(s) 3,394 bytes
4 Dir(s) 11,360,313,344 bytes free

C:\Program Files\Java>cd c:\

C:\>"\Program Files\Java\jdk1.6.0_13\bin\javac" HelloWorldApp.java
javac: file not found: HelloWorldApp.java
Usage: javac <options> <source files>
use -help for a list of possible options

C:\>\Program Files\Java\jdk1.6.0_13\bin\javac HelloWorldApp.java
'\Program' is not recognized as an internal or external command,
operable program or batch file.

C:\>"\Program Files\Java\jdk1.6.0_13\bin\javac" HelloWorldApp.java
javac: file not found: HelloWorldApp.java
Usage: javac <options> <source files>
use -help for a list of possible options

C:\>

Any ideas anyone...please!

shyam
05-14-2009, 06:37 PM
you need to get a better understanding of the command line and understand how directories work.

you should try giving the full/relative path to your java source file for javac to work...

seriously, consider using an ide like netbeans or eclipse

agfre44_9873
07-22-2009, 04:13 PM
Thank u shyam. I gave up on it

TheShaner
07-23-2009, 04:32 PM
you need to get a better understanding of the command line and understand how directories work.

you should try giving the full/relative path to your java source file for javac to work...

seriously, consider using an ide like netbeans or eclipse
An IDE is definitely the best option, but it doesn't hurt to help steer him in the right direction. If the OP is going to start programming in any way, he needs to be familiar with how accessing files within a directory structure work, even if for doing File I/O.

Two things you need to know:

You need to point to the location of javac if not currently in that directory
You need to point to the location of the main java file (which is the one that contains your main method) if not currently in that directory


All of the below options work (quotes are required if spaces exist in the path) and many more are available as long as you remember the two points above:
C:> "Program Files\Java\jdk1.6.0_13\bin\javac" "Program Files\Java\HelloWorldApp.java"
C:\Program Files\Java> "C:\Program Files\Java\jdk1.6.0_13\bin\javac" HelloWorldApp.java
C:\Program Files\Java> jdk1.6.0_13\bin\javac HelloWorldApp.java
C:\Some Folder> "C:\Program Files\Java\jdk1.6.0_13\bin\javac" "C:\Program Files\Java\HelloWorldApp.java"


But THE BEST option is to right click on My Computer, select Properties, click the Advanced tab, and click the Environment Variables button. You should now see a section that says "User variables for <user name>".

If the PATH variable doesn't exist, click the New button and for Variable Name use PATH and for Variable Value use "%PATH%;C:\Program Files\Java\jdk1.6.0_13\bin" (without the quotes).

If the PATH variable exists, select it and click Edit. Go to the end of the Variable Value, put a semicolon at the end, and then type (paste) in "C:\Program Files\Java\jdk1.6.0_13\bin" (without the quotes).

Once you've selected OK for the windows that are open, you will now be able to use the Java executables from wherever you are in your directory structure and will not have to use the full path, like so:

C:> javac "Program Files\Java\HelloWorldApp.java"
C:\Some Folder\I Dont Care Where\WhyNotHere\> javac "C:\Program Files\Java\HelloWorldApp.java"
C:\Program Files\Java> javac HelloWorldApp.java
-Shane