| Author |
New to Java
|
Benjamin Watson
Greenhorn
Joined: May 12, 2011
Posts: 2
|
|
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
}
^
1 Error
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...
|
 |
jishnu dasgupta
Ranch Hand
Joined: Mar 11, 2011
Posts: 103
|
|
Hey Benjamin,
Welcome to the Ranch. !!!
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
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 10040
|
|
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.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Benjamin Watson
Greenhorn
Joined: May 12, 2011
Posts: 2
|
|
|
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.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
Benjamin Watson wrote: . . . . tell me how the JVM finds the correct classes to run?
It uses import statements and the -cp option when you use the javac and java tools.
Maybe I'm worrying about things I shouldn't, . . .
Yes, you are. Fred is correct; leave that until you create applications with lots of classes.
|
 |
 |
|
|
subject: New to Java
|
|
|