Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Stumbling Block at the beginning

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been trying to go through the exercise in Head First Java, and I did the first exercise, but when I go to the command prompt to move to the directory where java is, the computer tells me that c:\program (It's in the program files) is not a recognizable command, or batch file, etc. What am I missing?
 
lowercase baba
Posts: 13048
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you shouldn't be going to where java is installed, but to where you have saved your .java file. and that should be somewhere OTHER than where java is installed. I have a c:\slop directory, but many folks don't like that name.

In any case, to change directories, you need to type "cd path/to/files".

if you are trying to change to a directory with a space in it (like 'program files'), enclose it in double-quotes:

cd "c:\program files"



Note that in windows, once you have 'enough' of the directory typed, you can hit the tab key and it will auto-finish. I think if you have NOT typed enough, it will put in the first match, and you can continue tabbing until you get the dir you want.

 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Debbie
In the CMD window, navigate to the directory where your .java files are present and set the given environment variables as follows,



After you have done the above you can compile and execute your Java programs.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably have to put quotes around "C:\Program Files\..." here too, because there is a space in the directory name:

Madhan Sundararajan Devaki wrote:

 
Marshal
Posts: 75644
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and welcome to the Ranch
 
Debbie Albright
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for all the help:) For the record, I did set the path for java, found the directory where the java file was living, and it won't let me change to that directory either. It says it cannot find the path specified. I'm using Windows 7, btw. Am I missing something? And Sheriff, thank you for the warm welcome.:)
 
Debbie Albright
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I finally got the compiler working. But when trying the example, the book says the last line of code is } //more code...
when I run javac, it says that there is an error in that statement, and I've tried taking it apart piece by piece, and there's still an error. Any suggestions?
 
Campbell Ritchie
Marshal
Posts: 75644
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome

I suggest you open a command prompt and write these two lines

mkdir java
cd java

Next time you need to get to your "java" folder, you only need the second line. Obviously you can choose a different name for the folder.
You should avoid putting your own work inside the Java™ installation folders in Program Files. If you create your own folder (which would be inside "My Documents" if you follow my suggestion), you will have access to it because the OS wont' think it is a system folder.

As for the compiler error, please show us more code.
 
fred rosenberger
lowercase baba
Posts: 13048
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
post all your code. use the 'code' button the same way you'd do italics or bold. clicking the button gives you a [ code] and a [ /code] (only without the spaces). paste what you have between them, and it will preserve your formatting, making it easier to read.

and don't just say 'the compiler gave me an error'. The text it gives is often very specific, telling you exactly what the error is. So please post the entire text of the error as well (if there is more than one, the first one or two are enough).

If you do those two things, it is orders of magnitude easier to help you with your problem.
 
Replace the word "snake" with "danger noodle" in all tiny ads.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic