This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, this is probably a really stupid question. I am learning java and it's my first time in an OO environment. Trying to write my first multi-class routine and I am having difficulties making the non-main class. This is taken from the head first java book.
My Dog.java file reads:
When I compile I get:
Dog.java:9: Missing return statement
I'm usually pretty good at debugging code, at least in non-OO like C, but I can't seem to figure this one out.
Also, correct me if I'm wrong, but my understanding is that when I'm done I'm going to have several .class files and I'll run the one with main. Can anyone tell me how the JVM finds the correct classes to run? Maybe I'm worrying about things I shouldn't, but it feels weird trusting it to just find the correct file when it's supposed to...
As for your question, you have the method definition as
but instead it should be
just remember that java is one o those lamguage in which case-sensitivity is really really important !!!, so whem you mentioned Void it just though it was a particluar object type which was to be returned by the method!!
As for the classes need to be run, it just looks in the current directory or the one specified by you in your classpath to look for the class files to be loaded as and when required by your program.
o an one more advice..use codeTags from now on while posting your code
If debugging is the process of removing bugs, then programming must be the process of putting them in. -- Edsger Dijkstra
I edited your post to used code tags. it makes it a little easier to read your java source. Just click the button labeled "code" when making your post, and paste your source between them.
In answer to the first part, Java is case sensitive. "Void" is NOT the same thing as "void". so, it is expecting your method to return an object of type "Void".
as to the second part of your question...you are right, up to a point. For simple stuff, the JVM usually knows to look in the current directory. Once you get a little more advance, you will learn how to tell it where to search for all the class files it needs - but don't worry about it for now.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: May 12, 2011
I'd like to say this is the first time CaSe-SenSitiviTy has been the issue in my java sources, but that would be bold faced lie. Thanks a ton for the help, and for the information about java and it's .class files.