Learning Java Through Games teaches students how to use the different features of the Java language as well as how to program. Suitable for self-study or as part of a two-course introduction to programming, the book covers as much material as possible from the latest Java standard while requiring no previous programming experience.
Taking an application-motivated approach, the text presents an abundance of games. Students must read through the whole chapter to understand all the features that are needed to implement the game. Most chapters start with a description of a game and then introduce different Java constructs for implementing the features of the game on need-to-use bases.
The text teaches students not only how to write code that works but also how to follow good software practices. All sample programs in the text strive to achieve low cohesion and high coupling—the hallmarks of well-designed code. Many programs are refactored multiple times to achieve code that is easy to understand, reuse, and maintain.
The first part of the book covers basic programming techniques, such as conditional statements, loops, methods, arrays, and classes. The second part focuses on more advanced topics, including class inheritance, recursions, sorting algorithms, GUI programming, exception handling, files, and applets.
Basic Principles
Computer Hardware and Software
Brief History of Computers
Hardware Components of a Computer
Binary Representation of Numbers
Software Creation and Types of Software
Type of Programming Languages
Brief History of Computer Games
Data Types and Conditional Statements
Our First Java Program
Variables
Random Numbers and the if Statement
Combining Conditions
The String Class
The switch Statement
The Conditional Operator
Loops
The while Statement
The do-while Construct
The for Loop
Nested for Loops
The Modulus Operation
Methods and Formatted Output
Introduction to Methods
Formatting Output
Code Refactoring
Documenting Methods Using JavaDoc
Sending Data between Methods
The Trading Game
Introduction to Arrays
One-Dimensional Arrays
The Trading Game Revisited
Two-Dimensional Arrays
Variable Argument Methods
Command Line Arguments
Introduction to Classes
Classes and Objects
Class Interaction and Data Encapsulation
Default Constructor
The toString Method
Instance versus Static
Non-Empty Constructors and the Hidden Parameter this
Array of Objects and Multi-Class Solutions
Multi-Class Solution to the Battleship Game
The ArrayList Class and the enum Keyword
Introduction to the ArrayList Class
Immutable Objects
The StringBuffer Class
The Interface of an ArrayList
Introducing the enum Construct
Advanced Programming Techniques
Classes Revisited
Class Containment
Inheritance and the super Keyword
Multiple Inheritance
Constructors of Subclasses
Abstract Classes and Methods
Auto-Casting, Polymorphism, and Dynamic Binding
Interfaces and the Comparable Interface
Access Privileges
The final Keyword
Static Methods and Polymorphism
Explicit Type Checking
Cloning Objects
Comparing Objects for Equality
Fun with Swing
Introduction to Swing
Creating Windows
Panels and Drawing
Nested Classes and Event Handling
The Timer Class
Nested Classes
Event Listeners
Multicasting
The Breakout Game (Complete Version)
Overview of the Game
Game Design
Moving the Ball
Adding the Paddle
Drawing the Stickmen
Adding the Menus
Adding the Bricks
Layout Management and GUI Components
Creating Buttons
Flow Layout
Border Layout
Text Fields and Labels
Grid Layout
Creating Text Areas with Scroll Bars
The Combo Box
Check Boxes
Radio Buttons
Document Listeners
Creating Dialog Boxes
Working with Password Fields
Exception Handling and Files
Handling Exceptions
Text Files
Data Files
Recursion
Base Case and General Case
Dynamic Programming
Internal Details of a Recursive Call
Array Algorithms
Java Applets
HTML and the Java Applet Architecture
Principles of Java Applets
Creating Popup Windows
The Tic-Tac-Toe Game
Index
A Summary, Syntax, Important Points, Exercises, Labs, and Projects appear at the end of each chapter.
Biography
Lubomir Stanchev is an associate professor in the Department of Computer Science at Indiana University-Purdue University Fort Wayne. He received a Ph.D. from the David R. Cheriton School of Computer Science at the University of Waterloo. He has taught introductory programming courses and software engineering courses about 15 times in the past eight years. He has published more than five journal articles and more than 20 conference proceedings in the area of computer science. He has been writing software code for over 30 years and has worked as a software developer in four different companies.