• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Trouble compiling .class file - Tried Sun's solutions

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Master Rancher
Posts: 5122
82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ove Lindström
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Marshal
Posts: 80281
432
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80281
432
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done
 
Jessica Hope
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Campbell et al.!
 
Campbell Ritchie
Marshal
Posts: 80281
432
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic