You are previewing Better, Faster, Lighter Java.
O'Reilly logo
Better, Faster, Lighter Java

Book Description

Sometimes the simplest answer is the best. Many Enterprise Java developers, accustomed to dealing with Java's spiraling complexity, have fallen into the habit of choosing overly complicated solutions to problems when simpler options are available. Building server applications with "heavyweight" Java-based architectures, such as WebLogic, JBoss, and WebSphere, can be costly and cumbersome. When you've reached the point where you spend more time writing code to support your chosen framework than to solve your actual problems, it's time to think in terms of simplicity. In Better, Faster, Lighter Java, authors Bruce Tate and Justin Gehtland argue that the old heavyweight architectures are unwieldy, complicated, and contribute to slow and buggy application code. As an alternative means for building better applications, the authors present two "lightweight" open source architectures: Hibernate--a persistence framework that does its job with a minimal API and gets out of the way, and Spring--a container that's not invasive, heavy or complicated. Hibernate and Spring are designed to be fairly simple to learn and use, and place reasonable demands on system resources. Better, Faster, Lighter Java shows you how they can help you create enterprise applications that are easier to maintain, write, and debug, and are ultimately much faster. Written for intermediate to advanced Java developers, Better, Faster, Lighter Java, offers fresh ideas--often unorthodox--to help you rethink the way you work, and techniques and principles you'll use to build simpler applications. You'll learn to spend more time on what's important. When you're finished with this book, you'll find that your Java is better, faster, and lighter than ever before.

