O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning Modular Java Programming

Book Description

Explore the power of modular programming for building applications with Java and Spring!

About This Book

  • Understand the basic concepts of Modular Programming to build enterprise applications with Java
  • Create short and precise code and eliminate recursion
  • The book follows a step-by-step approach that makes implementing Modular Programming easy

Who This Book Is For

This book targets Java developers who have a basic knowledge of application development with Java and are interested in learning the Modular Programming approach for building reusable applications that are easy to test, and thus improve overall project management.

What You Will Learn

  • Learn about Modular Programming and what modules an enterprise application can be divided into.
  • Set up a development environment and create a "Hello World" application.
  • Start implementing a sample application from the presentation layer.
  • Implement the persistence layer.
  • Implement the business layer, wrapping up all of the modules with Contexts and Dependency Injection (CDI).
  • Manage an application's life cycle.
  • Learn how to secure Web applications.
  • Test enterprise applications and their automation.
  • Understand how to version source code using Source Code Management (SCM) systems such as GIT and SVN.

In Detail

Modular programming means dividing an application into small parts and then developing it. It is an approach taken by developers to build applications and helps them add efficiency in their development process, thus making it more effective.

The book starts with the fundamentals of Modular Programming. Then we move on to the actual implementation, where we teach developers how to divide an application into different modules or layers (such as presentation, execution, security, lifecycle, services, and so on) for better management. Once readers are well-versed in these modules and their development, the book shows how to create bindings in order to join these different modules and form a complete application. Next, the readers will learn how to manage these modules through dependency injection.

Later, we move on to testing; readers will learn how to test the different modules of an application. The book ends by teaching readers how to maintain different versions of their application and how to modify it. By the end of the book, readers will have a good understanding of modular programming and will be able to use it to build applications with Java.

Style and approach

This book is a practical guide to help readers learn Modular Programming with Java and build an enterprise-ready app along the way.

The book is divided into three major sections. The first teaches the fundamentals of Modular Programming and how to implement them; the second teaches readers to combine and manage the modules developed; in the final section, the book explains the applications of Modular Programming.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Learning Modular Java Programming
    1. Table of Contents
    2. Learning Modular Java Programming
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
        2. Instant updates on new Packt books
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Introducing Modular Programming
      1. Software – the perspective
      2. Modules
        1. What is behind and in a module?
          1. The practical aspect
      3. The gang – modular programming
        1. The world of modules
      4. Tiers and layers in an enterprise application
        1. One-tier applications
        2. Two-tier applications
        3. Three-tier applications
        4. N-tier applications
        5. Java Enterprise architecture
      5. Sharing the work
      6. Coordinate with the team
        1. Versioning tools
          1. Centralized versioning
            1. CVS
            2. Apache Subversion
          2. The architecture of SVN
            1. The repository
            2. The client program
          3. Distributed versioning
            1. GitHub
      7. Summary
    9. 2. Saying Hello to Java EE
      1. The enterprise as an application
      2. The Java EE platform
        1. Features of the Java EE platform
        2. The world of dotcoms
        3. Servlet – the dynamicity
        4. MVC I architecture
        5. MVC II architecture
        6. The practical aspect
        7. What is a framework?
          1. Advantages of frameworks
        8. Spring MVC
          1. The components
          2. The front controller
          3. Spring MVC controller
          4. ModelAndView
          5. ViewResolver
          6. The configuration file
      3. Summary
    10. 3. Implementing the Presentation Layer
      1. Presentation
        1. Data binding
          1. Case 1 – Reading request parameters for searching
          2. Case 2 – Reading multiple form fields
            1. Form backing object
            2. Pre-population of forms
        2. Form validation
          1. Developing customized validators using Spring validators
          2. Annotation-based validations
      2. Summary
    11. 4. Talking to the Database
      1. Persistence
        1. Using object serialization
          1. Disadvantages of using object serialization
        2. Storing data in XML
          1. Disadvantages of storing data in XML
        3. Saving the data in a relational database
          1. Advantages of saving data in a relational database
      2. Interaction of Java with relational databases
        1. Types of JDBC drivers
          1. JDBC-ODBC bridge driver
            1. Advantages of the JDBC-ODBC bridge driver
            2. Disadvantages of the JDBC-ODBC bridge driver
          2. JDBC Native API Driver/Partly Java Driver
            1. Advantages of the JDBC Native API Driver
            2. Disadvantages of the JDBC Native API Driver
          3. JDBC Net Protocol Driver
            1. Advantages of the JDBC Net Protocol Driver
            2. Disadvantages of the JDBC Net Protocol Driver
          4. All Java drivers
            1. Advantage of Java drivers
            2. Disadvantages of the Java Driver
        2. Spring-JDBC integration
          1. Configuring DataSource in Spring JDBC
            1. Getting data sources by looking up using JNDI
            2. Getting data sources that pool connections configured on a server
            3. Getting data sources from the JDBC driver
        3. Types of integration of JDBC
          1. Integrating the DataSource to get a connection reference
          2. Integrating the JDBC template
          3. Integrating JDBC DAO support
        4. Problems with JDBC
      3. Introduction to ORM
        1. Advantages of using ORM
        2. Introduction to Hibernate
          1. Hibernate architecture
          2. Spring Hibernate integration
      4. Introduction to unit testing
        1. Unit testing using JUnit
          1. Steps for writing a TestCase using annotation
      5. Summary
    12. 5. Developing the Business Layer
      1. Business logic
        1. Domain knowledge
        2. Rules, formulas, and conditions
        3. Case studies
        4. Developing the business layer
      2. Transaction management
        1. JDBC and transaction management
        2. Spring and transaction management
          1. Programmatic transaction
          2. Declarative transaction
            1. Managing declarative transaction in Spring
              1. Step 1
              2. Step 2
              3. Step 3
        3. Declarative transaction management
        4. Programmatic transaction management
      3. Summary
    13. 6. Testing Your Application
      1. Software testing
        1. The waterfall model
        2. The spiral model
        3. The V model
          1. Verification phases
          2. Validation phases
      2. Mock testing
        1. Spring testing framework
          1. Case1 – Inserting contact with correct values as per validation rules
          2. Case2 – Inserting a contact by violating validation rules for contacts
      3. Why integration testing?
      4. Mockito testing
        1. Arquillian
      5. Summary
    14. 7. Securing the Application
      1. Make it safe, make it secure
      2. Spring security framework
        1. Secure web request
        2. Way 1 – Spring Security for URL using servlet filters
          1. Case 1 – Basic authentication
          2. Case 2 – Login form authentication
          3. Case 3 – Authentication against database
          4. Case 4 – Remember me
          5. Case 5 – Logout
        3. Way 2 – Spring Security using AOP
          1. @Secured
          2. @RolesAllowed
          3. SpEL-enabled security annotations for securing the methods
          4. Spring Security using pointcut
        4. Way 3 – Custom security
      3. Summary
    15. 8. Versioning and Deploying
      1. Versioning
        1. Collabnet server
      2. Visual SVN server
        1. Adding SVN as a plugin to Eclipse
          1. Adding files in the project and committing them to the repository
          2. Importing the project in the workspace
          3. Updating and tracking the project for latest changes in the repository
      3. Project deployment
        1. Copying a WAR file into Tomcat without Tomcat manager
        2. Copying a WAR file into Tomcat with Tomcat manager
      4. Summary
    16. Index