• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Greenhorn with 64-bit can't set path

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Gary Swann
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
lowercase baba
Posts: 13089
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 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.
 
Gary Swann
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Gary Swann
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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

 
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
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.
 
Gary Swann
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic