Home > Store

Imagine! Java: Programming Concepts in Context

Register your product to gain access to bonus material or receive a coupon.

Imagine! Java: Programming Concepts in Context


  • Sorry, this book is no longer in print.
Not for Sale



Short, manageable segments. This textbook contains many brief chapters allowing the instructor to present topics in small segments, making the material less intimidating, flexible and easier for students to understand.

An integrated approach. Unlike other texts that address topics in a detached manner, Frank Carrano offers a high level of continuity as students move from concept to concept throughout the book. Concepts and techniques are tightly integrated so that all topics are linked in a logical, contextual way resulting in a more global understanding of the relationship and interaction between the topics.

Covers all key Java programming concepts required by the ACM. This text addresses all CS1 topics normally covered in a one to two-semester CS1 Java course with an objects-early approach (Use in Ch. 4, write in Ch. 6).

“Debugging Interludes” after every major section (7 in the book) present examples of the kind of mistakes that a novice programmer is apt to make and how to repair them.

Succinct and to-the-point. Reviewers have told us that clarity and simplicity are the book’s greatest strength because it improves learning by helping students understand and absorb the material better. The text’s chapters are less cluttered with advanced asides and distractions; students who want to use their textbook to find key information quickly and easily will appreciate that the author has omitted this extraneous material from this text.

Appropriate for CS majors at all levels. While examples are simple, concise, and complete to appeal to a multitude of students, the author also offers small, relevant tidbits that offer the more advanced student an opportunity to pursue a given topic in more detail.

Useful pedagogy. Focused and contextually accurate programming tips, self-test questions, “design decisions”, “A problem solved!”, and notes about programming conventions and style further support Carrano’s proven teaching style.

VideoNotes are step-by-step video tutorials specifically designed to enhance the programming concepts presented in Carrano, Imagine! Java: Programming Concepts in Context, 1e. Students can view the entire problem-solving process outside of the classroom–when they need help the most. VideoNotes are available with the purchase of a new copy of select titles. Go to www.pearsonhighered.com/videonotes for a brief VideoNotes demo.

Uses detailed diagrams and graphics examples  to make examples fun, relevant and appealing to visual learners.

Uses the Java standard library rather than a custom library.

Superior treatment of recursion.

A focused, methodical, carefully-laid-out presentation of Java concepts.

View an online book tour!

View Frank's recorded webinar session, “Imagine! Success in CS1/Java Programming”.

Frank’s Making it Real blog http://frank-m-carrano.com/blog/ extends his textbooks and lectures to a lively discussion with instructors and students about teaching and learning computer science. Watch a video about Imagine! Java here.


  • Copyright 2011
  • Dimensions: 8" x 10"
  • Pages: 1008
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-147106-6
  • ISBN-13: 978-0-13-147106-1

For one or two-semester  introductory CS1 Java courses taken by CS majors and non-majors.

Based on his inspiring lecture style, author Frank Carrano’s new text, Imagine! Java, engages students immediately with vivid “what if” examples and everyday analogies that keep them engaged and wanting to learn more.

Carrano starts students slowly by presenting concepts in small, manageable chunks that force students to focus on one core concept at a time. Carrano uses engaging repetitive examples to reinforce learning before moving on to more complicated concepts. This approach offers the student an opportunity to establish patterns they can use in their own programs and ultimately develop a more intuitive and sustainable understanding of the programming concepts.

Sample Content

Table of Contents


1. Introduction

 An Overview of a Computer

        What Can a Computer Do?

        The Components of a Typical Computer

A Computing System’s Software

        The Programming Language Java


Writing, Compiling, and Running a Java Program

        Tools and Resources

        The Steps

2. A First Look at Java

A Simple Java Program


        Displaying Text


Data Types

        Primitive Types

        Reference Types





        Unnamed Constants

        Named Constants

Simple Input from the Keyboard

A Problem Solved: Apples by the Box

3. Arithmetic Expressions

Arithmetic Operators

        The Addition and Subtraction Operators, + and -

        The Multiplication Operator *

        The Division Operator /

        The Remainder Operator %

        The Order of Operations

Conversions Between Numeric Data Types



A Problem Partially Solved: Day of the Week

Standard Mathematical Methods

A Problem Solved: Wind Chill

Debugging Interlude 1 : The Errors Made by Programmers

Kinds of Errors

Compile-Time Errors

Execution-Time Errors

4. Using Classes and Objects


The Class String


        Characters Within Strings

        Joining Strings

        String Methods

        Comparing Characters and Strings

        Using Scanner to Read a String

        A Problem Solved: Processing a String

        Using Scanner to Extract Pieces of a String

        Immutable Strings

The Class Date

The Class BigDecimal

        A Problem Solved: More Apples by the Box

Wrapper Classes

The Class Random

The Class DecimalFormat

The Class JOptionPane

        Using a Dialog Box to Read or Write a String

5. Basic Graphics

Creating a Window

        Getting Ready to Draw

        A Sample Drawing Panel

        Displaying a Panel

The Class Graphics

        The Coordinate System

        Drawing Lines, Shapes, and Text

        Painting Shapes

A Problem Solved: Displaying a Temperature

        The Class Font

The Class Color

A Problem Solved: The Happy Face

6. Class Definitions: The Fundamentals

A Class Definition

        Using the Class Greeter

        Beginning the Class Definition

        Defining Constructors

        Defining Other Methods

        Local Variables

Creating a New Class

        The Design

        The Implementation

Passing Arguments

A Problem Solved: Comparing Classes of Squares

Debugging Interlude 2 : Common Mistakes When Working with Classes

Working with Classes

        A Silent Computational Error

        Undefined Variables of a Class Type


        Omitting the Method toString

A Problem Solved: Extracting Strings

7. Decisions

Flow of Control

The if Statement

        Compound Statements

Basic Comparisons

        Comparing Primitives

        Comparing Objects

A Problem Solved: Day of the Week

The if-else Statement

More Boolean Expressions in Comparisons

A Problem Solved: Leap Years


8. Class Definitions: More Details

Boolean-Valued Methods

Private Methods

        Checking the Validity of Data Fields

Final Fields and Static Final Fields


A Problem Solved: Representing Coins

        A Simpler Problem: A Class of Valueless Coins

        Enhancing the Class Definition

Calling a Constructor from a Constructor

9. Classes of Graphical Objects

A Problem Solved: The Happy Face Reprised

        The Class HappyFace: First Version

        The Class HappyFace: Improved Version

A Problem Solved: The Thermometer Reprised

    The Class Thermometer

    Displaying the Thermometer

    Displaying Two Thermometers

10. Multiway Decisions

Nested if Statements

A Problem Solved: Health Club Welcome

The switch Statement

A Problem Solved: Where To?

A Problem Solved: Representing a Temperature

11. Decisions and Object Interaction when Drawing

A Problem Solved: The Thermometer Yet Again

A Problem Solved: Displaying a Random Color

A Problem Solved: Displaying a Row of Dots

A Problem Solved: Where Is the Random Point?

Debugging Interlude 3: Introduction to Testing

Avoiding Mistakes

Displaying a Calendar

A Problem Solved: The Café Sign

        Comparing Two Solutions

12. Repetition

The Logic of a Loop

The while Statement

        A Problem Solved: A Guessing Game

Errors in Loops

        Off-by-One Errors

        Infinite Loops

Boolean Variables in Loops

Nested Loops

        The Scope of a Variable

A Problem Solved: Root of an Equation

13. Repetition Continued

The for Statement

        Using an Enumeration with a for Statement

The do Statement

14. Repetition when Drawing

A Problem Solved: Displaying a Row of Dots (Reprise)

A Problem Solved: The Quahog Shell

A Problem Solved: Circles and Squares

A Problem Solved: The Quilt

A Problem Solved: A Random Walk

Debugging Interlude 4: Debugging Loops


Debugging Loops

        An Example

Overview of Debugging Tools

        The Command-Line Tool jdb (Optional)

15. Designing Classes

Design Tools

        Choosing Classes

        CRC Cards

        The Unified Modeling Language

Specifying Methods

        Abstraction and Encapsulation


        Preconditions and Postconditions

A Problem Solved: Creating a Class to Represent People

        A Class Design

        A Client for Person

        Implementation of the Class Person

