Explore 1.5M+ audiobooks & ebooks free for days

From $11.99/month after trial. Cancel anytime.

Learning Modular Java Programming
Learning Modular Java Programming
Learning Modular Java Programming
Ebook491 pages2 hoursEnglish

Learning Modular Java Programming

Rating: 0 out of 5 stars

()

Read preview

About this ebook

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 to building reusable applications that are easy to test, and thus improve overall project management.

LanguageEnglish
PublisherPackt Publishing
Release dateJun 30, 2016
ISBN9781785883200
Learning Modular Java Programming

Related authors

Related to Learning Modular Java Programming

Related ebooks

Programming For You

View More

Related categories

Reviews for Learning Modular Java Programming

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Learning Modular Java Programming - Tejaswini Mandar Jog

    (missing alt)

    Table of Contents

    Learning Modular Java Programming

    Credits

    About the Author

    About the Reviewer

    www.PacktPub.com

    eBooks, discount offers, and more

    Why subscribe?

    Instant updates on new Packt books

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Errata

    Piracy

    Questions

    1. Introducing Modular Programming

    Software – the perspective

    Modules

    What is behind and in a module?

    The practical aspect

    The gang – modular programming

    The world of modules

    Tiers and layers in an enterprise application

    One-tier applications

    Two-tier applications

    Three-tier applications

    N-tier applications

    Java Enterprise architecture

    Sharing the work

    Coordinate with the team

    Versioning tools

    Centralized versioning

    CVS

    Apache Subversion

    The architecture of SVN

    The repository

    The client program

    Distributed versioning

    GitHub

    Summary

    2. Saying Hello to Java EE

    The enterprise as an application

    The Java EE platform

    Features of the Java EE platform

    The world of dotcoms

    Servlet – the dynamicity

    MVC I architecture

    MVC II architecture

    The practical aspect

    What is a framework?

    Advantages of frameworks

    Spring MVC

    The components

    The front controller

    Spring MVC controller

    ModelAndView

    ViewResolver

    The configuration file

    Summary

    3. Implementing the Presentation Layer

    Presentation

    Data binding

    Case 1 – Reading request parameters for searching

    Case 2 – Reading multiple form fields

    Form backing object

    Pre-population of forms

    Form validation

    Developing customized validators using Spring validators

    Annotation-based validations

    Summary

    4. Talking to the Database

    Persistence

    Using object serialization

    Disadvantages of using object serialization

    Storing data in XML

    Disadvantages of storing data in XML

    Saving the data in a relational database

    Advantages of saving data in a relational database

    Interaction of Java with relational databases

    Types of JDBC drivers

    JDBC-ODBC bridge driver

    Advantages of the JDBC-ODBC bridge driver

    Disadvantages of the JDBC-ODBC bridge driver

    JDBC Native API Driver/Partly Java Driver

    Advantages of the JDBC Native API Driver

    Disadvantages of the JDBC Native API Driver

    JDBC Net Protocol Driver

    Advantages of the JDBC Net Protocol Driver

    Disadvantages of the JDBC Net Protocol Driver

    All Java drivers

    Advantage of Java drivers

    Disadvantages of the Java Driver

    Spring-JDBC integration

    Configuring DataSource in Spring JDBC

    Getting data sources by looking up using JNDI

    Getting data sources that pool connections configured on a server

    Getting data sources from the JDBC driver

    Types of integration of JDBC

    Integrating the DataSource to get a connection reference

    Integrating the JDBC template

    Integrating JDBC DAO support

    Problems with JDBC

    Introduction to ORM

    Advantages of using ORM

    Introduction to Hibernate

    Hibernate architecture

    Spring Hibernate integration

    Introduction to unit testing

    Unit testing using JUnit

    Steps for writing a TestCase using annotation

    Summary

    5. Developing the Business Layer

    Business logic

    Domain knowledge

    Rules, formulas, and conditions

    Case studies

    Developing the business layer

    Transaction management

    JDBC and transaction management

    Spring and transaction management

    Programmatic transaction

    Declarative transaction

    Managing declarative transaction in Spring

    Step 1

    Step 2

    Step 3

    Declarative transaction management

    Programmatic transaction management

    Summary

    6. Testing Your Application

    Software testing

    The waterfall model

    The spiral model

    The V model

    Verification phases

    Validation phases

    Mock testing

    Spring testing framework

    Case1 – Inserting contact with correct values as per validation rules

    Case2 – Inserting a contact by violating validation rules for contacts

    Why integration testing?

    Mockito testing

    Arquillian

    Summary

    7. Securing the Application

    Make it safe, make it secure

    Spring security framework

    Secure web request

    Way 1 – Spring Security for URL using servlet filters

    Case 1 – Basic authentication

    Case 2 – Login form authentication

    Case 3 – Authentication against database

    Case 4 – Remember me

    Case 5 – Logout

    Way 2 – Spring Security using AOP

    @Secured

    @RolesAllowed

    SpEL-enabled security annotations for securing the methods

    Spring Security using pointcut

    Way 3 – Custom security

    Summary

    8. Versioning and Deploying

    Versioning

    Collabnet server

    Visual SVN server

    Adding SVN as a plugin to Eclipse

    Adding files in the project and committing them to the repository

    Importing the project in the workspace

    Updating and tracking the project for latest changes in the repository

    Project deployment

    Copying a WAR file into Tomcat without Tomcat manager

    Copying a WAR file into Tomcat with Tomcat manager

    Summary

    Index

    Learning Modular Java Programming


    Learning Modular Java Programming

    Copyright © 2016 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: June 2016

    Production reference: 1270616

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78588-882-3

    www.packtpub.com

    Credits

    Author

    Tejaswini Mandar Jog

    Reviewer

    Dionisios Petrakopoulos

    Acquisition Editor

    Larissa Pinto

    Content Development Editor

    Shali Deeraj

    Technical Editor

    Anushree Arun Tendulkar

    Copy Editor

    Safis Editing

    Project Coordinator

    Sanchita Mandal

    Proofreader

    Safis Editing

    Indexer

    Monica Ajmera Mehta

    Graphics

    Jason Monteiro

    Production Coordinator

    Aparna Bhagat

    Cover Work

    Aparna Bhagat

    About the Author

    Tejaswini Mandar Jog is a passionate and enthusiastic SCJP-certified trainer. She has more than eight years' experience in the IT training field, specializing in Java, J2EE, and relevant technologies. She has worked with many renowned corporate companies on training and skill enhancement programs. She is also involved in the development of projects using Java, Spring, and Hibernate.

    I still remember the very first conversation with the editor about the book. Before that day I was just a reader, I never thought of writing a book. But now I had an opportunity to be an author! I was in a dilemma, and confused—can I be? But then my personal guide and philosopher Mandar gave me the confidence to go for it. Thank you Mandar not just for providing strong support, but also for your valuable suggestions, which helped me to improve the contents.

    This book would not have been completed without the help of Shali, the editor. Her suggestions and efforts made the difference. Aaron, the acquisition editor, thank you for showing confidence in me, and giving me the confidence to write this book.

    Without the best wishes and support of my family, it is doubtful that I would have completed this book.

    It would be mean of me not to mention Ojas, my lovely son. I really appreciate the way he supported me, so that I was able to write peacefully. Love you a lot dear!!!

    Finally, thank you to all who helped by supporting me directly and indirectly to complete this book. Thank you all just for being with me!!!

    About the Reviewer

    Dionisios Petrakopoulos has worked in several companies, using different programming languages (C, C++, Java SE, Java EE, and Scala) and technologies, as a senior software engineer for the past 15 years. His main interest is the Java ecosystem and the various facets of it. His other area of interest is information security, and especially cryptography. He holds a BSc in computer science and an MSc in information security, both from Royal Holloway, University of London.

    I would like to thank my wife, Anna, for her support and love.

    www.PacktPub.com

    eBooks, discount offers, and more

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    eBooks, discount offers, and more

    https://www2.packtpub.com/books/subscription/packtlib

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Instant updates on new Packt books

    Get notified! Find out when new books are published by following @PacktEnterprise on Twitter or the Packt Enterprise Facebook page.

    Preface

    Welcome to the world of Java EE development! A huge world, with a large number of things to learn and so many skills to adapt. It's actually difficult to decide what to start with. When I started, I faced a similar problem. Now, also when I am in training sessions or seminars, I find many people who want be professional developers, but don't have much exposure to the processes, stages, and thinking involved in application development. This book helps you by providing a path for web development that can used to understand the process of Java modular development through an easy-to-understand case study. Nowadays, in Java EE, there are many technologies in the market. One such technology is Spring.

    Spring is useful for developing independent Java modules that can then be combined to create a complete application. We have used Spring, Spring MVC, and many of its features throughout the book, while discussing the concepts of database, unit testing, security, and many other topics.

    What this book covers

    Chapter 1, Introducing Modular Programming, starts with a discussion about Enterprise application, its architecture, and its development. Enterprise application development is a team that activity faces many problems concerning collaboration between team members. We will introduce coordinated development and the tools involved in this chapter.

    Chapter 2, Saying Hello to Java EE, involves a short warm up by discussing and developing a Java web application using Servlet-JSP. We will redevelop the application using a Spring to get startup gear as Spring MVC developer.

    Chapter 3, Implementing the Presentation Layer, discusses the points that need to be taken care of when developing the most important layer of an application: the presentation layer. We will discuss how to develop the pages to incorporate data binding for business logic, as well as for presentation, using Spring MVC features.

    Chapter 4, Talking to the Database, discusses Spring JDBC connectivity. Data collected from the user and data to be used in the business logic need to be persisted. We will also cover Spring DAO support persistency. We will then move on a step and introduce Hibernate, the ORM technology, and its integration with Spring. We will also cover unit testing to make sure our code is working fine.

    Chapter 5, Developing the Business Layer, discusses the development of the most important layer of an application—the business layer—and the communication between the layers. An application needs to be developed by following a number of business rules.

    Chapter 6, Testing Your Application, explains that the modules developed by the developer should produce the correct result. To ensure the correctness of the code in this chapter, we will cover the basics of testing with the help of the V module. We will also cover integration testing with JUnit and Mockito.

    Chapter 7, Securing the Application, discusses why and how to secure the application. In an application, there are certain modules that are open and available to all, and some that are restricted. We will apply the Spring security module to secure the Spring MVC application with the help of basic and form based security.

    Chapter 8, Versioning and Deploying, shows us how to collaborate on the application, which has been developed in parts, or by different team members simultaneously. In this chapter, we will set up and integrate Tortoise SVN as a versioning tool used to collaborate on the code. We will also discuss the creation of repositories, users, and setting access rules for Collabnet and Visual SVN servers.

    What you need for this book

    You will need to have sound knowledge and practical exposure of core Java to understand this book. Along with this, knowledge of basic JDBC and the concepts of object-oriented programming language is required. As we are using Eclipse IDE throughout the book, you should be familiar with it. Those who have an introductory knowledge of Spring beginner framework can refer to this book easily. If you are beginner for Spring, we suggest you first go through the basic concepts of Spring configuration and get some practical experience. A basic knowledge of Hibernate and JUnit will be an added advantage.

    Who this book is for

    The idea for this book is to give the reader experience of creating an application step by step using Java modular programming step by step. The book is useful for any novice developer who wants to get exposure of modular Java development. The book is also useful for anyone who wants to have a roadmap for developing an application in stages such as problem statement, UI development, business logic development, database layer development, and so on. The book covers all the aspects of application development required into a turn a the problem statement to product, with coverage of security, maintaining versions, and the deployment process.

    Conventions

    In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

    Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: Every object created based on this type will inherit these default properties such as toString, valueOf, hasOwnProperty, and so on.

    A block of code is set as follows:

    function doAddition(num1, num2){

      return num1 + num2;

    }

    function doSubtraction(num1, num2){

      var result = null;

      if(num1 > num2){

      result = num1 - num2;

     

      }else{

        result = num2 - num1;

      }

      return result;

    }

    Note

    Warnings or important notes appear in a box like this.

    Tip

    Tips and tricks appear like this.

    Reader feedback

    Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

    To send us general feedback, simply e-mail <feedback@packtpub.com>, and mention the book's title in the subject of your message.

    If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

    Customer support

    Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

    Downloading the example code

    You can download the example code files for this book 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 files e-mailed directly to you.

    You can download the code files by following these steps:

    Log in or register to our website

    Enjoying the preview?
    Page 1 of 1