
Here is where we left off. We created a Class (book.java) then we created a book object inside (Store.java). Then we took the Object (book1) in the Store.java file and invoked it inside the book.java file. So the Main class (book) referenced the book1 object to run the application and deliver to us the information we told it to. You guys still with me? I hope so. I am still with me but then I am the one typing.
I know this is all a fairly high overview of classes and objects. I feel though that it gives us a sample and starting point for understanding. If you plan to just type along and see it work and move to the next lesson all you will learn is how to type it out and move on. I highly recommend spending some time looking at all the codes, matching parts of the codes up and seeing how they reference each other. I provided all those links in the end of week 1 for your benefit as well as mine. Read them, bookmark them get used to going back and reading 20 pages of various explanations to help you put it all together in your style of thinking. That is the most critical part of this training. Put together how it is explained and discover how your brain functions and make it relate to you.
Moving on now, Methods. What are those? Well the answer will surprise you.
“A method is a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilizing the method’s name. Think of a method as a subprogram that acts on data and often returns a value.” Here is a simple reference to that.
Guess what? We have been using methods all along we just never put a name to it. Every time we used System.out.println we used a method. We used this method to put out a certain “text” and called or (invoked) a variable, remember this line System.out.println (“Author: ” + author); You were using methods.
Sorry to lead you guys on. Terminology is not my strong suit. I guarantee that if we had spent three paragraphs defining a method, we never would have made it this far.
We identified a class and a method without even knowing it. Now we need to take those two terms and move forward to using more methods and learn how to return a value.
The return command will, as it states, return the specified value when a method calls upon it. We are going to break this into two. Rather than paste the entire code in, I’m going to resort to screen shots with just a copy of the actual code addition. You will be able to clearly see where the code goes and what that new code is. I have chosen to do this simply because we are adding only a few lines in and working with two different Java files. It will save on space and scrolling. I hope everyone is OK with that.
Here are the two new lines we are adding to the book.java file.
public int getDimension() {
return 55;
}

Now we are going to step over to the Store.java file and add this line in:
System.out.println (“Book Size ” + book1.getDimension());

Now when we run this program our OUTPUT window will display the following:

We have successfully utilized return for the first time. What we need to do is analyze what we just did a little bit so we can gain as much understanding as we can.
We put this method in the book.java file:
public int getDimension() {
return 55;
}
We created a method of public int getDimension() { Whenever we attach this method to an object it will always return 55; If we just left it alone and didn’t do anything else the program would run but not give us a return because nothing has been associated to it yet. This is where we go to our Store.java file and insert this line System.out.println (“Book Size ” + book1.getDimension()); We are creating a method by using System.out.println. We then, as in all previous examples, told it what we wanted printed. Now we added in +book1 because that is what we named our new book in this line book book1 = new book and then the rest +book1.getDimension()); Which if you look in your book.java file is what we named the method public int getDimension() which will always return 55; When book1 is called upon or invoked.
Are we super confused yet? I hope not because it is going to only get worse from here on out. Spend some time looking the code over. Pair up the words from each side. If you pay attention as you are typing in the lines, Eclipse will always highlight and pair them visually so you can also see it. As always work in some of your own examples to help gain a better understanding and work with the code a little bit.
We will have a new lesson out shortly that will continue using the return method in another way.
Happy Coding everyone.

![[Review] Wireless Game Controller by Gamestop](http://androidspin.com/wp-content/uploads/2013/04/883386b1-150x150.jpg)




This was fun!