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.
Java is an Object Oriented language. That means you create objects that represent things. In this case, someone, somewhere has written a Robot class. There is probably a Robot.java file you can look at.
Calling the constructor creates an instance of the Robot. It's like telling a construction company to "Use this blueprint to go build a house". The values passed in to the constructor are like passing in the colors you want the bedroom painted.
Back to your example, once that constructor returns, you can now call the methods defined in the Robot class by saying
You could create many robot instances, and have each do their own thing:
and each robot would do its own thing.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Feb 01, 2008
these are the methods of the class( sorry the signatures twisted)
i undrerstand your example in which we get an object from which we could
use its method
are the arguments for a constructor of class Robot. We can't tell you what these values mean; you'd have to look at the class Robot to understand that. These values don't have anything to do with the methods in class Robot.
Look at a simple object, like a Boolean. To create one, you call (one of) its constructor, and pass in a value:
Boolean myBool = new Boolean("true") ;
In this case, I used the constructor that takes a String. Nowhere in the class does it actually STORE that string, it simply uses it to figure out how to create itself. That's not to say that such params passed to a constructor are NEVER saved - in fact, Jesper shows an example where they are.
The point is, you don't always know, and often don't need to know. That's kind of the point of OO programming - the details are hidden from people who don't need to know them.
Having said that, I would say that if nobody tells you what the values you are passing in are used for in some broad sense, then there is a documentation issue. They could be the starting position on a grid, whether or not it is holding a beeper, and what direction it is facing, for example. Or they could be something else entirely. We can't know without seeing the code or the specs.