aspose file tools*
The moose likes Beginning Java and the fly likes Stumbling Block at the beginning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stumbling Block at the beginning" Watch "Stumbling Block at the beginning" New topic
Author

Stumbling Block at the beginning

Debbie Albright
Greenhorn

Joined: Jul 26, 2011
Posts: 3
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?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10925
    
  12

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

@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.


S.D. MADHAN
Not many get the right opportunity !
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

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:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
... and welcome to the Ranch
Debbie Albright
Greenhorn

Joined: Jul 26, 2011
Posts: 3
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

Joined: Jul 26, 2011
Posts: 3
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
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
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
Bartender

Joined: Oct 02, 2003
Posts: 10925
    
  12

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stumbling Block at the beginning
 
Similar Threads
Remotely Accessing a pc in JAVA
OO Calculator -- a Tutorial
Problem compiling pgm
Error: Exeption in thread "main" java.lang.NoSuchMethodError: main
General Java