Book Image

Java Programming for Beginners

By : Mark Lassoff
Book Image

Java Programming for Beginners

By: Mark Lassoff

Overview of this book

Java is an object-oriented programming language, and is one of the most widely accepted languages because of its design and programming features, particularly in its promise that you can write a program once and run it anywhere. Java Programming for Beginners is an excellent introduction to the world of Java programming, taking you through the basics of Java syntax and the complexities of object-oriented programming. You'll gain a full understanding of Java SE programming and will be able to write Java programs with graphical user interfaces that run on PC, Mac, or Linux machines. This book is full of informative and entertaining content, challenging exercises, and dozens of code examples you can run and learn from. By reading this book, you’ll move from understanding the data types in Java, through loops and conditionals, and on to functions, classes, and file handling. The book finishes with a look at GUI development and training on how to work with XML. The book takes an efficient route through the Java landscape, covering all of the core topics that a Java developer needs. Whether you’re an absolute beginner to programming, or a seasoned programmer approaching an object-oriented language for the first time, Java Programming for Beginners delivers the focused training you need to become a Java developer.
Table of Contents (12 chapters)


In this section, we'll take a quick look at an important idea that relates to inheritance in Java. To wrap our heads around what we're going to talk about, I think it's best if we start an existing project in the system. So let's take a look at the code we have in the code files.

So far, we've done the following:

  • The main method of our program creates a list of objects. These objects are either of the type Book or Poem, but we've placed them in a list of Literature objects, leading us to believe that the Book and Poem classes must inherit from or extend the Literature class.
  • Once we've built this array, we simply iterate through it using a for loop and call the Print method of this for loop on each object.
  • At this point, we're dealing with objects as Literature objects, not the Books or Poems that they are at the lowest level....