File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Greenhorn with 64-bit can't set path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Greenhorn with 64-bit can Watch "Greenhorn with 64-bit can New topic
Author

Greenhorn with 64-bit can't set path

Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11
Hi,

Would you please help a Greenhorn with a 64-bit system, who downloaded java through a 64-bit Browser (does that make a difference?)

My Command Prompt says C:\Users\Gary>;

and I've then typed various combinations of: cd C:\Program Files\Java\jdki.6.0_15\bin\javac MyClass.java

which is what you were explaining to someone in yesterday's forum. Actually the 15 shown above and in my files is different to the update 26 it told me I was receiving. Also, should I put a space then MyClass.java after the path, which is what it looks like.

As you can tell, I'm a complete Greenhorn, so any help you can give me would be much appreciated.

Gary
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3815

Welcome to Javaranch, Gary .
ctually the 15 shown above and in my files is different to the update 26 it told me I was receiving.

Can you elaborate this a little bit?
Also, should I put a space then MyClass.java after the path,

Yes.
Were you able to compile the program, if not got any errors?

here's the beginners FAQ section which explains the basics.




SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11
Hi Vijitha, thanks for your help:

"Actually the 15 shown above and in my files is different to the update 26 it told me I was receiving".

By this I just meant that the folder was called jdk1.6.0_15 and I thought the 15 was the update - yet when I loaded java it told me I had update 21 (sorry, not 26). It probably isn't important!!

I was trying to set the path rather than compile any program, and the error message was either "The system cannot find the path specified or, 'C:Program' is not recognized as an internal or external command operable program or batch file.

It's probably something stupid that I'm doing wrong or maybe I'm missing a bit of what I should have downloaded. For instance the book is 2005 and it says I need API documentation. Eh? I couldn't find where to download that or whether it is still relevant and isn't included automatically.

Cheers

Gary
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11139
    
  16

you don't want to type
cd C:\Program Files\Java\jdki.6.0_15\bin\javac MyClass.java


the 'cd' means 'change directory', and it is expecting you to ONLY give a directory - not a path to an executable and an argument to that exe.

try typing this:

C:\Program Files\Java\jdki.6.0_15\bin\javac -version

and tell us what you get. If you get an error, then you don't have the compiler. If you get something like "javac 1.6.0_20", then we're making progress.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11
Hi Fred, thanks for helping me..

I typed what you said (and put jdki instead of jdk1 !!) it said 'C:\Program' is not recognized etc... so it appears that I don't have a compiler. Can you help me there?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11139
    
  16

sorry - replying while at work...

another issue is the space character in the path name. I think you also don't need the "c:" at the front, if you are in the C drive already.

so...drop the "c:" from the beginning, and wrap the whole thing in quotes.

you can tell if you have the compiler if you cd into that directory and do a "dir *.exe"

you can also try something like this:

C:\>dir "\program files\java\jre6\bin\*.exe"


obviously you'd need to adjust to your path.
Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11
Wow Fred, I think we're cooking on gas..

I changed it to the c directory and entered: C:\>dir "\program files\java\jre6\bin\*.exe"

...and I got a directory of program files. It probably doesn't mean my path is working yet, but it's the nearest I've got to a meaningful response from the command line..

Any ideas of what my next move is to get my path working. Please remember, there's Greenhorns, and there's Green Greenhorns, and I come under the latter category..

Cheers,

Gary
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11139
    
  16

in that list of .exe files, did you see the one "javac.exe"? that is what you need to compile something.

Assuming you do...

The fastest way would be to cd into the directory where your *.java file you want to compile is. once there, type

"\program files\blah\blah\blah\javac.exe filename.java"

make sure you use the quotes around the whole thing...it's the space in the path that that is messing you up.

If this works, we'll go to the next step.
Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11
Hi Fred,

I've got javacpl.exe; java.exe; java-rmi.exe; in fact everything but javac.exe! I'm going to do what you said though but with javacpl.exe - feel free to stop me if it won't help...
Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11
Thinking about it, I changed that line of yours

from

C:\>dir "\program files\java\jre6\bin\*.exe" where I got the directory without javac.exe

to

C:\>dir "\program files\java\jdk1.6.0_15\bin\*.exe" and I got javac.exe in the list

HOORAY

So I've now saved a WordPad file MyFirstApp.java in the above route within the bin folder - I'm sure that's the wrong thing to do.. however, ..

Then typed "\Program Files\Java\jdk1.6.0_15\bin\javac.exe MyFirstApp.java"

and it wasn't recognised..

But Fred, we must be getting close...

Cheers

Gary
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

So I've now saved a WordPad file MyFirstApp.java in the above route within the bin folder - I'm sure that's the wrong thing to do.. however, ..

Yep Not that it's not going to work, but it's going to pollute your JDK install directory.

Then typed "\Program Files\Java\jdk1.6.0_15\bin\javac.exe MyFirstApp.java" and it wasn't recognised..

Try "\Program Files\Java\jdk1.6.0_15\bin\javac.exe" MyFirstApp.java. You have to be in the directory where MyFirstApp.java is.

By the way, we have a new FAQ about creating your first Java program. This may help.


[My Blog]
All roads lead to JavaRanch
Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11


Thank you all for trying to help, but I'm afraid I'm getting nowhere. I've followed the FAQ - to the letter - about creating your first java program, but it won't work my MyFirstApp.java or MooseGreetings.java - javac is not recognised...

Have I put the stuff in the wrong folder:

C:\>"Program Files\Java\jdk1.6.0_15\bin\javac.exe" MyFirstApp.java

I put the MooseGreetings.java - as instructed in the FAQ - in the java/src - but in my install it's a zip file. Surely that wouldn't work!

C:\>Program Files\java\src (zip file)

so now I've put MooseGreeting.java and MyFirstApp.java in:

C:\>Program Files\Java\jdk1.6.0_15\bin folder - not pretty, but the object of the exercise is getting it to work! - and I've no idea where to put them.

I've tried all sorts of angles but get repeatedly "Program Files not recognised" or " javac: file not found MooseGreetings.java"

Please help. Will to live is slipping away..

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Maybe you are not so familiar with working with the Windows command prompt window? Try finding a tutorial on working with the command prompt.

One important concept to understand is the current directory. When you open the command prompt, you get a line that looks something like this:

C:\Users\JdeJong> _

The "C:\Users\JdeJong" is the path of the current directory. When you start a program by typing in a command, the program will look for files from that directory. When you want to compile a Java source file by typing in a command like javac MyProgram.java, then the directory that contains the source file (MyProgram.java) has to be in the current directory.

You can change the current directory by using the cd command, for example:

C:\Users\JdeJong> cd "\Program Files\Java\src"
C:\Program Files\Java\src> _


Note that the prompt has changed after typing the command, to show what the new current directory is (C:\Program Files\Java\src, in this case).

So, first cd to the directory that contains your source file. Use the dir command to list the files in the current directory. Make sure that your source file is in the current directory and has the correct name before you try to compile it.

To avoid having to type the entire path to javac (the compiler) each time, you'll have to add the bin directory of your JDK installation to the PATH environment variable. After you've done that, you can just type "javac" instead of "C:\Program Files\java\jdk1.6.0_21\bin\javac". The page that Christophe linked to explains how to change the PATH.

The fact that you're using 64-bit Windows doesn't make any difference; this all works exactly the same on 32-bit Windows.


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

Joined: Oct 24, 2007
Posts: 11
Thank you for that. I've now done the following to get in the directory:

