Product Cover Image

Agile Java™: Crafting Code with Test-Driven Development

By Jeff Langr

Published by Prentice Hall

Published Date: Feb 14, 2005

Description

Master Java 5.0 and TDD Together: Build More Robust, Professional Software

Master Java 5.0, object-oriented design, and Test-Driven Development (TDD) by learning them together. Agile Java weaves all three into a single coherent approach to building professional, robust software systems. Jeff Langr shows exactly how Java and TDD integrate throughout the entire development lifecycle, helping you leverage today's fastest, most efficient development techniques from the very outset.

Langr writes for every programmer, even those with little or no experience with Java, object-oriented development, or agile methods. He shows how to translate oral requirements into practical tests, and then how to use those tests to create reliable, high-performance Java code that solves real problems. Agile Java doesn't just teach the core features of the Java language: it presents coded test examples for each of them. This TDD-centered approach doesn't just lead to better code: it provides powerful feedback that will help you learn Java far more rapidly. The use of TDD as a learning mechanism is a landmark departure from conventional teaching techniques.

  • Presents an expert overview of TDD and agile programming techniques from the Java developer's perspective

  • Brings together practical best practices for Java, TDD, and OO design

  • Walks through setting up Java 5.0 and writing your first program

  • Covers all the basics, including strings, packages, and more

  • Simplifies object-oriented concepts, including classes, interfaces, polymorphism, and inheritance

  • Contains detailed chapters on exceptions and logging, math, I/O, reflection, multithreading, and Swing

  • Offers seamlessly-integrated explanations of Java 5.0's key innovations, from generics to annotations

  • Shows how TDD impacts system design, and vice versa

  • Complements any agile or traditional methodology, including Extreme Programming (XP)


© Copyright Pearson Education. All rights reserved.

Table of Contents

About the Author.

Foreword.

Acknowledgments.

Introduction.

    Who Is This Book For?

    What This Book Is Not

    How to Use This Book

    Exercises

    Conventions Used in This Book

An Agile Overview.

    What Is “Agile?”

    What Is Java?

    Why OO?

    What Is an Object?

    What Are Classes?

    Why UML?

    What Is Inheritance?

    Why Test-Driven Development?

Setting Up.

    Software You’ll Need

    Does It Work?

    Compiling Hello World

    Executing Hello World

    Still Stuck?

Lesson 1: Getting Started.

    Testing

    Design

    A Simple Test

    JUnit

    Adding a Test

    Creating a Student

    Creating the Student Class

    Constructors

    Local Variables

    Returning a Value from a Method

    Assertions

    Instance Variables

    Summarizing the Test

    Refactoring

    this

    private

    Naming Conventions

    Whitespace

    Exercises

Lesson 2: Java Basics.

    CourseSession

    Enrolling Students

    int

    Initialization

    Default Constructors

    Suites

    The SDK and java.util.ArrayList

    Adding Objects

    Incremental Refactoring

    Objects in Memory

    Packages and the import Statement

    The java.lang Package

    The Default Package and the package Statement

    The setup Method

    More Refactoring

    Class Constants

    Dates

    Overload Constructors

    Deprecation Warnings

    Refactoring

    Creating Dates with Calendar

    Comments

    Javadoc Comments

    Exercises

Lesson 3: Strings and Packages.

    Characters and Strings

    Strings

    StringBuilder

    System Properties

    Looping Through All Students

    Single-Responsibility Principle

    Refactoring

    System.out

    Using System.out

    Refactoring

    Package Structure

    Access Modifiers

    Using Ant

    Exercises

Lesson 4: Class Methods and Fields.

    Class Methods

    Class Variables

    Operating on Class Variables with Class Methods

    Static Import

    Incrementing

    Factory Methods

    Simple Design

    Static Dangers

    Using Statics: Various Notes

    Jeff’s Rule of Statics

    Booleans

    Tests as Documentation

    More on Initialization

    Exceptions

    Revisiting Primitive-Type Field Initialization

    Exercises

Lesson 5: Interfaces and Polymorphism.

    Sorting: Preparation

    Sorting: Collections.sort

    CourseReportTest

    Interfaces

    Why Interfaces

    Implementing Comparable

    Sorting on Department and Number

    The if Statement

    Grading Students

    Floating-Point Numbers

    Testing Grades

    Refactoring

    Enums

    Polymorphism

    Using Interface References

    ArrayList and the List Interface

    Exercises

Lesson 6: Inheritance.

    The switch Statement

    Case Labels Are Just Labels

    Maps

    Inheritance

    Abstract Classes

    Extending Methods

    Refactoring

    Enhancing the Grade Enum

    Summer Course Sessions

    Calling Superclass Constructors

    Refactoring

    More on Constructors

    Inheritance and Polymorphism

    The Principle of Subcontracting

    Exercises

Lesson 7: Legacy Elements.

    Looping Constructs

    Breaking Up a Student’s Name

    The while Loop

    Comparing Java Loops

    Refactoring

    Looping Control Statements

    The Ternary Operator

    Legacy Collections

    Iterators

    Iterators and the for-each Loop

    Casting

    Wrapper Classes

    Arrays

    Refactoring

    Exercises