Overloaded Methods

Class Relationships

        Reusing Classes

        Coupling and Cohesion

The Modifier static

        Static Fields

        Static Methods

An Enumeration as a Class

16. Object-Oriented Concepts

Java Interfaces

        Writing an Interface

        Some UML Details

        Implementing an Interface

        An Interface as a Data Type

        Casting and Interfaces

        Polymorphism and Interfaces

Inheritance Basics

        The Class Object

        Overriding the Method equals

        Polymorphism and Inheritance

        Extending an Interface

The Comparable Interface

17. Inheritance and Interfaces in Swing and the AWT

The Organization of Major Classes Within the AWT and Swing

Using Button Input

        The Class JButton

        Implementing the Interface ActionListener

        Registering an Action Listener

        Responding to a Button Click

        A Problem Solved: Smile or Frown

Using Mouse Input

        The Interface MouseListener

        A Problem Solved: Changing Color at the Click of a Mouse

        The Interface MouseMotionListener

Using Text Fields

        The Class JTextField

        A Problem Solved: Displaying RGB Colors

Debugging Interlude 5: Debugging Tools

Using Breakpoints and Watches in an IDE


        The Class Logger

        An Example

More Logging (Optional)

        Message Levels

        Other Logger Methods

        Logging Messages at Levels Lower Than INFO

A Problem Debugged: The Click Disc

18. Arrays


Array Basics

        Declaring and Creating an Array

        Declaring and Initializing an Array

        Referencing Array Elements

        Array Index Out of Bounds

Examples of Processing an Array

        Computing Deviations

        Partially Filled Arrays

        Counting Occurrences in an Array

        Finding the Smallest Entry in an Array

        Finding the Index of the Smallest Entry in an Array

        Searching an Array for a Given Entry

More Fundamentals

        Arrays of Objects

        Passing an Array to a Method

        Array Assignments

        Copying an Array

        Methods that Return an Array

        Array Equality

        Time Out

19. An Array-Based Data Structure

The Bag

        A Bag’s Behaviors

Specifying a Bag

        An Interface

Implementing and Testing a Bag

        A Group of Core Methods

        Implementing More Methods

        Methods That Remove Strings

        The Class Definition

20. Arrays Continued

More About One-Dimensional Arrays

        The For-Each Loop Applied to Arrays

        Resizing an Array

        A Problem Solved: An Expandable Bag

        An Arbitrary Number of Arguments

        The Parameter in the Method main

Multidimensional Arrays

        The Basics

        Java’s Representation

        A Problem Solved: Processing a Digital Image

        Arrays of Three or More Dimensions

        Ragged Arrays

Parallel Arrays

Debugging Interlude 6 : Debugging Arrays

An Unallocated Array

A Silent Error

        The Method toArray as a Stub

Array Index Out of Bounds

        Defining the Method toArray

Another Silent Error

        The Method remove

21. Array Lists

The List

        The Behaviors of a List

The Interface List

The Class ArrayList

        An Array List’s Size and Capacity

        Creating an Array List

        Adding Entries to a List

        Retrieving Entries

        Searching for Entries

        Replacing Entries

        Removing Entries

Arrays Versus Array Lists

22. Arrays when Drawing


        Polygon Methods in the Class Graphics

        The Class Polygon

A Class of Right Triangles

        Data Fields and Methods

        The Class Point

        Specifications for the Class RightTriangle

        Implementing RightTriangle

A Problem Solved: A New Quilt

        A Class of Squares

        A Class of Quilts

A Problem Solved: Connecting the Dots

        Using Parallel Arrays of Coordinates

        Using an Array of Points

        Using a List of Points

A Problem Solved: The Keypad

        Establishing the Design

        The Class OutputPanel

        The Class KeypadPanel

        The Class KeypadDriver

23. Sorting and Searching


        Selection Sort

        Detecting When an Array Is Sorted

        Insertion Sort

        Sorting Objects

        Sorting Methods in the Java Class Library


        A Linear Search of an Unsorted Array

        A Linear Search of a Sorted Array

        A Binary Search of a Sorted Array

        Searching Methods in the Java Class Library

