aspose file tools*
The moose likes Beginning Java and the fly likes Getting Started Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting Started" Watch "Getting Started" New topic
Author

Getting Started

Jack Ireland
Greenhorn

Joined: May 08, 2006
Posts: 5
I have done programming in java before, but took a long break. For some reason I always have trouble getting started with Java. Here is where I am:

1) I have downloaded J2EE 1.4 SDK
2) I went to control panel and under the path name it said "C:\Sun\AppServer\bin"
3) I added "c:\Program Files\Java\j2re1.4.1_02\bin"
4) My path now says "C:\Sun\AppServer\bin; c:\Program Files\Java\j2re1.4.1_02\bin"
5) I went to the comand prompt and entered in javac -verbose
6) It told me javac is not recognized

Any ideas on how to get started here?
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
JRE does not include javac! the JRE just knows how to run java programs. did you try to run "java" ? this should work.

you need the JDK to compile java files and you need to put it on the PATH. if if you are not sure if you have the JDK or not, then just search all your drives for "javac" and if you do not find anything, then you need to download it from javasoft.com


pascal
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jack Ireland:
...3) I added "c:\Program Files\Java\j2re1.4.1_02\bin"...

As pascal pointed out, the above points to a Java Runtime Environment ("JRE"). But the compiler (javac) is part of the Java Development Kit (JDK), and this is what you need to add to your PATH variable in order to compile.

If I'm not mistaken, the J2EE 1.4 download also includes the J2SE 1.5 JDK. (Note that EE is Enterprise Edition, and SE is Standard Edition.) I'm guessing that your jdk bin directory is probably at:

C:\Program Files\Java\jdk1.5.0_06\bin

(And here I also assummed Update 6. You will need to confirm this before setting the PATH.) See these Windows installation instructions for details -- in particular, step 5.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
nige llan
Greenhorn

Joined: May 08, 2006
Posts: 4
Hi,

I am also having the same problem except I have set the class path to C:\Program Files\Java\jdk1.5.0_06\bin

I have downloaded the jdk1.5.0_06 and installed it.

When I try to compile a file I get an error saying that it does not recognise javac.

Any help would be much appriciated.

Thanks
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
nige
there is difference between classpath and path:
path is where the executables (java, javac, rmic, ...= of your JDK/JRE must be located.
classpath is where your libraries, classes and resources are found.

there are lots of entries on this topic... search the forum and if this does not help, then create a new post.


pascal
Jack Ireland
Greenhorn

Joined: May 08, 2006
Posts: 5
Thanks to your help I am getting closer, but still not there. I have now:

1) Downloaded the NetBeans IDE + JDK 5.0 Update 6

2) Have this path set C:\Sun\AppServer\bin; C:\Program Files\Java\jdk1.5.0_06\bin

3) When I open the Command Prompt I can only get it to work by manually setting the path with Change Directory command "CD C:\Program Files\Java\jdk1.5.0_06\bin"

There is obviously something wrong with step #2, but I have no idea what.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jack Ireland:
...There is obviously something wrong with step #2, but I have no idea what.

When the system checks PATH, it will iterate through the options from left to right until it finds a path that will work. Is it possible that there is some interfering path value to the left of the correct one?

This is just a guess: I don't know what's in C:\Sun\AppServer\bin; but you might try moving that to the far right in your list of paths.
Peter Brockway
Greenhorn

Joined: Oct 12, 2005
Posts: 19
Originally posted by Jack Ireland:
There is obviously something wrong with step #2, but I have no idea what.
You can check your path with the commandat the command line. (There is also a stray space in the PATH as you have posted it here - I don't know if this makes a difference.)

When you say "I can only get it to work" do you mean that the javac command results in "'javac' is not recognized as an internal or external command, operable program or batch file.", or is there some other error?
[ May 08, 2006: Message edited by: Peter Brockway ]
Jack Ireland
Greenhorn

Joined: May 08, 2006
Posts: 5
Wow! I really appreciate all the help. I think part of the problem was that fact I had a space between the two paths. Now when I type javac I get the list of output that you would expect. Also when I type path can see the directory. I hate to push it, but there are still some issues.

If I get to the directory by doing the CD C:\Program Files\Java\jdk1.5.0_06\bin I can compile a Hello World program and run it with no problem. However, if I don't do the Change Directory thing it tells me "error: cannot read: hello.java" If I try to run it, it tells me "Exception in thread..."

Why would it be able to "see" the javac, but not the hello.java, which is in the same bin directory as the javac?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jack Ireland:
...If I get to the directory by doing the CD C:\Program Files\Java\jdk1.5.0_06\bin I can compile a Hello World program and run it with no problem. However, if I don't do the Change Directory thing it tells me "error: cannot read: hello.java" If I try to run it, it tells me "Exception in thread..."

Why would it be able to "see" the javac, but not the hello.java, which is in the same bin directory as the javac?

Do not place your own files in the bin directory. This directory is for binary files ("executables") that you don't want to risk messing with. Instead, create your own directory for your own files -- for example, c:\myJava.

The idea behind setting the PATH variable is that it allows you to run javac/java from any directory, without changing to (or typing the location of) that bin directory. When starting out, you typically change to a directory that contains your .java source file (for example, c:\myJava). From there, the PATH variable allows your system to find the bin directory that contains javac.

So...
  • Create your own directory c:\myJava.
  • Save your Hello.java file in that directory.
  • At the Command Prompt, change the directory to your own directory: c:\>cd c:\myJava
  • From this directory, run javac on your file (including the .java extension on your file name): c:\myJava>javac Hello.java
  • If it compiles successfully without error messages, then run (with no file extension on the class name): c:\myJava>java Hello
  • If you get error messages, please post the exact message.
    nige llan
    Greenhorn

    Joined: May 08, 2006
    Posts: 4
    Thanks for the help Pascal. I can now compile files but again like Jack I cannot run files?

    I have created a path to both the jdk and jre bin folders separated by a semicolon.

    I am not sure where to go from here? Again any help would be much appriciated!

    Thanks
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Originally posted by nige llan:
    ...I have created a path to both the jdk and jre bin folders separated by a semicolon...

    Try removing the jre bin location from your PATH. You should not need a PATH entry pointing to this. You should only need the jdk bin location.
    nige llan
    Greenhorn

    Joined: May 08, 2006
    Posts: 4
    Hi,

    I have now taken out the jre reference in the path so that now the path is only pointing to the JDK bin.

    However I am still not able to run files? I am only able to compile them?
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Originally posted by nige llan:
    ...However I am still not able to run files? I am only able to compile them?

    If you are able to compile, then you will have a file with a .class extension. Have you verified that this .class file exists?

    When you try to run, what is the exact error message you are getting when you attempt to run?

    (Note: You might want to start fresh with this Hello World tutorial that takes you through each step.)
    nige llan
    Greenhorn

    Joined: May 08, 2006
    Posts: 4
    Thank you for your help! I have it working now, the problem was that I was trying to run the wrong file
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Getting Started
     
    Similar Threads
    HF EJB compile error
    running simple servlet
    having issues with compile for AdviceBean from HF EJB
    Help
    class not found error