Learning Modular Java Programming
()
About this ebook
- 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
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.
Related to Learning Modular Java Programming
Related ebooks
RESTful Java Web Services Security Rating: 0 out of 5 stars0 ratingsJava 9 Programming By Example Rating: 4 out of 5 stars4/5Beginning Java Programming: The Object-Oriented Approach Rating: 0 out of 5 stars0 ratingsProfessional Java for Web Applications Rating: 0 out of 5 stars0 ratingsMaven Essentials: Get started with the essentials of Apache Maven and get your build automation system up and running quickly Rating: 0 out of 5 stars0 ratingsJava Programming Interviews Exposed Rating: 5 out of 5 stars5/5Spring MVC: Beginner's Guide - Second Edition Rating: 0 out of 5 stars0 ratingsBasic Java Programming for Kids and Beginners Rating: 0 out of 5 stars0 ratingsLearning Oracle 12c: A PL/SQL Approach Rating: 0 out of 5 stars0 ratingsJavaScript Interview Questions, Answers, and Explanations: JavaScript Certification Review Rating: 0 out of 5 stars0 ratingsUltimate Machine Learning with Scikit-Learn Rating: 0 out of 5 stars0 ratingsJava: A complete practical solution Rating: 0 out of 5 stars0 ratingsProfessional C# 7 and .NET Core 2.0 Rating: 0 out of 5 stars0 ratingsSelenium Essentials Rating: 3 out of 5 stars3/5Professional SQL Server 2012 Internals and Troubleshooting Rating: 4 out of 5 stars4/5Mockito for Spring Rating: 0 out of 5 stars0 ratingsMastering Hibernate Rating: 0 out of 5 stars0 ratingsLearning Python Design Patterns - Second Edition: Learning Python Design Patterns - Second Edition Rating: 0 out of 5 stars0 ratingsEJB 3 Developer Guide Rating: 0 out of 5 stars0 ratingsIntroduction to DBMS: Designing and Implementing Databases from Scratch for Absolute Beginners Rating: 0 out of 5 stars0 ratingsTesting in Scrum: A Guide for Software Quality Assurance in the Agile World Rating: 5 out of 5 stars5/5Java Hibernate Cookbook: Over 50 recipes to help you build dynamic and powerful real-time Java Hibernate applications Rating: 0 out of 5 stars0 ratingsComprehensive Guide to Flyway Database Migrations: Definitive Reference for Developers and Engineers Rating: 0 out of 5 stars0 ratingsMockito Essentials Rating: 3 out of 5 stars3/5Scala for Java Developers Rating: 5 out of 5 stars5/5Simply SQL: The Fun and Easy Way to Learn Best-Practice SQL Rating: 4 out of 5 stars4/5Object-Oriented Programming in ColdFusion Rating: 5 out of 5 stars5/5Case Studies in Design Patterns Rating: 5 out of 5 stars5/5Web Development Toolkit for Java Developers: Build dynamic, secure, and scalable web applications with Java (English Edition) Rating: 0 out of 5 stars0 ratings
Programming For You
Creating ELearning Games with Unity Rating: 0 out of 5 stars0 ratingsLearn SAP BI in 24 Hours Rating: 3 out of 5 stars3/5PowerShell 7 for IT Professionals Rating: 1 out of 5 stars1/5Programming in Python: Learn the Powerful Object-Oriented Programming Rating: 0 out of 5 stars0 ratingsProxmox Administration Essentials: Definitive Reference for Developers and Engineers Rating: 0 out of 5 stars0 ratingsThe Book of Powershell Rating: 0 out of 5 stars0 ratingsLearning LEGO MINDSTORMS EV3 Rating: 5 out of 5 stars5/5PHP & MySQL Practice It Learn It Rating: 4 out of 5 stars4/5PHP, MySQL, & JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5iOS 26 App Development Essentials - SwiftUI Edition: Developing iOS 26 Apps using SwiftUI, Swift and Xcode 26 Rating: 0 out of 5 stars0 ratingsSAP Service Management - Advanced Configuration Guide 2 Rating: 0 out of 5 stars0 ratingsJavaScript Made Easy: A Beginner's Practical Guide to Coding Interactive Web Pages Rating: 0 out of 5 stars0 ratingsOntotext GraphDB in Practice: The Complete Guide for Developers and Engineers Rating: 0 out of 5 stars0 ratingsSwipe This!: The Guide to Great Touchscreen Game Design Rating: 4 out of 5 stars4/5Unity Multiplayer Games Rating: 5 out of 5 stars5/5Web Designer's Idea Book, Volume 4: Inspiration from the Best Web Design Trends, Themes and Styles Rating: 4 out of 5 stars4/5Learn to Code with Scratch: Let Your Kids' Creative Ideas Come to Life by Coding Them into Programs Rating: 0 out of 5 stars0 ratingsJob Ready Python Rating: 0 out of 5 stars0 ratingsC# for Beginners: Learn in 24 Hours Rating: 0 out of 5 stars0 ratingsPython For Kids For Dummies Rating: 0 out of 5 stars0 ratingsGood Luck Have Fun: The Rise of eSports Rating: 3 out of 5 stars3/5Hacking Android Rating: 5 out of 5 stars5/5OCP Oracle Certified Professional Java SE 11 Programmer II Study Guide: Exam 1Z0-816 and Exam 1Z0-817 Rating: 5 out of 5 stars5/5
Reviews for Learning Modular Java Programming
0 ratings0 reviews
Book preview
Learning Modular Java Programming - Tejaswini Mandar Jog
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
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 morehttps://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