The Performance of Algorithms

        The Performance of Sorting Methods

        The Performance of Searching Methods

24. Recursion

What Is Recursion?

        Example: The Countdown

        Implementation Details

Tracing a Recursive Method

Recursive Methods That Return a Value

A Problem Solved: Speaking the Digits in a Number

A Problem Solved: Writing a Number in Words

Recursion Versus Iteration

        Fibonacci Numbers: A Poor Use of Recursion

Kinds of Recursion

        Tail Recursion

        Direct, Indirect, and Mutual Recursion

25. Recursive Array Processing

Basic Techniques

Searching an Array Recursively

        A Recursive Linear Search

        Searching a Bag Recursively

        A Recursive Binary Search

A Recursive Merge Sort

        Merging Arrays

        The Merge Sort Algorithm

        A Merge Sort Method

        Merge Sort in the Java Class Library

        The Performance of Merge Sort (Optional)

Recursion Versus Iteration

        Binary Search

        Merge Sort

26. Recursive Drawings

A Problem Solved: The Target

A Problem Solved: Painting Like Mondrian

A Problem Solved: The Sierpinski Carpet

Debugging Interlude 7 : Debugging Recursive Methods

Infinite Recursion

        Carpeting Trouble: Base-Case Omission

Incorrect Results

        Sorting and Merging, Merging and Sorting

        Verbalizing Integers: Saying Too Much

27. Inheritance Continued

A Problem Solved: Designing a Hierarchy of Classes

The Basic Rules of Inheritance

        What Is Inherited?

        Constructors of the Superclass and Subclass

        Protected Access

        The Implementation So Far

        Packages and Package Access

        Type Compatibility

        Casting Object Types

Abstract Classes and Methods

        Interfaces Versus Abstract Classes

Overriding Methods, Hiding Methods

        Overriding Revisited

        Hiding Methods

Final Classes and Methods

28. Exceptions

The Basics

        Kinds of Exceptions


Handling an Exception

        Postpone Handling: The throws Clause

        Handle It Now: The try-catch Blocks

        Multiple catch Blocks

Throwing an Exception

Programmer Defined Exception Classes

        A Sample Definition

        Using Our Own Exception Class

A Problem Solved: Groups of People

Inheritance and Exceptions

The finally Block

29. Text Files


        Why Files?


        The Kinds of Files

        File Names

Creating a Text File

        Opening, Writing, and Closing a Text File

        A Class for Creating Text Files

        A Problem Solved: Creating a Text File of Colleges and Universities

Reading a Text File

        Opening, Reading, and Closing a Text File

        A Problem Solved: Displaying a List of Colleges and Universities

        Reading a Text File More Than Once

Appending Data to an Existing Text File

Changing Existing Data in a Text File


30. Sequential Binary Files

Creating a Binary File of Objects

    Opening, Writing, and Closing a Binary File

    A Class for Creating a Binary File of Objects

    A Problem Solved: Creating a Binary File of Colleges and Universities

Reading a Binary File of Objects

    Opening, Reading, and Closing a Binary File

    A Problem Solved: Displaying a List of Colleges and Universities

Arrays in Binary Files

    Writing Arrays to a Binary File

    Reading Arrays From a Binary File

Binary Files of Primitive Data

    Writing Primitive Data to a Binary File

    Reading Primitive Data From a Binary File

31. Random-Access Files

The File Pointer

Basic Operations for a Random Access File

        Opening a Random-Access File

        Writing to a Random-Access File

        Reading a Random-Access File

        Recording File-Pointer Values

A Problem Solved: A Glossary of Terms

        Creating the Glossary

        Accessing the Glossary

32. Generics and Collections


        Generic Types Within a Class Definition

        Generic Types Within an Interface

        A Problem Solved: A Bag of Objects


        Abstract Data Types

        Data Structures

        The Java Collections Framework


A. Getting Java for Free

B. Reserved Words

C. Unicode Characters

D. Documentation and Programming Style

Naming Variables and Classes



    Single-Line Comments

    Comment Blocks

    When to Write Comments

    Java Documentation Comments

    Running javadoc

E. Cloning

Cloning an Object

Cloning an Array





Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership