Skip to main content
main-content
Top

About this book

This book presents a focused and accessible primer on the fundamentals of Java programming, with extensive use of examples and hands-on exercises. Topics and features: provides an introduction to variables, input/output and arithmetic operations; describes objects and contour diagrams, explains selection structures, and demonstrates how iteration structures work; discusses object-oriented concepts such as overloading and classes methods, and introduces string variables and processing; illustrates arrays and array processing and examines recursion; explores inheritance and polymorphism and investigates elementary files; presents a primer on graphical input/output, discusses elementary exception processing, and presents the basics of Javadoc; includes exercises at the end of each chapter, with selected answers in an appendix and a glossary of key terms; provides additional supplementary information at an associated website.

Table of Contents

1. Variables, Input/Output, and Arithmetic

In addition to an introduction to hardware and software concepts, including the concept of compiling, interpreting, and executing a program, this chapter provides an initial skeleton program from which to create subsequent programs. An introduction to variables, constants, assignment statements, arithmetic operations, and simple input/output using the keyboard and monitor is also provided. Further, there is a discussion concerning errors, comments, and program design. A simple complete program is included at the end of the chapter.
James T. Streib, Takako Soma

2. Objects: An Introduction

This chapter introduces classes and objects. Public and private data members along with value-returning methods and void methods with parameters are discussed. How objects are created and how methods are invoked are illustrated using contour diagrams. Contours help the reader have a better understanding of object-oriented concepts by providing visual representation of objects. Constructors are introduced along with multiple objects and classes. Lastly, UML (Universal Modeling Language) class diagrams are illustrated and a complete program implementing a simple class and client program is provided.
James T. Streib, Takako Soma

3. Selection Structures

Selection structures are explained in this chapter using flowcharts, pseudocode, and the corresponding Java code. The if-then, if-then-else, and nested if structures, including if-then-else-if and if-then-if structures, are introduced. The dangling-else problem is also discussed. Logical operators are presented followed by the introduction of the case structure. Two complete programs are provided: one with objects and one without.
James T. Streib, Takako Soma

4. Iteration Structures

This chapter shows how iterations structures work using flowcharts, pseudocode and Java. It includes pretest indefinite loop structures, both count and sentinel controlled while loops. The posttest indefinite do-while loop and the definite iteration for loop are also discussed. Nested loops and potential problems are examined, and complete programs both with and without objects are included.
James T. Streib, Takako Soma

5. Objects: Revisited

Objects are revisited in this chapter. The sending and returning an object to and from a method is illustrated using contours. Overloaded constructors and methods are discussed and the reserved word this is introduced. Local, instance, and class constants and variables along with class methods are shown using contour diagrams. Two complete programs, one with focus on overloaded methods and another with class data members and methods are included.
James T. Streib, Takako Soma

6. Strings

This chapter discusses string variables and the String class. In addition to the concatenation of strings, various methods defined in the String class such as the length, indexOf, and substring methods are examined. The toString method which returns a string representation of the properties of an object is also shown along with a complete program implementing String objects.
James T. Streib, Takako Soma

7. Arrays

Arrays and array processing are illustrated in the chapter starting with declaration, access, input and output. In addition to simple processing, the passing of an array to and from a method is demonstrated. Other processing includes reversing, searching (sequential and binary), and sorting an array using the bubble sort. Also, two-dimensional arrays and arrays of objects are introduced, along with a complete program.
James T. Streib, Takako Soma

8. Recursion

This chapter examines recursion using contour diagrams. The power function and Fibonacci numbers are used as examples. In addition to contour diagrams, stack frames and a tree of calls are shown as alternative ways of visualizing the recursive process. As with other chapters, a complete program is provided.
James T. Streib, Takako Soma

9. Objects: Inheritance and Polymorphism

This chapter returns to objects and explores the concepts of inheritance. Contours are used to explain how a subclass is extended and inherits data members and methods from a superclass. Further, protected variables and methods along with abstract classes are discussed. Another object-oriented programming concept, polymorphism, which is a useful tool for developing software, is introduced. A complete program implementing inheritance and polymorphism is included.
James T. Streib, Takako Soma

10. Elementary File Input and Output

This chapter discusses elementary file, including how to obtain data from a file and how to save output to a file. It also discusses how the file location is specified. Two complete programs, one performing matrix multiplication using a data stored in a file, and another sorting string data from a file, are included.
James T. Streib, Takako Soma
Additional information