Lesson 8: Exceptions and Logging.

    Exceptions

    Dealing With Exceptions

    Checked Exceptions

    Exception Hierarchy

    Creating Your Own Exception Type

    Checked Exceptions vs. Unchecked Exceptions

    Messages

    Catching Multiple Exceptions

    Rethrowing Exceptions

    Stack Traces

    The finally Block

    Refactoring

    Logging

    Logging in Java

    Testing Logging

    Logging to Files

    Testing Philosophy for Logging

    More on FileHandler

    Logging Levels

    Logging Hierarchies

    Additional Notes on Logging

    Exercises

Lesson 9: Maps and Equality.

    Logical Operators

    Short-Circuiting

    Hash Tables

    Courses

    Refactoring Session

    Equality

    The Contract for Equality

    Apples and Oranges

    Collections and Equality

    Hash Tables

    Collisions

    An Ideal Hash Algorithm

    A Final Note on hashCode

    More on Using HashMaps

    Additional Hash Tables and Set Implementations

    toString

    Strings and Equality

    Exercises

Lesson 10: Mathematics.

    BigDecimal

    More on Primitive Numerics

    Integer Math

    Numeric Casting

    Expression Evaluation Order

    NaN

    Infinity

    Numeric Overflow

    Bit Manipulation

    Java.lang.Math

    Numeric Wrapper Classes

    Random Numbers

    Exercises

Lesson 11: IO.

    Organization

    Character Streams

    Writing to a File

    Java.io.File

    Byte Streams and Conversion

    A Student User Interface

    Testing the Application

    Data Streams

    CourseCatalog

    Advanced Streams

    Object Streams

    Random Access Files

    The Student Directory

    sis.db.DataFileTest

    Static Nested Classes and Inner Classes

    sis.db.DataFile

    sis.db.KeyFileTest

    sis.db.KeyFile

    sis.util.IOUtilTest

    sis.util.IOUtil

    sis.util.TestUtil

    Developing the Solution

    Exercises

Lesson 12: Reflection and Other Advanced Topics.

    Mock Objects Revisited

    The Jim Bob ACH Interface

    The Mock Class

    The Account Class Implementation

    Anonymous Inner Classes

    Adapters

    Accessing Variables from the Enclosing Class

    Tradeoffs

    Reflection

    Using JUnit Code

    The Class Class

    Building the Suite

    Class Modifiers

    Dynamic Proxy

    A Secure Account Class

    Building the Secure Account Solution

    The SecureProxy Class

    Problems With Reflection

    Exercises

Lesson 13: Mulithreading.

    Multithreading

    Search Server

    The Search Class

    Less Dependent Testing

    The Server

    Waiting in the Test

    Creating and Running Threads

    Cooperative and Preemptive Multitasking

    Synchronization

    Creating Threads with Runnable

    Synchronized

    Synchronized Collections

    BlockingQueue

    Stopping Threads

    Wait/Notify

    Additional Notes on wait and notify

    Locks and Conditions

    Thread Priorities

    Deadlocks

    ThreadLocal

    The Timer Class

    Thread Miscellany

    Summary: Basic Design Principles for Synchronization

    Exercises

Lesson 14: Generics.

    Parameterized Types

    Collection Framework

    Multiple Type Parameters

    Creating Parameterized Types

    Erasure

    Upper Bounds

    Wildcards

    Implications of Using Wildcards

    Generic Methods

    Wildcard Capture

    Super

    Additional Bounds

    Raw Types

    Checked Collections

    Arrays

    Additional Limitations

    Reflection

    Final Notes

    Exercises

Lesson 15: Assertions and Annotations.

    Assertions

    The assert Statement vs. JUnit Assert Methods

    Annotations

    Building a Testing Tool

    TestRunnerTest

    TestRunner

    The @TestMethod Annotation

    Retention

    Annotation Targets

    Skipping Test Methods

    Modifying TestRunner

    Single-Value Annotations

    A TestRunner User Interface Class

    Array Parameters

    Multiple Parameter Annotations

    Default Values

    Additional Return Types and Complex Annotation Types

    Package Annotations

    Compatibility Considerations

    Additional Notes on Annotations

    Summary

    Exercises

Additional Lesson I: Swing, Part 1.

    Swing

    Getting Started

    Swing Application Design

    Panels

    Refactoring

    More Widgets

    Refactoring

    Button Clicks and ActionListeners

    List Models

    The Application

    Layout

    GridBagLayout

    Moving Forward

Additional Lesson II: Swing, Part 2.

    Miscellaneous Aesthetics

    Feel

    Tables

    Feedback

    Responsiveness

    Remaining Tasks

    Final Notes

Additional Lesson III: Java Miscellany.

    JARs

    Regular Expressions

    Cloning and Covariance

    JDBC

    Internationalization

    Call by Reference versus Call by Value

    Java Periphery

    What Else Is There?

Appendix A: An Agile Java Glossary.

Appendix B: Java Operator Precedence Rules.

Appendix C: Getting Started with IDEA.

    IDEA

    The Hello Project

    Running Tests

    Taking Advantage of IDEA

Agile Java References.

Index.

Purchase Info

ISBN-10: 0-13-265035-5

ISBN-13: 978-0-13-265035-9

Format: eBook (Watermarked)?

This eBook includes the following formats, accessible from your Account page after purchase:

ePubEPUBThe open industry format known for its reflowable content and usability on supported mobile devices.

MOBIMOBIThe eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

Adobe ReaderPDFThe popular standard, used most often with the free Adobe® Reader® software.

This eBook requires no passwords or activation to read. We customize your eBook by discretely watermarking it with your name, making it uniquely yours.

Includes EPUB, MOBI, and PDF

$47.99 $38.39

Add to Cart