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

Complete Beginner

Christopher Daly
Greenhorn

Joined: Sep 01, 2010
Posts: 10
Hi All,
Starting the java programming side of my Computer Science degree in October and I was looking at geting a head start. Ive downloaded the Java Development Kit as suggested in 'the Learn Java through a little hard work in the JavaRanch Cattle Drive' section of your website but I cant get thet Hello World program to run in my DOS command prompt. It says it doesnt recognise the JAVAC command.

Help!

Chris
Virendrasinh Gohil
Ranch Hand

Joined: Jun 09, 2004
Posts: 46
Christopher Daly wrote:.... It says it doesnt recognise the JAVAC command...

Looks like you are facing problem with PATH variable. You must have your 'JAVA_HOME' defined and your path '%JAVA_HOME%/bin' added.
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

You have to set the path to command prompt. like set path = C:\Program Files\Java\jdk1.6.0_05\bin;.; if you have windows OS.

Life is easy because we write the source code.....
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

How do I set or change the PATH system variable
Christopher Daly
Greenhorn

Joined: Sep 01, 2010
Posts: 10
That worked a lot better only now its says:

HelloWorld.java:1: error while writing Hello World: HelloWorld.class <Access is denied>
public class HelloWorld
^

1 error

Thanks for your help
Christopher Daly
Greenhorn

Joined: Sep 01, 2010
Posts: 10
Thanks for that thread on changing the PATH whats the difference between the PATH and CLASSPATH and which directory do I need to put in? C:\Program Files\Java\jdk1.6.0_21\bin this one or the one suggested on this website?

I they both just pointing the command pompt to my classes?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14111
    
  16

PATH is what Windows uses to find programs to run. CLASSPATH is what Java uses to find *.class files to run. It's best to leave CLASSPATH not set to anything. If you don't set it, Java will look in the current directory for class files.

Don't put your source code or compiled classes in C:\Program Files\Java\jdk1.6.0_21\bin. You're not supposed to put anything in that directory. Just create a C:\Projects directory or something like that, and put your own stuff in there.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Christopher Daly
Greenhorn

Joined: Sep 01, 2010
Posts: 10
So, for example my HelloWorld program is the c:\Projects folder and I want to compile and run it. As long as my PATH is set correctly it should be no problem to go to c:\Projects in DOS and run the compile command JAVAC? Also, am I setting the path to C:\Program Files\Java\jdk1.6.0_21\bin or the one suggested on the website?

Christopher Daly
Greenhorn

Joined: Sep 01, 2010
Posts: 10
Got it, thanks for your help I added this C:\Program Files\Java\jdk1.6.0_21\bin to my PATH. I ran the file as you suggested from c:\Projects and it ran a treat. Thanks for all your help.
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

Go checkout the library at your college and see if they have "Head first java", if not try and pickup a second hand copy off ebay/amazon. Read through that and you'll be better placed than a lot in your class!


Kind Regards, James. OCPJP 1.6 || My SCJP / OCJCP Study Notes
Interested in : SCJP, Google App Engine, Stripes, Android;|| My Bite-Size SCJP Study Blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
James Elsey wrote: . . . "Head first java", if not try and pickup a second hand copy off ebay/amazon.
Read it and do the exercises therein. And make sure to get the 2nd edition.
 
Consider Paul's rocket mass heater.
 
subject: Complete Beginner