This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Head First Design Patterns - Can't run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Design Patterns - Can Watch "Head First Design Patterns - Can New topic
Author

Head First Design Patterns - Can't run

Martin Hart
Greenhorn

Joined: Feb 12, 2005
Posts: 6
Hi all:

I'm *so* new to Java that I'm almost ashamed to post me question ;-)

I have a PC with WinXP - SP2 and Java runtime and Java SDK 1.5 installed. I also have Borland's JBuilder 2005 Foundry Version installed.

I wish the run the sample code from the Head First Design Patterns book, but can't get it to run. I hve also downloaded the execution bath file, still no luck.

Boy, I'm slow today!!

The error I'm getting is:
Exception in thread "main" java.lang.NoClassDefFoundError: headfirst/strategy/MiniDuckSimulator

and the command line is:
java -cp ./classes headfirst.strategy.MiniDuckSimulator

Please help!!


---<br />Regards,<br />Martin
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The -CP tells the java command where to start looking for classes. The package path on the classname has to match the directory structure from that point. Check and see if your directories look like this:

If that's all correct, we'll try to figure out what to check next.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Why would you be ashamed when you're new? Now, had you been coding Java for five years, maybe that feeling would be justified (though I still feel it never is ... I'm just making a point). And please, no one wants to read anyone disparaging themselves. We're all friends here!Isn't Windows just wonderful?! The problem is that you're using a Unix path separator. Try this:or simply remove the ".\" altogether.
Martin Hart
Greenhorn

Joined: Feb 12, 2005
Posts: 6
Originally posted by Stan James:
The -CP tells the java command where to start looking for classes. The package path on the classname has to match the directory structure from that point. Check and see if your directories look like this:

If that's all correct, we'll try to figure out what to check next.


Stan:

Maybe I need some more basic Java help, let me explain.

I've been a C,C++, Pascal and C# programmer for more than 20 years, so my OS skills and general programming skills should be okay (I think!), but Java is new and that's where I'm having trouble.

I'm not too sure what I should be executing. Is it a .java file on the hard disk or a .java file inside a .jar file. The structure inside the hfdp.jar is root|src|headfirst|??? where ??? are actual direcories containg the java code. I have extracted the contents of the jar file to harddisk starting at d:\hfdp and then src, headfirst etc.

I have replaced the ./ with .\ for my Windows installation.

Finally the file MiniDuckSimulator.class does not exist, just the MiniDuckSimulator.java file, this seems to me to be a critial issue, but I don't know how to generate the .class file.

Regards,
Martin.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
ah, you need to compile the thing first.
Like C and C++ Java is a compiled language. The downloadable stuff for the book contains only the source files.

go to the classes directory and type to compile the application class and everything it needs (that's not compiled already). The compiler will figure out the dependencies for you.
You can compile from elsewhere using the appropriate compiler options, running javac without any parameters will give you a list (or use the documentation for the JDK).


42
Martin Hart
Greenhorn

Joined: Feb 12, 2005
Posts: 6
go to the classes directory


What do you mean by 'classes directory'?

and type to compile the application class and everything it needs (that's not compiled already). The compiler will figure out the dependencies for you.


I have tried this but it doesn't seem to see the 'included' java files.

The source file has 'package headfirst.strategy;' on the first line, what is this doing?

TIA,
Martin.
Subhash Bhushan C
Ranch Hand

Joined: Jan 27, 2005
Posts: 106
IMHO...

1. Its not a good idea to start java with "Head First Design Patterns". Maybe you should get "Head First Java" first or "Just Java", get some experience with the concepts of Java programming and then leap on the design pattern bandwagon. You can buy the book at the following links:
--> Head First Java
--> Just Java 2

2. Or.. you could start your journey in Java Programming by the Sun recommended tutorial . Find the link to the basic tutorial here.
First Cup of Java


Regards,<br />Subhash Bhushan.
Martin Hart
Greenhorn

Joined: Feb 12, 2005
Posts: 6
Originally posted by Agni Vartula:
IMHO...

1. Its not a good idea to start java with "Head First Design Patterns". Maybe you should get "Head First Java" first or "Just Java", get some experience with the concepts of Java programming and then leap on the design pattern bandwagon. You can buy the book at the following links:
--> Head First Java
--> Just Java 2


Agni:

I bought the Design Patterns book not knowing it's examples were in Java (I'm a C++ and C# programmer with more than 20 years software development experience) and have found the book a 100% winner.

I'm just interested in running the examples, but... now it seems like I'm getting hooked on Java :-) I've already ordered the Head First Java book (hasn't arrived yet), but the question still stands: How do I run the sample code?

Regards,
Martin.
Subhash Bhushan C
Ranch Hand

Joined: Jan 27, 2005
Posts: 106
Martin,
Apart from writing a source file in Java, its important that you set some PATH and CLASSPATH variables appropriately, for your program to compile and run.

The link that I provided earlier, to "First Cup of Java" has these instructions. Please take the time and trouble to go through it, because even if I am able to explain everything, I will not be able to do it better than them.

Here are the defined links:

Windows Installation instructions

Your first java program... How to code, compile and run
Martin Hart
Greenhorn

Joined: Feb 12, 2005
Posts: 6
Agni:

Thanks for your time. I have printed the pages you indicated and will study them later today.

I'm sure this will anwser my questions,

Regards,
Martin.
Martin Hart
Greenhorn

Joined: Feb 12, 2005
Posts: 6
Okay, all done and dusted :-))

I followed the links Agni suggested and also got myself the eclipse.org IDE and its all up and running.

Thanks to all who contributed.

Regards,
Martin.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Design Patterns - Can't run
 
Similar Threads
oo concepts book
Design Patterm Doubt
self taught
Coolest Java books
Design Pattern Best Book