aspose file tools*
The moose likes Beginning Java and the fly likes Trouble compiling .class file - Tried Sun's solutions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble compiling .class file - Tried Sun Watch "Trouble compiling .class file - Tried Sun New topic
Author

Trouble compiling .class file - Tried Sun's solutions

Jessica Hope
Greenhorn

Joined: Dec 04, 2008
Posts: 8
Hi, all! I'm trying to compile from the command line for the first time. I can compile fine (ie., without an error message), but I don't see any nice HelloWorldApp.class file appearing in my directory.

I understand this is a common issue. I've read the threads here and have implemented the steps at Sun's link: http://java.sun.com/javase/6/webnotes/install/jdk/install-windows.html#Environment. Still no luck...

Any suggestions?

Thanks in advance!

Oh...

PATH is set to C:\Program Files\Java\jdk1.6.0_11\bin
CLASSPATH is set to .;

[ December 04, 2008: Message edited by: Jessica Hope ]
[ December 04, 2008: Message edited by: Jessica Hope ]
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
It sounds like you are using Windows, and you're using the command line, is that right? Not any IDE like Eclipse or IDEA or Netbeans or any of that, I mean. OK, good. You've got an unusually detailed and well-informed problem statement for someone who hasn't been able to compile and run your first Java program. You've apparently eliminated the most common problems encountered at this point, and as a result I can't easily guess what the real problem is. The good news is, your willingness to actually read the instructions and then post clear, detailed questions will prove very valuable skills to you in the long run. If we can just past this initial difficulty.

Can you tell us what prints out when you type "dir" at the command prompt? What directory are you in currently? What command are you using when you compile (or try to)? And what is the output? Please try to answer each question exactly, showing both the commands you used and the results of those commands. It's easiest if you simply copy and paste the results into your post here. Hopefully it's just a matter of selecting that area of your command-line window with a mouse, pressing control-C (copy), then going to your browser's "Post a Reply" page and pasting in the content with a control-V (paste). If that doesn't work, tell us exactly what operating system you're using (XP? Vista? ME? ), and how you're getting to the command line.
Jessica Hope
Greenhorn

Joined: Dec 04, 2008
Posts: 8
Hi, Mike! Thanks for the reply. Yes, I neglected to mention that I'm on a Windows machine running Vista. I have actually successfully written, compiled, and run Java programs with JCreator, but decided I wanted to do it from the command line instead. That's when all the trouble started!

At the command line, first I head to the directory where my HelloWorldApp.java file is. That directory is c:\PROGRA~1\Java\jk1.6.0_11. When I then do a directory listing ("dir"), here is what shows up:

12/04/2008 09:22 PM <DIR> .
12/04/2008 09:22 PM <DIR> ..
12/01/2008 11:19 PM <DIR> bin
11/10/2008 06:16 AM 3,841 COPYRIGHT
12/01/2008 11:24 PM <DIR> demo
12/02/2008 12:42 AM <DIR> docs
12/04/2008 09:22 PM 1,908 HelloWorldApp.java
12/01/2008 11:19 PM <DIR> include
12/01/2008 11:21 PM <DIR> jre
12/01/2008 11:22 PM <DIR> lib
12/01/2008 11:19 PM 17,400 LICENSE
12/01/2008 11:19 PM 17,496 LICENSE.rtf
12/01/2008 11:19 PM 29,318 README.html
12/01/2008 11:19 PM 25,828 README_ja.html
12/01/2008 11:19 PM 21,275 README_zh_CN.html
12/01/2008 11:40 PM 5,305 register.html
12/01/2008 11:40 PM 5,724 register_ja.html
12/01/2008 11:40 PM 4,902 register_zh_CN.html
12/01/2008 11:24 PM <DIR> sample
11/10/2008 06:17 AM 19,621,235 src.zip
12/01/2008 11:19 PM 231,168 THIRDPARTYLICENSEREADME.txt
12 File(s) 19,985,400 bytes
9 Dir(s) 5,020,598,272 bytes free

Next, I enter "javac HelloWorldApp.java" and hit enter. Things whirr and hum and I get no error message. Then I type the "dir" command again, and find that, alas, the HelloWorldApp.class file that I had so been hoping to see is not there. As far as I can tell, the contents of the directory are precisely the same as before the "javac" command.

Here's a transcript of the entire session:

C:\Users\Jessica>cd c:\progra~1\java\jdk1.6.0_11

c:\PROGRA~1\Java\jdk1.6.0_11>dir
Volume in drive C is SQ004286V02
Volume Serial Number is CE35-D374

Directory of c:\PROGRA~1\Java\jdk1.6.0_11

12/04/2008 09:22 PM <DIR> .
12/04/2008 09:22 PM <DIR> ..
12/01/2008 11:19 PM <DIR> bin
11/10/2008 06:16 AM 3,841 COPYRIGHT
12/01/2008 11:24 PM <DIR> demo
12/02/2008 12:42 AM <DIR> docs
12/04/2008 09:22 PM 1,908 HelloWorldApp.java
12/01/2008 11:19 PM <DIR> include
12/01/2008 11:21 PM <DIR> jre
12/01/2008 11:22 PM <DIR> lib
12/01/2008 11:19 PM 17,400 LICENSE
12/01/2008 11:19 PM 17,496 LICENSE.rtf
12/01/2008 11:19 PM 29,318 README.html
12/01/2008 11:19 PM 25,828 README_ja.html
12/01/2008 11:19 PM 21,275 README_zh_CN.html
12/01/2008 11:40 PM 5,305 register.html
12/01/2008 11:40 PM 5,724 register_ja.html
12/01/2008 11:40 PM 4,902 register_zh_CN.html
12/01/2008 11:24 PM <DIR> sample
11/10/2008 06:17 AM 19,621,235 src.zip
12/01/2008 11:19 PM 231,168 THIRDPARTYLICENSEREADME.txt
12 File(s) 19,985,400 bytes
9 Dir(s) 5,020,598,272 bytes free

