Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New to Java

 
Benjamin Watson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12123
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Benjamin Watson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic