newbie: how to save and print objects in Java?
<p>Sorry for the newbie question, but I'm just starting with programming and this stuff is complex.</p>

<p>I have the following code excerpt that creates objects of the type Book to build my library.</p>

<pre><code> public class Library {

  public static void main(String[] args) {

   int bookID = 0;
   String title;
   String author;
   int printDate;


   Book book1 = new Book(bookID++, "Book title example", "Book author example", 1990);
   Book book2 = new Book(bookID++, "Another book title", "Another author", 1992);

   // Now lets print the available book titles in my library
   for (int i = 1; i &lt;= bookID; i++)
     System.out.println(book[i].title);

 }
}
</code></pre>

<p>This is not working, of course, but I'm not sure how to address all the objects to print them at once.</p>

<p>It seems the solution would be to send all the Book objects info to some kind of array, and then print the array contents.</p>

<p>But if I want to add new books to the library, then I have to build a new array, and this doesn't seem like the best way to do it.</p>

<p>Also, whenever the program initializes, the bookID will always be at 0.
But if there is a way to force the bookID variable to always contain the last introduced bookID, then I wouldn't have to use the bookID++ operator when setting the ID for each book. It would just read from somewhere (maybe that array that contains object info?) and add one value to the new Object.</p>

<p>Sorry, this is probably easy stuff, but I just started learning a couple of weeks ago.</p>

<p>Thanks! </p>
