blakdragon39 Posted September 15, 2010 Share Posted September 15, 2010 Hello, its me again. :unsure: I've downloaded this JDK: http://www.oracle.com/technetwork/java/javase/downloads/jdk6-jsp-136632.html And now all I'm trying to do is create a simple hello world program: [hide] //firstprog.java: class firstprog { public static void main (String[] args) { System.out.println("Hello, world."); } } [/hide] Using command prompt, I go into the directory I saved this into and type: javac firstprog.java And this is what I get: 'javac' is not recognized as an internal or external command,operable program or batch file. After some searching to find out what was going wrong I found this page: http://download.oracle.com/javase/tutorial/getStarted/problems/index.html And tried the first suggestion, which didn't fix the problem. At first I tried typing in exactly what they said there, and it said it couldn't find the path file specified. So then I tried typing: C:\Program Files\Java\jdk1.6.0_21\bin\javac firstprog.java That's where the javac executable is. It told me 'C:\Program' wasn't a recognized command. What I got from that was that it didn't like the space that I used while typing the command.. So here are my questions:1) How can I type that file path correctly to see if this will work?2) If that DOES work, what can I do to make it so I don't have to type that entire file path every time I want to compile a Java program?3) If that doesn't work, what might I have done wrong? EDIT: After playing around a bit more, I tried moving the javac executable into the same directory as firstprog.java. When I tried to compile it using the same command, it told me some file was missing. So I felt like I was getting somewhere. :P I tried copying the ENTIRE jdk1.6.0_21 contents into the same directory and this is what happened: [hide]C:\Users\User\Documents\Classes\CMPT 270>javac firstprog.javaException in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/MainCaused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source)Could not find the main class: com.sun.tools.javac.Main. Program will exit. C:\Users\User\Documents\Classes\CMPT 270>[/hide] So now I know it's doing something? But evidently I've messed up somewhere... But I shouldn't have to have the entire contents of the JDK6 in the same directory as my program to use it, right? Link to comment Share on other sites More sharing options...
GottaGetDownOnfriday Posted September 15, 2010 Share Posted September 15, 2010 Use quotations ("") around the path. Also, in order to keep from typing in the path to the JDk, you might want to add the directory to your path environment variable. This will allow you to simply type in "javac myjavafile.java". To add the jdk to your path variable, go into system settings(press windows key+ pause|break button or go to control panel > system settings). Under the "Advanced" tab there will be a button which says "Environmental Variables". Under the "System Variables" groupbox, there is a line which says "Path". Add a semicolon(;) to the end if there is not one already then add the path to the bin directory of your JDK. Click "Ok" then "Apply". If you had command prompt open, close and open it again and now you can use the JDK via command line without typing in the path. 65,280 to 99 fletching on 3-14-0940,405 to 99 woodcutting on 10-17-2009 Link to comment Share on other sites More sharing options...
blakdragon39 Posted September 15, 2010 Author Share Posted September 15, 2010 Great I'll try doing both of those! I tried adding my C/C++ compiler to my environmental variables once... I don't think it went well. =\ I have a batch file I run every time I open command prompt to temporarily ... do something to make the compiler work. xD Hopefully I have better luck with this right now! EDIT: Good progress so far... Upon typing: "C:\Program Files\Java\jdk1.6.0_21\bin\javac" firstprog.java My program compiled perfectly, and then ran perfectly. :D So I know if I wanted to be, I could finally be on my way to making Java applications, hoorah!! Now I'm going to try changing that environmental variable. :P EDIT: Tried changing the environmental variable... Didn't do it right I suppose. :P When I went to add it this is what I typed:Variable name: javacVariable value: C:\Program Files\Java\jdk1.6.0_21\bin\javac[Caution: Executable File]; Is that correct? Link to comment Share on other sites More sharing options...
GottaGetDownOnfriday Posted September 15, 2010 Share Posted September 15, 2010 Great I'll try doing both of those! I tried adding my C/C++ compiler to my environmental variables once... I don't think it went well. =\ I have a batch file I run every time I open command prompt to temporarily ... do something to make the compiler work. xD Hopefully I have better luck with this right now! EDIT: Good progress so far... Upon typing: "C:\Program Files\Java\jdk1.6.0_21\bin\javac" firstprog.java My program compiled perfectly, and then ran perfectly. :D So I know if I wanted to be, I could finally be on my way to making Java applications, hoorah!! Now I'm going to try changing that environmental variable. :P EDIT: Tried changing the environmental variable... Didn't do it right I suppose. :P When I went to add it this is what I typed:Variable name: javacVariable value: C:\Program Files\Java\jdk1.6.0_21\bin\javac[Caution: Executable File]; Is that correct? No. You must append your jdk path to the existing variable called "path"'s contents by adding";C:\Program Files\Java\jdk1.6.0_21\bin;". This will allow you to use any java executable file in that folder by typing in its name. 65,280 to 99 fletching on 3-14-0940,405 to 99 woodcutting on 10-17-2009 Link to comment Share on other sites More sharing options...
obfuscator Posted September 15, 2010 Share Posted September 15, 2010 Use netbeans ;) Seriously, that'll save you the trouble. http://www.netbeans.org "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
blakdragon39 Posted September 15, 2010 Author Share Posted September 15, 2010 No. You must append your jdk path to the existing variable called "path"'s contents by adding";C:\Program Files\Java\jdk1.6.0_21\bin;". This will allow you to use any java executable file in that folder by typing in its name. Ooh! Okay, thanks! Give this another try. :D And I might use netbeans or something sometime (there's some IDE we're going to be using in the class I'm taking.. can't remember what it's called.) But for right now, I want to know how to make it work with just a text editor and command prompt as well! Can't hurt to know. :) EDIT: It worked! Hoorrah. :D It took FOREVER to run just the hello world program though... not sure why. =\ But anyways, now maybe I can figure out how to get my C compiler to work correctly as well! Thanks for the help guys. :) If anyone could tell me why it took so long just to print "hello world" though? EDIT: It worked super fast the second time I ran firstprog... EDIT: AAHHH I even figured out how to properly install my C compiler. :D Thanks for all the help guys!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now