Table of Contents

  1. Better, Faster, Lighter Java
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Who Should Read This Book?
    2. Organization of This Book
    3. Conventions Used in This Book
    4. Comments and Questions
    5. Acknowledgments
      1. Bruce A. Tate
      2. Justin Gehtland
  4. 1. The Inevitable Bloat
    1. 1.1. Bloat Drivers
      1. 1.1.1. Enterprise Mega-Frameworks
      2. 1.1.2. Progress
      3. 1.1.3. Economic Forces
      4. 1.1.4. Misuse
    2. 1.2. Options
    3. 1.3. Five Principles for Fighting the Bloat
      1. 1.3.1. 1. Keep It Simple
      2. 1.3.2. 2. Do One Thing, and Do It Well
      3. 1.3.3. 3. Strive for Transparency
      4. 1.3.4. 4. Allow for Extension
      5. 1.3.5. 5. You Are What You Eat
    4. 1.4. Summary
  5. 2. Keep It Simple
    1. 2.1. The Value of Simplicity
      1. 2.1.1. Choosing the Foundations
        1. 2.1.1.1. Technology you buy
        2. 2.1.1.2. Design patterns
        3. 2.1.1.3. Your own code
    2. 2.2. Process and Simplicity
      1. 2.2.1. The Best of Agile
      2. 2.2.2. Pick Your Battles
        1. 2.2.2.1. Algorithms
        2. 2.2.2.2. Architecture
        3. 2.2.2.3. Performance
        4. 2.2.2.4. Design patterns
    3. 2.3. Your Safety Net
      1. 2.3.1. Getting Started with JUnit
        1. 2.3.1.1. Organizing tests
        2. 2.3.1.2. Initialization and clean up
        3. 2.3.1.3. Assertions
        4. 2.3.1.4. Exceptions and intentional failure
      2. 2.3.2. Automating Test Cases with Ant
      3. 2.3.3. Refactoring for Testability
        1. 2.3.3.1. Reuse and testability
        2. 2.3.3.2. Coupling
    4. 2.4. Summary
  6. 3. Do One Thing, and Do It Well
    1. 3.1. Understanding the Problem
      1. 3.1.1. Gathering Requirements
      2. 3.1.2. Controlling Scope Creep
        1. 3.1.2.1. Managing good change
        2. 3.1.2.2. Curtailing disruptive change
    2. 3.2. Distilling the Problem
      1. 3.2.1. Collecting Requirements
      2. 3.2.2. Whittling Away the Noise
      3. 3.2.3. Refining Your Design
    3. 3.3. Layering Your Architecture
      1. 3.3.1. The Basics of Layering
      2. 3.3.2. Interfaces Between Layers
        1. 3.3.2.1. A word about good interfaces
      3. 3.3.3. Common Layers
        1. 3.3.3.1. Business domain models
        2. 3.3.3.2. Data access
        3. 3.3.3.3. Communication
        4. 3.3.3.4. Façades
        5. 3.3.3.5. User interfaces
    4. 3.4. Refactoring to Reduce Coupling
      1. 3.4.1. Microcoupling
        1. 3.4.1.1. Direct access
        2. 3.4.1.2. Inheritance
        3. 3.4.1.3. Transitive coupling
        4. 3.4.1.4. The role of transparency
        5. 3.4.1.5. Testing and coupling
      2. 3.4.2. Macrocoupling
        1. 3.4.2.1. Communication model
        2. 3.4.2.2. Façades
        3. 3.4.2.3. Shared data
        4. 3.4.2.4. Databases
        5. 3.4.2.5. Configuration
    5. 3.5. Summary
  7. 4. Strive for Transparency
    1. 4.1. Benefits of Transparency
    2. 4.2. Who's in Control?
      1. 4.2.1. Active Domain Models
      2. 4.2.2. The Power of Passive Models
    3. 4.3. Alternatives to Transparency
      1. 4.3.1. Techniques That Compromise Transparency
        1. 4.3.1.1. Invading the model
        2. 4.3.1.2. Subclassing
        3. 4.3.1.3. Building a hardwired service
        4. 4.3.1.4. Code metadata
        5. 4.3.1.5. Imposing an invasive programming paradigm
      2. 4.3.2. Moving Forward
    4. 4.4. Reflection
      1. 4.4.1. The Reflection API
      2. 4.4.2. Accessing a Class
      3. 4.4.3. Accessing Fields
      4. 4.4.4. Accessing Methods and Constructors
        1. 4.4.4.1. Invoking a method
    5. 4.5. Injecting Code
      1. 4.5.1. Byte code enhancement frameworks
    6. 4.6. Generating Code
      1. 4.6.1. How Code Generation Works
      2. 4.6.2. Code Generation and Transparency
    7. 4.7. Advanced Topics
      1. 4.7.1. Coarse- and Fine-Grained Services
      2. 4.7.2. A New Programming Paradigm
    8. 4.8. Summary
  8. 5. You Are What You Eat
    1. 5.1. Golden Hammers
      1. 5.1.1. The Allure
        1. 5.1.1.1. The sales process
      2. 5.1.2. Some Examples
        1. 5.1.2.1. Java
        2. 5.1.2.2. J2EE
        3. 5.1.2.3. Distribution
        4. 5.1.2.4. EJB
        5. 5.1.2.5. XML
        6. 5.1.2.6. Persistence frameworks
        7. 5.1.2.7. Web services
    2. 5.2. Understanding the Big Picture
      1. 5.2.1. Modern Cathedrals
        1. 5.2.1.1. Aligning your goals
        2. 5.2.1.2. A hypothetical example
        3. 5.2.1.3. It's all business
        4. 5.2.1.4. Passion and software
    3. 5.3. Considering Technical Requirements
      1. 5.3.1. Outer Questions
      2. 5.3.2. Inner Questions
        1. 5.3.2.1. Prototypes
        2. 5.3.2.2. Documentation
    4. 5.4. Summary
  9. 6. Allow for Extension
    1. 6.1. The Basics of Extension
      1. 6.1.1. Inheritance and Interfaces
      2. 6.1.2. Planned Extension
        1. 6.1.2.1. The Inventor's Paradox
      3. 6.1.3. Unplanned Extension
    2. 6.2. Tools for Extension
      1. 6.2.1. Standards
      2. 6.2.2. Configuration
        1. 6.2.2.1. Client-side configuration with Java Preferences
        2. 6.2.2.2. Server-side configuration with Apache Digester
      3. 6.2.3. Class Loading
        1. 6.2.3.1. Loading a class with Class.forName
        2. 6.2.3.2. Invoking methods
        3. 6.2.3.3. Which class loader?
      4. 6.2.4. What Should You Configure?
        1. 6.2.4.1. Fundamental concepts
        2. 6.2.4.2. External touch points
        3. 6.2.4.3. External resources
    3. 6.3. Plug-In Models
      1. 6.3.1. Plug-Ins at a Lower Level
        1. 6.3.1.1. Service locators
        2. 6.3.1.2. Inversion of control
      2. 6.3.2. The Role of Interfaces
    4. 6.4. Who Is the Customer?
    5. 6.5. Summary
  10. 7. Hibernate
    1. 7.1. The Lie
    2. 7.2. What Is Hibernate?
      1. 7.2.1. Simple Example
      2. 7.2.2. Writing the Object Model
      3. 7.2.3. Building the Schema
      4. 7.2.4. Configuring the Mapping
        1. 7.2.4.1. Identifiers
        2. 7.2.4.2. Relationships
        3. 7.2.4.3. Types
    3. 7.3. Using Your Persistent Model
      1. 7.3.1. Configuring Hibernate
      2. 7.3.2. Using Your Model
        1. 7.3.2.1. Loading data
        2. 7.3.2.2. Updating the database
    4. 7.4. Evaluating Hibernate
      1. 7.4.1. Keep It Simple
      2. 7.4.2. Do One Thing, and Do It Well
      3. 7.4.3. Strive for Transparency
      4. 7.4.4. Allow for Extension
      5. 7.4.5. You Are What You Eat
        1. 7.4.5.1. Going against the grain
      6. 7.4.6. The Down Side
        1. 7.4.6.1. Alternatives
    5. 7.5. Summary
  11. 8. Spring
    1. 8.1. What Is Spring?
      1. 8.1.1. Inversion of Control
    2. 8.2. Pet Store: A Counter-Example
      1. 8.2.1. The Configuration
    3. 8.3. The Domain Model
    4. 8.4. Adding Persistence
      1. 8.4.1. The Model
      2. 8.4.2. The Mapping
      3. 8.4.3. The DAO Interface
      4. 8.4.4. The DAO Implementation
      5. 8.4.5. Using the Model Through a Façade
      6. 8.4.6. Configuration for the DAO Layer
      7. 8.4.7. The Benefits
    5. 8.5. Presentation
      1. 8.5.1. Configuration
      2. 8.5.2. Controllers
      3. 8.5.3. Forms
      4. 8.5.4. Validation
    6. 8.6. Summary
  12. 9. Simple Spider
    1. 9.1. What Is the Spider?
    2. 9.2. Examining the Requirements
      1. 9.2.1. Breaking It Down
      2. 9.2.2. Refining the Requirements
    3. 9.3. Planning for Development
    4. 9.4. The Design
    5. 9.5. The Configuration Service
      1. 9.5.1. Principles in Action
    6. 9.6. The Crawler/Indexer Service
      1. 9.6.1. Principles in Action
    7. 9.7. The Search Service
      1. 9.7.1. Principles in Action
    8. 9.8. The Console Interface
      1. 9.8.1. Principles in Action
    9. 9.9. The Web Service Interface
      1. 9.9.1. Principles in Action
    10. 9.10. Extending the Spider
  13. 10. Extending jPetStore
    1. 10.1. A Brief Look at the Existing Search Feature
      1. 10.1.1. Deciding on the Spider
      2. 10.1.2. Extending jPetStore
    2. 10.2. Replacing the Controller
      1. 10.2.1. Rewrite or Replace?
      2. 10.2.2. Implementing the Interface
      3. 10.2.3. Registering Our New Class with jPetStore
        1. 10.2.3.1. Principles in action
    3. 10.3. The User Interface (JSP)
      1. 10.3.1. Changes to the Original Code to Fit the JSP
      2. 10.3.2. What if We Don't Have the Spider Source?
      3. 10.3.3. Principles in Action
    4. 10.4. Setting Up the Indexer
      1. 10.4.1. Embed in jPetStore or Launch Externally?
      2. 10.4.2. Using the System Scheduler
      3. 10.4.3. Smell the Roses
      4. 10.4.4. Principles in Action
    5. 10.5. Making Use of the Configuration Service
      1. 10.5.1. Principles in Action
    6. 10.6. Adding Hibernate
      1. 10.6.1. Existing Architecture
      2. 10.6.2. Hibernate Mappings for Existing Domain Objects
      3. 10.6.3. Hibernate DAOs
      4. 10.6.4. Changing the Application Configuration
      5. 10.6.5. Spring's Built-In Hibernate Support
      6. 10.6.6. Principles in Action
    7. 10.7. Summary
  14. 11. Where Do We Go from Here?
    1. 11.1. Technology
      1. 11.1.1. Less Is More
      2. 11.1.2. Open Source
      3. 11.1.3. Aspect-Oriented Programming (AOP)
      4. 11.1.4. Persistence
      5. 11.1.5. Containers
    2. 11.2. Process
    3. 11.3. Challenges
    4. 11.4. Conclusion
  15. 12. Bibliography
    1. 12.1. Books
    2. 12.2. Referenced Internet Sources
    3. 12.3. Helpful Internet Sources
    4. 12.4. Other References
  16. About the Authors
  17. Colophon
  18. Copyright