File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Reading in Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading in Objects" Watch "Reading in Objects" New topic

Reading in Objects

Johnny Donovan

Joined: Mar 23, 2011
Posts: 6

Hi Guys,

So im a little confused.

Say i have 2 Objects - An author object and a book object. Now i have a created class which implements a class which contains all the methods needed to get information for the objects ex. getAuthorName, getAuthorDOB, getBookName, getBookReleaseDate.

Now the book object also contains an authour object .

How would i get all the books written by a specific author using this method?

Sorry i am trying to learn Java in my spare time but i am very confused.

Thanks you
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

In pseudo-code:

public List<Book> getBooksByAuthor(Author anAuthor) {
List<Book> booksOfAuthor ...
loopAllBooks {
if the author of the book is the same as anAuthor
add to booksOfAuthor

return booksofAuthor;

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Johnny Donovan

Joined: Mar 23, 2011
Posts: 6

Thank you so much for replying.

My only problem now is how do i get the Books object?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43394
You would have to put all your book objects into a List<Book> or a Book[] array when you create them. Then they are available for you to go through and look for the author.
Johnny Donovan

Joined: Mar 23, 2011
Posts: 6

So i could say :

subject: Reading in Objects
jQuery in Action, 3rd edition