c:\PROGRA~1\Java\jdk1.6.0_11>javac HelloWorldApp.java

c:\PROGRA~1\Java\jdk1.6.0_11>dir
Volume in drive C is SQ004286V02
Volume Serial Number is CE35-D374

Directory of c:\PROGRA~1\Java\jdk1.6.0_11

12/04/2008 09:22 PM <DIR> .
12/04/2008 09:22 PM <DIR> ..
12/01/2008 11:19 PM <DIR> bin
11/10/2008 06:16 AM 3,841 COPYRIGHT
12/01/2008 11:24 PM <DIR> demo
12/02/2008 12:42 AM <DIR> docs
12/04/2008 09:22 PM 1,908 HelloWorldApp.java
12/01/2008 11:19 PM <DIR> include
12/01/2008 11:21 PM <DIR> jre
12/01/2008 11:22 PM <DIR> lib
12/01/2008 11:19 PM 17,400 LICENSE
12/01/2008 11:19 PM 17,496 LICENSE.rtf
12/01/2008 11:19 PM 29,318 README.html
12/01/2008 11:19 PM 25,828 README_ja.html
12/01/2008 11:19 PM 21,275 README_zh_CN.html
12/01/2008 11:40 PM 5,305 register.html
12/01/2008 11:40 PM 5,724 register_ja.html
12/01/2008 11:40 PM 4,902 register_zh_CN.html
12/01/2008 11:24 PM <DIR> sample
11/10/2008 06:17 AM 19,621,235 src.zip
12/01/2008 11:19 PM 231,168 THIRDPARTYLICENSEREADME.txt
12 File(s) 19,985,400 bytes
9 Dir(s) 5,020,561,408 bytes free

c:\PROGRA~1\Java\jdk1.6.0_11> // Bummer... no class file!


I hope that provides you with some more detail on the problem, and I thank you very much for your help!
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

First of all: Do NOT put your .java files in the JDK-instal directory.

Second: How does your HelloWorldApp.java look like? Does it have a package-declaration as the first thing in the file? If it does, the .java file have to be in the same directory structure as the package name.

I.e. if the java file declares package se.lime.demo; you have to put the java-file in the directory <src-root>\se\lime\demo\MyJavaFile.java and compile it, standing in the <src-root> directory with javac -cp . se\lime\demo\MyJavaFile.java. That will put your .class in the same directory as the .java file.

Then you run it with java -cp . se.lime.demo.MyJavaFile, still standing in the <src-root>.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Does HelloWorldApp.java contain a line like

class HelloWorldApp { ...

If so, you might use the Windows "find" feature to find HelloWorldApp.class . If not, then there shouldn't be one anyway.


[Jess in Action][AskingGoodQuestions]
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Originally posted by Ernest Friedman-Hill:
Does HelloWorldApp.java contain a line like

class HelloWorldApp { ...

If so, you might use the Windows "find" feature to find HelloWorldApp.class . If not, then there shouldn't be one anyway.


If it didn't, you would get an "class, interface, or enum expected" error message.
Jessica Hope
Greenhorn

Joined: Dec 04, 2008
Posts: 8
Hi, all! Thanks for your input. Where would you suggest that I store my .java files? Would the C:\Program Files\Java directory be an appropriate place?

Also, the HelloWorldApp.java file comes straight from the Sun "Getting Started" tutorial.

This is the code for the file:


At this point should I move the HelloWorldApp.java file to a different directory and try compiling a .class file? That's what your post seems to suggest, but I'm a newbie, so...

Thanks again!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Originally posted by Jessica Hope:
[1] Where would you suggest that I store my .java files? Would the C:\Program Files\Java directory be an appropriate place?
[2] Should I move the HelloWorldApp.java file to a different directory and try compiling a .class file?


[1] No. Some directory in a "user" area would be better. Suggestion: open your command line, write "mkdir Java" then "cd Java". That will produce a Java folder in "Documents and Settings", but you can put it anywhere that you have access to.

[2] Yes. Now you have a Java directory, use Windows Explorer or similar to drag'n'drop your HelloWorldApp.java file there, then you should be able to open the command line and write

cd Java
javac HelloWorldApp.java
java HelloWorldApp

. . . depending on where you put your "Java" folder.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Ove Lindstr�m:

If it didn't, you would get an "class, interface, or enum expected" error message.


No, you would not, but thanks for playing!

Jessica Hope
Greenhorn

Joined: Dec 04, 2008
Posts: 8
Okay, lovely... I now have it working. Thanks, all, for your help. I plan to continue to be on the forum as I move forward in my Java journey.

I appreciate all the input greatly!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Well done
Jessica Hope
Greenhorn

Joined: Dec 04, 2008
Posts: 8
Thanks, Campbell et al.!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble compiling .class file - Tried Sun's solutions