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 Head First and I Can't make a .class file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First and I Can Watch "Head First and I Can New topic
Author

Head First and I Can't make a .class file?

Dawn Tal
Greenhorn

Joined: Aug 15, 2003
Posts: 5
Hi:
Just bought Head First Java and a new Dell Infinion running XP home edition v5.1 service Pack1. I downloaded the J2SDK1.4.2 and installed it (and downloaded the documentation files as recommended). I think I unzipped the source file - but I'm not sure. All the files look like they are in the right place...c:\j2sdk1.4.2\bin\javac etc. Now when I try the test docs I get cannot read HelloWorld.java. I can create the file, save the file but cannot compile to create a .class file. I corrected the Path but left the default CLASSPATH of "C\QTJava.zip". My "Run" line still can't find the javac. (The "HelloWorldApp.java" extention is correctly saved). Lastly these DOS windows open and close so fast I have a hard time reading the error message. When I use the full path in the command line I get a cannot read java.exe?
This book is so cool - I want to get going but I'm stuck on the first step!!
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

Hello, Dawn, and welcome to JavaRanch!
I suggest opening a DOS prompt and running java from the command line; forget the "Run" dialog. That way, whenever you get an error, the message will still be around for you to read.
Secondly, if you ran the SDK installer from Sun, it should have adjusted the PATH for you. Open a DOS prompt and type javac -help and see if you get a response.
Next, you should adjust your CLASSPATH to represent where your java files are. For example, my java and class files are in (among other places) C:\user\java\sources. As such, C:\user\java\sources is listed in my CLASSPATH variable. Just for convenience, I also have the curent directory (".") in the CLASSPATH.
If you double check all this and still can't get it to work, paste the error message here and we'll try to help you further.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Dawn Tal
Greenhorn

Joined: Aug 15, 2003
Posts: 5
Thanks I'll get to work!
Dawn Tal
Greenhorn

Joined: Aug 15, 2003
Posts: 5
OK The good news is I got .class file to generate!! Thank You.
The bad news is - it's still generating errors...
My CLASSPATH = c:\j2sdk1.4.2\bin\
My Path = %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program Files\Common Files\Adaptec Shared\System;C:\j2sdk1.4.1.2\bin
Here is the error message.
C:\Java>java HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
I copied the whole file in case I didn't catch the real error message.
---------------------------------------
C:\Documents and Settings\Dawn>cd c:\java
C:\Java>dir
Volume in drive C has no label.
Volume Serial Number is 20D1-F4F4
Directory of C:\Java
08/15/2003 03:18 PM <DIR> .
08/15/2003 03:18 PM <DIR> ..
08/15/2003 03:18 PM 186 HelloWorld.html
08/15/2003 03:17 PM 319 HelloWorld.java
08/15/2003 03:10 PM 290 HelloWorldApp.java
3 File(s) 795 bytes
2 Dir(s) 31,753,252,864 bytes free
C:\Java>javac HelloWorldApp.java
'javac' is not recognized as an internal or external command,
operable program or batch file.
C:\Java>c:\j2sdk1.4.2\bin\javac HelloWorldApp.java
C:\Java>dir
Volume in drive C has no label.
Volume Serial Number is 20D1-F4F4
Directory of C:\Java
08/15/2003 07:03 PM <DIR> .
08/15/2003 07:03 PM <DIR> ..
08/15/2003 03:18 PM 186 HelloWorld.html
08/15/2003 03:17 PM 319 HelloWorld.java
08/15/2003 07:03 PM 432 HelloWorldApp.class
08/15/2003 03:10 PM 290 HelloWorldApp.java
4 File(s) 1,227 bytes
2 Dir(s) 31,753,187,328 bytes free
C:\Java>java HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
C:\Java>
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

Your classpath should include either "C:\Java" or "." Since the HelloWorldApp.class file is not in C:\j2sdk1.4.2\bin, the java program cannot find it.
Incidentily, the CLASSPATH does not need to include c:\j2sdk1.4.2\bin\, since (most people) don't put their classfiles there.
Also, if you change your PATH to include c:\j2sdk1.4.2\bin\
(instead of c:\j2sdk1.4.1.2\bin\), it should find the javac command.
Dawn Tal
Greenhorn

Joined: Aug 15, 2003
Posts: 5
I found the typo - dumb. Classpath all set. I've just run my first program!! Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First and I Can't make a .class file?