Agile Java Development With Spring Hibernate and Eclipse
Agile Java Development With Spring, Hibernate and Eclipse Anil Hemrajani anil@visualpatterns. com © Visual Patterns, Inc.
About This Presentation • Not a tutorial on any one technology! Overview of each technology (use website, books, etc. for details) Downloadable code (working application) Latest buzz in the US, Europe, etc. • End-to-end system! Requirements Architecture/design Java development and debugging Deployment Logging/monitoring Advanced considerations • Content/format (text, graphs, code, comics) © Visual Patterns, Inc. 2
Material In This Presentation Taken Directly From My Book Agile Java Development With Spring, Hibernate and Eclipse Forewords by Scott W. Ambler and Rod Johnson available on amazon. com 1. Introduction to Agile Java Development 2. The Sample Application: An Online Timesheet System 3. XP and AMDD-Based Architecture and Design Modeling 4. Environment Setup: JDK, Ant, and JUnit 5. Using Hibernate For Persistent Objects 6. Overview of the Spring Framework 7. The Spring Web MVC Framework 8. The Eclipse Phenomenon 9. Logging, Debugging, Monitoring and Profiling 10. Beyond the Basics 11. What Next? 12. Parting Thoughts 13. 14. Appendices (with lots of goodies) © Visual Patterns, Inc. 3
My Background (details at Visual. Patterns. com) • 20 years of experience in the IT Working with Java Technology since late 1995 as a developer, entrepreneur, author, and trainer. Helped several Fortune 100 companies (some smaller organizations) Published a book and 30 articles Presented at conferences and seminars around the world Awards: "Outstanding Contribution to the Growth of the Java Community" "Best Java Client" for Back. Online (a Java-based online backup product) nominated for a Computerworld-Smithsonian award by Scott Mc. Nealy • Founder of: Isavix Corporation – successful IT solutions company (now Inscope Solutions) Developer. Hub. com (formerly isavix. net) - award-winning online developer community (grew to over 100, 000 registered members) • At present – Visual. Patterns. com and Agile. Draw. org © Visual Patterns, Inc. 4
Practical Stuff, Not Fluff! • Recently completed project for U. S. Fortune 50 company • Application Financial application process billions of $ every week Clustered application (99. 9% uptime required) Used most the technologies covered in presentation (spring, hibernate, eclipse, ant, JUnit…) © Visual Patterns, Inc. 5
Agenda 1. 2. 3. 4. Introduction to Agile Java Development Agile Processes Agile Modeling Agile Development Environment Setup: Directory Structure, JDK, Ant and JUnit Using Hibernate For Persistent Objects (Short Break) The Spring Framework The Eclipse Phenomenon! Logging, Debugging, Monitoring, and Profiling 5. Beyond The Basics © Visual Patterns, Inc. 6
Introduction to Agile Java Development Assume simplicity. Travel light. - Agile Modeling principles: agilemodeling. com © Visual Patterns, Inc.
What Is Agile Java Development? It Could Include… 1. Agile Software Lifecycle Processes (e. g. Scrum, XP, TDD) 2. Agile Architecture/Design Modeling Incremental (just-in-time) design “Good enough” diagrams Agile Model Driven Development (AMDD) 3. Agile Java Design/Development Simple design and coding! Test-driven development (TDD) Efficient frameworks and tools (Ant, JUnit, Hibernate, Spring, Eclipse…) Plain Old Java Objects (POJOs), whenever possible © Visual Patterns, Inc. 8
Sample (Time Sheet) Application Used In This Presentation Downloadable code: visualpatterns. com/resources. jsp © Visual Patterns, Inc. 9
Agile Processes Requirements change. Design evolves. Documents are seldom current. © Visual Patterns, Inc.
Some Stats by The Standish Group (standishgroup. com) © Visual Patterns, Inc.
The Solution CHAOS Ten – Success Factors source: standishgroup. com In 2001, seventeen methodologists came together to unify their methodologies under one umbrella; they jointly defined the term, Agile! Read story at: martinfowler. com/articles/agile. Story. html © Visual Patterns, Inc. 12
Agile. Manifesto. org © Visual Patterns, Inc. 13
What Does “Agile” Exactly Mean? The Term Agile incorporates a wide range of methods, for example: • AM - Agile Modeling • • • ASD - Adaptive Software Development AUP - Agile Unified Process Crystal FDD - Feature Driven Development DSDM - Dynamic Systems Development Method Lean Software Development • Scrum • Xbreed • XP - e. Xtreme Programming © Visual Patterns, Inc. 14
Agility - All About Smaller Chunks (Shorter/Frequent Cycles) Release 2 Release 1 Iteration 0 �software Iteration 1 �software . . . � software Iteration n �software Iteration 0 Iteration 1 � software . . . Iteration n software Incrementally Build Software - Highest Priority Features First! © Visual Patterns, Inc. .
Agile Method: Scrum • • Simple process for product/project management Product Backlog - List of known features/changes for product Sprint - 1 -month iterations (develop highest priority items) Meetings Sprint Planning Meeting – Done at beginning of each sprint (after planning, features moved from product backlog to sprint backlog) Daily scrum meeting (short: 15 minutes) Sprint review meeting © Visual Patterns, Inc. 16
Extreme Programming (XP) • Shorter and Frequent Cycles (smaller chunks!) Release - Quarterly Cycles (set a theme) Iteration - Weekly Cycles (e. g. aim for last day of week) 10 -minute builds Continuous integration (multiple times per day; manual or automatic) Incremental Design and Planning (defer investment till needed) Development in small increments using Test-First development • Communications - Sit Together, Informative Workspace, onsite customer • Flow - sustainable pace versus rigid phases; velocity, continuous integration • Others… visit extremeprogramming. org © Visual Patterns, Inc. 17
Presentation Outline Introduction to Agile Java Development Agile Processes • Agile Modeling • Agile Development Environment Setup: Directory Structure, JDK, Ant and JUnit Using Hibernate For Persistent Objects The Spring Framework The Eclipse Phenomenon! Logging, Debugging, Monitoring, and Profiling • Beyond The Basics © Visual Patterns, Inc. 18
Agile Modeling “. . . your goal is to build a shared understanding, it isn’t to write detailed documentation. ” - Scott W. Ambler © Visual Patterns, Inc.
Quick Poll Have you ever been on a project where documentation was kept up-to-date through end of project? © Visual Patterns, Inc. 20
Agile Model Driven Development (AMDD) • Subset of Agile Modeling (agilemodeling. com) • Agile version of Model Driven Development (MDD) • Instead of extensive models, “barely good enough” • Initial modeling activity 1. 2. Requirements Architecture • Requirements modeling Usage models Domain models UI models • Architecture modeling Free-form diagrams Change cases © Visual Patterns, Inc. 21
Project Initiation © Visual Patterns, Inc. 22
Problem Statement Our employees currently submit their weekly hours worked using a paper-based timesheet system that is manually intensive and errorprone. We require an automated solution for submitting employee hours worked, in the form of an electronic timesheet, approving them, and paying for the time worked. In addition, we would like to have automatic notifications of timesheet status changes and a weekly reminder to submit and approve employee timesheets. © Visual Patterns, Inc. 23
Project Kickoff Meeting © Visual Patterns, Inc. 24
Choices Of Release (High) Level Models Release Level Models scope table, glossary, etc. domain model user stories UI prototype & flow map architecture Iteration Level Models acceptance tests CRC cards application flow map UML diagrams database model Model with a purpose -- shared understanding! © Visual Patterns, Inc. 25
Sample Scope Table Shared understanding: what's in and what's out © Visual Patterns, Inc. 26
Domain Model Shared understanding: business concepts > key domain objects © Visual Patterns, Inc. 27
User Stories Or Use Cases 3 XP Style User Story Card Use Case - Casual, Brief or Fully Dressed Shared understanding: features required of software © Visual Patterns, Inc. 28
User Interface (UI) Prototype Shared understanding: functionality, look-and-feel, etc. © Visual Patterns, Inc. 29
UI Flow Map (Storyboard) Shared understanding: user interface navigation/flow © Visual Patterns, Inc. 30
High-Level Architecture Diagram Web Browser HTTP Controller Model Spring Business objects, Dispatcher. Servlet Hibernate beans View JSP/HTML JDBC RDBMS (Oracle) Spring Schedule r Objects managed by Spring Io. C Container BEA Web. Logic Server Shared understanding: technologies, scalability, security, reliability © Visual Patterns, Inc. 31
Glossary - List Of Common Business/Technical Terms • Accounting The accounting department/staff. • Approved Status of a timesheet when a Manager approves a previously submitted timesheet. • Employee A person who works on an hourly basis and reports to a manager. • Paid Status of a timesheet when the accounting department has issued a check. • Etc… Shared understanding: common terminology © Visual Patterns, Inc. 32
Choices Of Iteration Level (Detailed) Models Release Level Models scope table, glossary, etc. domain model user stories UI prototype & flow map architecture Iteration Level Models acceptance tests CRC cards application flow map UML diagrams database model © Visual Patterns, Inc. 33
Acceptance Tests (Serve As Detailed Requirements) • Sign In The employee id can be up to 6 characters. The password must be between 8 and 10 characters. Only valid users can sign in. • Timesheet List Only a user's personal timesheets can be accessed. • Enter Hours must contain numeric data. Daily hours cannot exceed 16 hours. Weekly hours cannot exceed 96 hours. Hours must be billed to a department. Hours can be entered as two decimal places. Employees can only view and edit their own timesheets. © Visual Patterns, Inc. 34
Active Stakeholder Participation (With Business Representative) © Visual Patterns, Inc. 35
Exploring Classes Using CRC Cards First, let's reflect on what we know, domain model, UI and architecture Second, let's explore classes on CRC cards using both as input models Timesheet List screen free-form architecture domain model © Visual Patterns, Inc. 36
Application Flow Map (Home Grown Artifact) • Complementary to class diagrams and CRC cards • Can be extended using CRUD columns © Visual Patterns, Inc. 37
UML Class and Package Diagrams © Visual Patterns, Inc. 38
Focus Is On Working Software vs. Comprehensive Documentation Conceptual Models problem statement scope table domain model user stories UI prototypes glossary architecture Physical Models acceptance tests application flow map Implementation Data Base CRC cards database model UML diagrams “…your goal is to build a shared understanding, it isn’t to write detailed documentation. ” - Scott W. Ambler THE FINAL AND LASTING ARTIFACTS! UI prototype Code Base & flow map © Visual Patterns, Inc. 39
Shifting Some Upfront Design to Refactoring © Visual Patterns, Inc. 40
Shifting Some Upfront Design To Refactoring (Continuous Design) • Refactoring is not a new concept; the term is relatively new • refactoring. com “Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. ” - Martin Fowler Over 100 refactoring techniques; for example: Extract superclass Extract interface Move class Move method © Visual Patterns, Inc. 41
Agile Draw - Elegantly Simple Modeling Technique High-Level Architecture UI Flow Map Visit Agile. Draw. org Conceptual Class Diagram © Visual Patterns, Inc. 42
Presentation Outline Introduction to Agile Java Development Agile Processes Agile Modeling • Agile Development Environment Setup: Directory Structure, JDK, Ant and JUnit Using Hibernate For Persistent Objects The Spring Framework The Eclipse Phenomenon! Logging, Debugging, Monitoring, and Profiling • Beyond The Basics © Visual Patterns, Inc. 43
Agile Java Development: Environment Setup (Directory Structure, JDK, Ant, and JUnit) © Visual Patterns, Inc.
Quick Poll How many of you are using Ant, JUnit, Maven, Cruise Control, etc? © Visual Patterns, Inc. 45
Personal Opinion: Early Environment Setup Is Essential § Involves more than people expect/plan Cycle 0 • Get minimal environment setup (scripts, directory, version control, etc. ) • Get end-to-end demo working Helps team © Visual Patterns, Inc. 46
Directory Structure, Naming Conventions, Version Control, etc. controller/Timesheet. List. Controller. java model/Timesheet. java ➔model/Timesheet. Manager. java ➔test/Timesheet. List. Controller. Test. java ➔test/Timesheet. Manager. Test. java ➔view/timesheetlist. jsp ➔ ➔ © Visual Patterns, Inc. 47
Ant (ant. apache. org) • Ant task types Compile tasks (that is, javac) Deployment tasks File tasks such as copy, delete, move, and others. Property tasks for setting internal variables Audit/coverage tasks Database tasks Documentation tasks Execution tasks Mail tasks Preprocess tasks Property tasks Remote tasks Miscellaneous tasks (e. g. echo) <ftp server="mirrors. kernel. org" action="get" remotedir="/gnu/chess" userid="anonymous" password="guest@guest. com" verbose="yes" binary="yes"> <fileset file="README. gnuchess"/> </ftp> <mail tolist="friend@somehost. com" subject="Hello!" from="me@myhost. com" mailhost="myhost. com" user="myuserid" password="mypassword"/> © Visual Patterns, Inc. 48
JUnit (junit. org) • Originally written by Erich Gamma (Gang of Four, Design Patterns) Kent Beck (author of Extreme Programming and Test Driven Development) • Simple framework – various assert methods assert. Equals assert. False assert. Not. Null assert. Not. Same assert. Null assert. Same assert. True public class Simple. Test extends junit. framework. Test. Case { int value 1 = 2, value 2 = 3, expected. Result = 5; public static void main(String args[]) { junit. textui. Test. Runner. run(suite()); } public static Test suite() { return new Test. Suite(Simple. Test. class); } } public void test. Add. Success() { assert. True(value 1 + value 2 == expected. Result); } © Visual Patterns, Inc. 49
JUnit GUI Based Testing Console Runner Eclipse Plug-in © Visual Patterns, Inc. 50
Agile Method: Test Driven Development (TDD) w/ JUnit • • A term coined by Kent Beck Also, a XP practice (test-first) “Red - Green - Refactor” Write Test First Code, Compile, Test ��� Write unit test code Write some actual code ��� More unit test code �More actual code ���� More unit test code �� More actual code Several benefits to this approach: Minimal code written to satisfy requirements ( nothing more, nothing less! ) If code passes the unit tests, it is done! Can help design classes better (from a client/interface perspective) Refactor with confidence © Visual Patterns, Inc. 51
Presentation Outline Introduction to Agile Java Development Agile Processes Agile Modeling • Agile Development Environment Setup: Directory Structure, JDK, Ant and JUnit Using Hibernate For Persistent Objects The Spring Framework The Eclipse Phenomenon! Logging, Debugging, Monitoring, and Profiling • Beyond The Basics © Visual Patterns, Inc. 52
Agile Java Development: Using Hibernate For Persistent Objects © Visual Patterns, Inc.
Quick Poll What persistence solution does your project use (e. g. JDBC, ORM, entity bean)? © Visual Patterns, Inc. 54
Where Hibernate Fits Into Our Architecture © Visual Patterns, Inc. 55
An Overview of Object-Relational Mapping (ORM) • ORM - Java object to database table/record mapping Java = objects database = relational • Relationships unidirectional and bidirectional relations in a relational database are bidirectional by definition • Cardinality (OO term is multiciplicity) One-to-one one-to-many-to-one and many-to-many • Object Identity • Cascade • Others… © Visual Patterns, Inc. 56
Hibernate Basics • Dialect (DB 2, Microsoft SQL Server, My. SQL, Oracle, Postgre. SQL, SAP DB, Sybase, Times. Ten…) • Session. Factory, Session, and Transaction • Work with Database Records (as Java Objects) • Object States - persistent, detached, and transient • Data Types – more than you'll likely need! • Hibernate Query Language (HQL) – powerful SQL-like language © Visual Patterns, Inc. 57
From Domain Model To A (Denormalized) Physical Data Model © Visual Patterns, Inc. 58
Working With Hibernate - Simple Example Using Department 1. hibernate. cfg. xml – Hibernate configuration file (DB configuration) <mapping resource="Department. hbm. xml" /> 2. Department. hbm. xml – Mapping file for our Department table <class name="com. visualpatterns. timex. model. Department" table="Department"> <id name="department. Code" column="department. Code"> <property name="name" column="name"/> 3. Department. java – Bean file with two variables: String department. Code; String name; 4. Hibernate. Test. java – Simple test program (on next slide) © Visual Patterns, Inc. 59
Hibernate. Test. java Session. Factory session. Factory = new Configuration(). configure(). build. Session. Factory(); Session session = session. Factory. get. Current. Session(); Transaction tx = session. begin. Transaction(); Department department = (Department) session. get(Department. class, "IT"); System. out. println("Name for IT = " + department. get. Name()); . . . List department. List = session. create. Query("from Department"). list(); for (int i = 0; i < department. List. size(); i++) { department = (Department) department. List. get(i); System. out. println("Row " + (i + 1) + "> " + department. get. Name() + " (" + department. get. Department. Code() + ")"); }. . . session. Factory. close(); © Visual Patterns, Inc. 60
Other Hibernate Features • Saving (save, merge, save. Or. Update) session. save. Or. Update(timesheet) • Deleting records session. delete(Object), or session. create. Query("DELETE from Timesheet") • Queries using Criteria interface (more OO and typesafe) List timesheet. List = session. create. Criteria(Timesheet. class). add(Restrictions. eq("employee. Id", employee. Id)). list(); Related classes: Restrictions, Order, Junction, Distinct, and others • Locking Objects (Concurrency Control) • Lots More Hibernate (associtions, annotations, filters, interceptors, scrollable iterations, native SQL, transaction management, etc. ) © Visual Patterns, Inc. 61
Presentation Outline Introduction to Agile Java Development Agile Processes Agile Modeling • Agile Development Environment Setup: Directory Structure, JDK, Ant and JUnit Using Hibernate For Persistent Objects The Spring Framework The Eclipse Phenomenon! Logging, Debugging, Monitoring, and Profiling • Beyond The Basics © Visual Patterns, Inc. 62
Agile Java Development: The Spring Framework © Visual Patterns, Inc.
Spring Modules © Visual Patterns, Inc. 64
Spring Java Packaging (org. springframework. ) © Visual Patterns, Inc. 65
Quick Poll Are you familiar with Inversion of Control (Io. C)? © Visual Patterns, Inc.
Io. C Container And Dependency Injection Pattern Using Io. C Normal Way public class A { B my. B = new B(); C my. C = new C(); } Class C Class B IOC Container Class A public class A { B my. B; C my. C; public set. B(B my. B) public set. C(C my. C) • Dependency Injection Styles Two Supported By Spring: Setter/getter based Constructor based Fowler suggests a 3 rd, interface injection, http: //www. martinfowler. com/articles/injection. html • Spring Io. C Concepts: Beans, Bean. Factory, Application. Context… © Visual Patterns, Inc. 67
Benefits of Using Spring • Light weight Inversion of Control (Io. C) container • Excellent support for POJOs (e. g. declarative transaction management) • Modular – not an all-or-nothing approach • Testing – dependency injection and POJOs makes for easier testing • Many others No Singletons Builds on top of existing technologies (e. g. JEE, Hibernate) Robust MVC web framework Consistent database exception hierarchy (e. g. wrap SQLException) © Visual Patterns, Inc. 68
Where Spring Framework Fits Into Our Architecture Optional Hibernate integration © Visual Patterns, Inc. 69
Quick Poll Which web framework do you use? © Visual Patterns, Inc. 70
Spring Web MVC • Easier testing – mock classes, dependency injection • Bind directly to business objects • Clear separation of roles – validators, adaptable controllers, command (form) object, etc. • Simple but powerful tag libraries • Support for various view technologies and web frameworks (e. g. Struts, webwork, tapestry, JSF) © Visual Patterns, Inc. 71
Spring MVC Java Concepts 1. Controller 2. Model. And. View 3. Command (Form Backing) Object 4. Validator 5. Spring Tag Library (spring: bind) © Visual Patterns, Inc. 72
Spring MVC Configuration <servlet> <servlet-name>timex</servlet-name> <servlet-class> org. springframework. web. servlet. Dispatcher. Servlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>timex</servlet-name> <url-pattern>*. htm</url-pattern> </servlet-mapping> web. xml timex-servlet. xml <bean id="url. Map. Authenticate” class= "org. springframework. web. servlet. handler. Simple. Url. Handler. Mapping"> <prop key="/enterhours. htm">enter. Hours. Controller</prop>. . . <bean id="view. Resolver" class="org. springframework. web. servlet. view. Internal. Resource. View. Resolver" > <property name="view. Class"> <value>org. springframework. web. servlet. view. Jstl. View</value> </property> <property name="prefix"> <value>/WEB-INF/jsp/</value> </property> <property name="suffix"> <value>. jsp</value> </property> </bean> 73 © Visual Patterns, Inc.
Sample End-To-End Flow Using Spring and Hibernate © Visual Patterns, Inc. 74
Timesheet List: A No-Form Controller Example public class Timesheet. List. Controller implements Controller {. . . public Model. And. View handle. Request( Http. Servlet. Request request, Http. Servlet. Response response) mock. Http. Servlet. Request = new Mock. Http. Servlet. Request("GET", "/timesheetlist. htm"); Model. And. View model. And. View = timesheet. List. Controller. handle. Request( mock. Http. Servlet. Request, null); assert. Not. Null(model. And. View. get. Model()); © Visual Patterns, Inc. 75
Enter Hours: A Form Screen 1. Enter. Hours. Controller. java 2. Enter. Hours. Validator. java 3. enterhours. jsp public class Enter. Hours. Controller extends Simple. Form. Controller © Visual Patterns, Inc. 76
View/JSP Code – Spring and JSTL Tag Libraries <spring: bind path="command. employee. Id"> <input name='<c: out value="${status. expression}"/>' value='<c: out value="${status. value}"/>' type="text" size="6" maxlength="6"> </spring: bind> Special (Spring) variable named status • status. value • status. expression • status. error. Messages • status. display. Value © Visual Patterns, Inc. 77
Sign In (Authentication) - Spring Handler. Interceptor public class Http. Request. Interceptor extends Handler. Interceptor. Adapter { public boolean pre. Handle(Http. Servlet. Request request, Http. Servlet. Response response, Object handler) { if (!signed. In) { response. send. Redirect(this. sign. In. Page); return false; } © Visual Patterns, Inc. 78
Other Spring Web Stuff • View with no controllers (e. g. only JSP files) <bean id="url. Filename. Controller" class="org. springframework. web. servlet. mvc. Url. Filename. View. Controller"/> <prop key="/help. htm">url. Filename. Controller</prop> • Spring 2. 0 – new tag libraries form: form - org. springframework. web. servlet. tags. form. Form. Tag form: input- org. springframework. web. servlet. tags. form. Input. Tag form: password - org. springframework. web. servlet. tags. form. Password. Input. Tag form: hidden - org. springframework. web. servlet. tags. form. Hidden. Input. Tag form: select - org. springframework. web. servlet. tags. form. Select. Tag form: option - org. springframework. web. servlet. tags. form. Option. Tag form: radiobutton - org. springframework. web. servlet. tags. form. Radio. Button. Tag Others… • Other Web Flow – gaining a lot of momentum! Wizard-like features. Portlet API – based on JSR-168 Portlet Specification (jcp. org). © Visual Patterns, Inc. 79
Spring ORM Module: Support for Hibernate • Management of sessionfactory and session (no close calls) • Declarative transaction management in light-weight containers • Easier testing (pluggable Sessionfactory via XML file) • Less lines of code – focus on business logic! © Visual Patterns, Inc. 80
Spring ORM Module: Support for Hibernate (cont’d) Session session = Hibernate. Util. get. Session. Factory(). get. Current. Session(); session. begin. Transaction(); try { session. save. Or. Update(timesheet); session. get. Transaction(). commit(); } catch (Hibernate. Exception e) { session. get. Transaction(). rollback(); throw e; } get. Hibernate. Template(). save. Or. Update(timesheet); Less lines of code © Visual Patterns, Inc. 81
More Spring… • Scheduling Jobs (with Quartz or JDK timers) <bean id="reminder. Email. Job. Detail" class= "org. springframework. scheduling. quartz. Method. Invoking. Job. Detail. Factory. Bean"> <property name="target. Object" ref="reminder. Email" /> <property name="target. Method" value="send. Mail" /> </bean> <bean id="reminder. Email. Job. Trigger" class="org. springframework. scheduling. quartz. Cron. Trigger. Bean"> <property name="job. Detail" ref="reminder. Email. Job. Detail" /> <property name="cron. Expression" value="0 0 14 ? * 6" /> </bean> • Spring email support • Much more JEE support Sub-projects (Acegi, Bean. Doc, Spring IDE, etc. ) © Visual Patterns, Inc. 82
Presentation Outline Introduction to Agile Java Development Agile Processes Agile Modeling • Agile Development Environment Setup: Directory Structure, JDK, Ant and JUnit Using Hibernate For Persistent Objects The Spring Framework The Eclipse Phenomenon! Logging, Debugging, Monitoring, and Profiling • Beyond The Basics © Visual Patterns, Inc. 83
Agile Java Development: The Eclipse Phenomenon! © Visual Patterns, Inc.
Quick Poll Which IDE do you use? © Visual Patterns, Inc. 85
The Eclipse Foundation, Platform and Projects • Foundation Originally developed by Object Technology International (OTI), purchased by IBM ($40 million) and donated it to open source! Recruited various corporations; from eclipse. org: Industry leaders Borland, IBM, MERANT, QNX Software Systems, Rational Software, Red Hat, Su. SE, Together. Soft and Webgain formed the initial eclipse. org Board of Stewards in November 2001. By the end of 2003, this initial consortium had grown to over 80 members. My view: Eclipse foundation is similar to Apache foundation for GUI tools • Platform objectives robust platform for highly integrated dev tools enable view and/or editing of any content type attract a large community of developers to develop plug-ins • Projects Application Development, editors, modeling, performance, testing, reporting, and many more © Visual Patterns, Inc. 86
Many Platforms Supported (Windows, Unix, Linux, Mac OS X…) © Visual Patterns, Inc. 87
Personal Opinion: The Java versus Microsoft Thing First exciting IDE Huge community - Plug-ins galore (thousand+) Ward Cunningham and Erich Gamma Battle of IDEs has only now begun! © Visual Patterns, Inc. 88
Eclipse Basic Concepts 1. 2. 3. 4. 5. 6. Workspace (directory of projects) Workbench Perspectives Editors and Views Project Wizards (hundreds) 7. Plug-ins (galore!) sample workspace © Visual Patterns, Inc. 89
Project/Plug-in: Java Development Tools (JDT) • • • Java views (e. g. packages, types, members) Intelligent code fix and content assist Compile during save (within the blink of an eye) Powerful debugger (than works!) Pre-configured for JUnit and Ant • Others Formatting options Powerful search Code refactoring (some based on Fowler's refactoring. com) TODO lists Scrapbook Export feature (create zip files, etc. ) © Visual Patterns, Inc. 90
JDT Features Java Browsing JUnit Java Compile Errors/Warnings Ant Assist © Visual Patterns, Inc. 91
Project/Plug-ins: Eclipse Web Tools Platform (WTP) • Tools for developing J 2 EE Web applications • Editors Source - HTML, Java. Script, CSS, JSP, SQL, XML, DTD, XSD, and WSDL Graphical - XSD and WSDL • Database access and query tools and models • Web service wizards • J 2 EE - project natures, builders, models navigator © Visual Patterns, Inc. 92
WTP Web Services Related Screens © Visual Patterns, Inc.
Other WTP Features Servers JSP Assist Database © Visual Patterns, Inc. 94
CVS (Eclipse Team Sharing) © Visual Patterns, Inc. 95
Hibernate and Spring Plug-Ins Hibernate Spring IDE © Visual Patterns, Inc. 96
Startup Time Comparison To Intelli. J and Net. Beans Intell. IJ - 1 minute, 5 seconds! Net. Beans - 42 seconds. Eclipse with JDT, WTP, Hibernate, Eclipse. . . 19 seconds! © Visual Patterns, Inc. 97
Presentation Outline Introduction to Agile Java Development Agile Processes Agile Modeling • Agile Development Environment Setup: Directory Structure, JDK, Ant and JUnit Using Hibernate For Persistent Objects The Spring Framework The Eclipse Phenomenon! Logging, Debugging, Monitoring, and Profiling • Beyond The Basics © Visual Patterns, Inc. 98
Agile Java Development: Logging, Debugging, Monitoring, and Profiling © Visual Patterns, Inc.
Quick Poll Do you use a GUI debugger? Or, a logging framework? Or, use println statements? © Visual Patterns, Inc. 100
Logging Basics and Frameworks • Types 1. Audit log 2. Tracing 3. Error reporting • Pros • No human intervention (automated) • Great for headless servers • Cons • Performance hit • Can clutter code Logging Frameworks • Alternative to println statements • Key benefit - Output control (destination, format, log level) • Most popular - Apache Log 4 J and JDK Logging • Jakarta Commons Logging -- bridge to frameworks import org. apache. commons. logging. Log; import org. apache. commons. logging. Log. Factory; public class Commons. Logging. Test { private static Log log = Log. Factory. get. Log(Commons. Logging. Test. class); } public static void main(String[] args) { log. fatal("This is a FATAL message. "); log. error("This is an ERROR message. "); log. warn("This is a WARN message. "); log. info("This is an INFO message. "); log. debug("This is a DEBUG message. "); } © Visual Patterns, Inc. 101
Headaches of Finding and Fixing Bugs! © Visual Patterns, Inc. 102
Debugging Java Code With Eclipse • Debug perspectives and views “consolidated debugging” • Breakpoints • Step through code • Variable inspection • Hotswap • Remote debugging © Visual Patterns, Inc. 103
Debugging Web User Interfaces Using Mozilla Firefox Java. Script debugger Web Developer Tamper Data © Visual Patterns, Inc. 104
Java Monitoring and Profiling • Monitoring JSE 5. 0 includes JConsole Memory issues Class loading and garbage collection Spring MBean Exporter <bean id="timex. Jmx. Bean” class= "com. visualpatterns. timex. util. Timex. Jmx. Bean" /> <bean id="exporter” class= "org. springframework. jmx. export. MBean. Exporter"> <property name="beans"> <map> <entry key="Time Expression: name=timex-stats" value-ref="timex. Jmx. Bean" /> Management of MBeans and JDK logging level, etc … • Profiling Memory usage and leaks CPU utilization Trace objects and methods Determine performance bottlenecks © Visual Patterns, Inc. 105
Presentation Outline Introduction to Agile Java Development Agile Processes Agile Modeling Agile Development Environment Setup: Directory Structure, JDK, Ant and JUnit Using Hibernate For Persistent Objects The Spring Framework The Eclipse Phenomenon! Logging, Debugging, Monitoring, and Profiling • Beyond The Basics © Visual Patterns, Inc. 106
Beyond The Basics © Visual Patterns, Inc.
Custom Tag Libraries <timex: periodcheck. Date="${command. period. Ending. Date}"> <input name="save" type="submit" value="Save"> </timex: periodcheck> public class Pay. Period. Check. Tag extends Tag. Support { public int do. Start. Tag() throws Jsp. Exception { boolean include. Text = ; // do something if (include. Text) return Tag. Support. EVAL_BODY_INCLUDE; } return Tag. Support. SKIP_BODY; © Visual Patterns, Inc. 108
Security, Reliability and Scalability Considerations © Visual Patterns, Inc. 109
Application Security Considerations • Authentication (user and application levels) • Authorization (roles, groups, etc. ) • Encryption (wire protocol, configuration files) User-level authentication & authorization Wire protocol (HTTP/S) Application-level authentication © Visual Patterns, Inc. 110
Other Considerations • Exception Handling 1. Checked exceptions (e. g. IOException) – required catch or throw 2. Unchecked exceptions (e. g. Null. Pointer. Exception) - no catch/throw needed 3. Errors (e. g. Out. Of. Memory. Error) • Clustering (serialize, no static variables, simplicity…) • Multi-threading (JDK 1. 5 concurrent API) • Rich Internet Applications (RIA) AJa. X Google Web Toolkit (GWT) - http: //code. google. com/webtoolkit/ Direct Web Remoting (DWR) - http: //getahead. ltd. uk/dwr/ Adobe Flex Java Swing and Web Start © Visual Patterns, Inc. 111
Cool Concept For Smaller Apps - Entire System In A WAR File! • • Code (source, binary) Relational database (e. g. HSQLDB) Job Scheduling More… © Visual Patterns, Inc. 112
Wrap Up! © Visual Patterns, Inc.
Presentation Outline Introduction to Agile Java Development Agile Processes Agile Modeling Agile Development Environment Setup: Directory Structure, JDK, Ant and JUnit Using Hibernate For Persistent Objects The Spring Framework The Eclipse Phenomenon! Logging, Debugging, Monitoring, and Profiling Beyond The Basics © Visual Patterns, Inc.
Constant Learning – Be a “Generalizing Specialist” © Visual Patterns, Inc. 115
Don’t Forget - Release Completion Celebration! RON STEVE © Visual Patterns, Inc. RAJ SUSAN 116
Some Near Term Plans © Visual Patterns, Inc.
Book - Released 12 th May, 2006 Agile Java Development With Spring, Hibernate and Eclipse Forewords by Scott W. Ambler and Rod Johnson available on amazon. com 1. Introduction to Agile Java Development 2. The Sample Application: An Online Timesheet System 3. XP and AMDD-Based Architecture and Design Modeling 4. Environment Setup: JDK, Ant, and JUnit 5. Using Hibernate For Persistent Objects 6. Overview of the Spring Framework 7. The Spring Web MVC Framework 8. The Eclipse Phenomenon 9. Logging, Debugging, Monitoring and Profiling 10. Beyond the Basics 11. What Next? 12. Parting Thoughts 13. 14. Appendices (with lots of goodies) © Visual Patterns, Inc. 118
Interesting Stuff At Visual. Patterns. com - Visit Site Periodically Comics Cheat Sheets R&D Concepts © Visual Patterns, Inc. 119
THE END! • • agilemodeling. com agiledata. org Stay in touch! agilemanifesto. org extremeprogramming. org Anil@Visual. Patterns. com hibernate. org springframework. org eclipse. org • code. google. com/webtoolkit/ • getahead. ltd. uk/dwr/ • Visual. Patterns. com (links, comics, code, cheat sheets…) © Visual Patterns, Inc. 120
- Slides: 120