cd "\Program Files\java\jdk1.6.0_15\bin" (I've got my applications languishing in there for the time being!)

I then typed:

javac MyFirstApp.java

and got the response:

MyFirstApp.java:1: class MooseGreetings is public, should be declared in a file named MooseGreetings.java
public class MooseGreetings {

1 error

If I type javac MooseGreetings.java in the directory, nothing happens at all.

I notice that MooseGreetings has got a java file and a class file in the folder, whereas MyFirstApp has just got a java file.

Hopefully you can see from the above what I'm doing wrong...


fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11139
    
  16

ok...as has been said, you really shouldn't leave your files in that directory, but we can deal with that later.

When you write a java file, you write it in a language you can understand, and have to follow well defined rules. One of those rules says that you can only have ONE public class defined in a given file, and the file name MUST match the name of the class.

So, in your file MyFirstApp.java, you clearly have something like "public class MooseGreetings...". This is not allowed. You need to either change the name of the file to "MooseGreetings.java", or change the class name in the file to "MyFirstApp".

If I type javac MooseGreetings.java in the directory, nothing happens at all.
I doubt that is true. Try deleting your MooseGreetings.class file. then run that command again. I'm guessing that first, of all, it drops you back to a command prompt (that is something, even if it doesn't look like it). I'm betting it also created your MooseGreetings.class file. That is also something.

Once you write a .java file, you have to compile it into a language your computer can understand - or more precisely, the JVM can understand. That's what a class file is. You now need to RUN the class file (assuming it has a main() method in it).

To do this, you need to find the path of your java.exe program. From the directory where your .class file lives, call the java.exe with the full path (again, probably in quotes) and then give it JUST THE CLASS NAME, not the file name...something like

"\program files\java\jre6\bin\java.exe" MooseGreetings


Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11
Fred, you're spot on:

I deleted the class file, ran it again and it did nothing (i.e. it returned me to the prompt) and it reappeared in the bin folder (if you can think of a sensible place where I should put these files, where it will still work...?)

I then ran it again as you directed and it said: mooooooooooo

That's got to be a good sign..

In MyFirstApps however, there wasn't any mention of a Moose but when I looked in there there was. Eh? I got it straight out of page 9 of the book

Anyway, I re-worded it:

public class MyFirstApp {
public static void main(String[] args) {
System.out.println("Hello");
System.out.println("World");
}
}

Then made the class file like you told me, and re-entered:

"\program files\java\jre6\bin\java.exe" MyFirstApp

and it said:

Hello
World

Please tell me that's a good thing.. It looks to me like we're cooking on gas..
Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11
Fred,

I just moved onto page 10 and typed up:

public class FirstExercisePage10 {

public static void main (String[] args) {
int x = 3;
String name = "Dirk";
x = x * 17;
System.out.print ("x is " + x);
double d = Math.random ();
//this is a comment
}
}

Then made the class file like you said, and ran it like you said, and got:

x is 51

it looks like, to me, that thanks to you Fred, and Vijitha, Christophe, and Jesper - that I've cracked it.

Thank you very very much for you time.

I'm being dragged away now (kicking and screaming) but if you can leave any useful hints of how I can improve my system (for instance where to put my compilations) then I will be very grateful. Or, if you realise that I haven't cracked it at all and I'm living in cloud-cuckoo-land, then please let me know.

Many thanks again

Gary
(Sheffield UK)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11139
    
  16

We have established that you have the JDK, which lets you compile. You also have the JRE (which is actually part of the JDK) which lets you run things.

You now know how to compile and run things.

this is a terrific first step.

Many folks, especially when first starting, will just make their own directory, somehting like:

C:\JavaProjects

then, under that, you can make subfolders to your hearts content. I'd create a subfolder for each project you do, so something like a "HFJava" folder, "goofingAround" folder, and "myAppToTakeOverTheWorld" folder.

Put your source (aka '*.java') files in the appropriate directory. then, navigate to the directory where you want to compile. You can call the compiler as above...you can then run it the same way.

Eventually, you will get tired of typing the full path to the .exe each time. The solution is to edit your PATH environment variable. Search this forum, or google it, and you'll find tons of write ups on how to do that. If you get stuck come back. You can tell it works if, after doing it and opening a new command window, you type "javac -version" from ANY directory, and you don't get an error.

<pedant>It is really wrong of you to say you type your command and it does nothing. It returns to a command prompt, which is actually quite a lot. it creates a new file in your directory. Yes, it doesn't give you a warm fuzzy or say "Hooray!!! Your code compiled!!!", but it doesn't have to. the fact that you got back to your command prompt and there are no errors or warnings is PLENTY.
</pedant>
Gary Swann
Greenhorn

Joined: Oct 24, 2007
Posts: 11
Fred et al,

Thank you.

Hopefully I'll get a good few pages into the book before you hear from me again. I'm on page 10 of 688 (Head First Java 2005) but it looks like it's explained in a manner which even I should be able to understand.

Best regards, and thank you again for your time,

Gary

 
wood burning stoves
 
subject: Greenhorn with 64-bit can't set path
 
Similar Threads
classpath/ Assertions
2 Questions - I'm Really At A Loss!
Setting up Java on WinXP: PATH creation?
knb page# 793 doubt.
2 Questions - I'm really at a loss!