Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Complete Beginner

 
Christopher Daly
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
 
Christopher Daly
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christopher Daly
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Campbell Ritchie
Sheriff
Posts: 48441
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic