Advanced Java Training Class - On The Edge Software Consulting

bricklayerbelchedInternet and Web Development

Feb 5, 2013 (4 years and 5 months ago)

112 views

Confidential and Proprietary

AAA NCNU © 2008, 2009

Enterprise Architecture

Java SE / Java EE Training

Awareness

M. Reha, Enterprise Architecture

2009
-
04
-
10, v0.1

2

2

Agenda



>
Course #1:


Introduction to the Java Language and the Java Platform

>
Course #2:


“Hello World” Java programming example


Encapsulation, Inheritance, Interfaces

>
Course #3:


Introduction to the Java EE Platform

>
Course #4:


“Hello World” Java EE web application programming example


Web Tier, Business/Services Tier, Persistence Tier

3

Course #1

Introduction to the Java Language and the Java Platform

4

4

Course Objectives

>
Learn about the history of Java.

>
Learn about the Java Platform.

>
Learn what the fundamentals of the Java language.





5

5

What is Java?

>
Is Java just a programming language?

>
What is the JDK?

>
What is Java Standard Edition (Java SE)?

>
What is Java Enterprise Edition (Java EE)?

>
What is the JVM?

>
What is a Java EE Application Server?

>
What is a Java Applet?

>
What is Java Swing?

>
What is a Java Portlet

>
What else?


Java ME


Java Mobile Edition (for mobile phones / devices)


Java RT


Java Real Time (for embedded real time applications)


Java TV


Java for TV (for TV and Set Top Box applications)


Java DB


Java based RDBMS


Java Card


Java for Smart Cards


Java FX


Java building next generation RIA’s





6

What is Java?

Java EE

Application Server

WebSphere, Oracle WebLogic, JBoss, etc

Java Virtual Machine (JVM)

Sun, IBM, Oracle, Apple, etc.

JDK (for SE and EE)

Compilers, tools,
documentation for the
developer

Browser

Web Pages

Portlets

Java Applet

JavaFX Applet

Java Desktop
Application

(Swing, Console,
JavaFX)

Mobile Application
and Consumer

(Java ME, JavaFX,
JavaTV)

Java EE Runtime

Implements the Java EE API’s

Java SE Runtime

Also referred to as JRE

Implements Java SE API’s

Implements Java SE for CDC

Java is a programming language!

Java used as a platform to build applications ranging from web,
desktop, mobile, and more!

Java Virtual Machine (JVM)

Nokia, Philips, Sony,

7

7

Introduction to the Java Programming Language

>
Java is a programming language originally developed by James
Gosling at Sun Microsystems and released in 1995 as a core
component of Sun Microsystems' Java platform.

>
The language derives much of its syntax from C and C++ but has
a simpler object model and fewer low
-
level facilities.

>
Java applications are typically compiled to byte
-
code that can run
on any Java virtual machine (JVM) regardless of computer
architecture.

>
The original and reference implementation Java compilers, virtual
machines, and class libraries were developed by Sun from 1995.

>
As of May 2007, in compliance with the specifications of the Java
Community Process, Sun made available most of their Java
technologies as free software under the GNU General Public
License.





8

History of the Java Platform

Java SE Platform:



JDK 1.0 released in January 1996



JDK 1.1 released in February 1997



J2SE 1.2 released in January 1998



J2SE 1.3 released in May 2000



J2SE 1.4 released in February 2002



J2SE 5.0 released in September 2004



J2SE 6.0 released in December 2006



J2SE 7.0 released in end of 2010


Java EE Platform:



Java Platform Edition JPE announced in May 1998



J2EE 1.2 released in December 1999 (peak of the .COM era)



J2EE 1.3 released in September 2001 (end of .COM era)



J2EE 1.4 released in November 2003



EE 5 released in May 2006



EE 6 scheduled release for the end of 2008 (approval of JCP specification)


Lots of enterprises are still on J2EE 1.3 from 2002!

The Portlet Specification was not released until October 2003.


We are here in 2002!


We have some ability to leverage J2SE 5.0


Java RI will be based on J2SE5.0


We are here in 2003!


Java RI will be based on EE 5

9

9

Java Language


Language Basics

>
Java is a strongly typed language. This means all variables must be declared
with a type before using.


Example: int count = 0


int is the type for a variable called count that is initialized to 0


>
Java Primitives are defined by the Java Language (and are reserved keywords)
and are very similar in
syntax

to the C/C++ programming language:


byte, short, int, long, float, double, boolean, char


There are wrapper classes for most primitive types (Integer class wraps an int)

>
Java Operators are special symbols that perform specific operations on one or
more operands (much like the C/C++ language):


++
--
, * /, >> <<, == !=, < >, & | ^, && ||

>
Java Control Flow statements for program control and decision making and are
very similar to to the C/C++ programming language:


if else, switch, while, do while, for


exception handling (not really flow control!)

10

10

Java Language


Classes and Objects

>
Java was the first Internet “aware” and Security “aware” object orientated
programming language.

>
(Almost) everything declared in Java defined by a Object implemented in a
Class. One of the first main stream object oriented languages.


Object:


An object is a software bundle of related state and behavior. Software objects are often
used to model the real
-
world objects that you find in everyday life.


Real
-
world objects share two characteristics: They all have state and behavior.


Class:


A class is a blueprint or prototype from which objects are created.


Created by using the new Java keyword. Example: ClassA a = new ClassA();


Unused classes are removed from memory via the Garbage Collector


There is (in theory) no memory management coding required by programmer

>
Classes can inherit state and behavior from other classes through Inheritance.


ClassA extends ClassB

>
Classes can define contracts with the outside world (or other classes) through
interfaces.


ClassA implements ClassB

11

11

Java Language


Runtime Library

>
A library of classes that are included as part of the Java Standard Edition which
are implemented in ALL Java Runtime distributions (IBM, Oracle/JRockit, Sun,
etc.).


>
Utility: I/O, String, Date, Time, Calendar, Internationalization, Math, Collection, …

>
Networking: HTTP, Cookies, TCP URL and Sockets, and UDP Datagrams, …

>
Database: JDBC, Prepared Statements, ResultSets, Transactions, …

>
Component Model: JavaBean, …

>
Multimedia: Sound, 2D Graphics, 3D Graphics (extension lib), …

>
User Interface: AWT, Swing, Applet, …

>
Web Services: XML, SOAP

>
Misc: JNI, JMX, RMI, Serialization, Logging, Zip, Regular Expressions, …

>
System: Threads, Concurrency (Locks, Mutex, etc), Security, JNDI, …

>
Deployment: Java Web Start, Java Plug
-
In, …


>
These are all documented in the Java Development Kit (JDK)!

12

12

Java SE 6


JDK and JRE


Image Courtesy of Sun http://java.sun.com/javase/6/docs/

13

Course #2

Example Java SE Programming

14

14

Course Objectives

>
Learn what a simple Java class looks like.

>
Learn about Encapsulation.

>
Learn about Inheritance and Interfaces.

>
Walk through a “Hello World” console application.





15

15

“Hello World” in the Java Programming Language





Object

Data / State

Behavior / Operations

HelloWorld

private String message;

private int count;

public sayHello();

Name of Object

In Java == ObjectName.java

Also known as a Class

The Objects
internal data,
attributes, or
object state

The Objects behavior,
methods, or operations

16

16

“Hello World” in the Java Programming Language





17

17

More “Hello World” in the Java Programming Language





HelloWorld

public sayLoudHellIo();

private someUtility();

Extends the behavior of
HelloWorld

private String message;


public sayHello();

private setText();

BaseHello

18

18

More “Hello World” in the Java Programming Language





19

Course #3

Introduction to Java EE

20

20

Course Objectives

>
Learn about the history of the Java EE Platform.

>
Learn about basic technologies in the Java EE Platform.

>
Learn about current trends of the Java EE Platform.





21

21

What is Enterprise Java a.k.a. Java EE?



>
Java EE defines standard API’s for building web applications.

>
Introduced right before the .COM era started.

>
The Java EE Standard is defined by Sun and the JCP.

>
There have been lots of contributions from the Open Source
Community to fill in gaps from the Java EE Standard and enrich
the capabilities for building web applications.

>
A Java EE Application Server implements the Java EE Standard
and provides a platform to execute web applications. Sometimes
the Application Server vendor “enhances” the platform by adding
value added features and capabilities such as Administration
Consoles, Debugging facilities, and Monitoring.

>
A Java EE Application Server is rapidly becoming a commodity
with a number of very robust and scalable open source
alternatives now available on the market.

22

22

Introduction to the Java EE Stack?



>
Web Tier Technologies:


Servlet


lowest level (above protocols and sockets) to handle HTTP request


Java Server Pages


markup (like HTML tags) to build dynamic pages


Java Standard Template Library


standard tags for conditional, loops, etc.


Java Server Faces


web framework (built from JSP)

>
Business/Service Tier Technologies:


Enterprise Java Bean EJB


business components


JTA


transaction API

>
Persistence Tier Technologies:


JDBC


lowest level database programming


Java Persistence API JPA


Object Relational Mapping framework

>
Integration Technologies:


Java Connector Architecture JCA


API to access legacy systems (like SAP)


Java Messaging Service JMX


send JMS messages (like MQ)


Web Services JAX
-
WS, JAX
-
B, JAX
-
R


web service stack support

23

J2EE Platform from post .COM era (2002
-
2004)

J2EE 1.3


1.4

Web

JSP

Servlet

EJB

Session

Entity

MDB

JAX
-
RPC

JAX
-
R

JAXB

JMX

JAAS

JMS

Mail

JTA

JCA

J2SE 1.3


1.4

AWT

Swing

Java 2D

Java 3D

JavaBean

JDBC

JNDI

JNI

RMI

Application Server

Containers and Services for UI, Business, Database

Security

Administration and Deployment

Value Add Services (Proprietary Frameworks etc.)


Client (mostly browser based)

Web Application

UI: HTML, CSS/DHTML, JavaScript, AJAX, Applets, Flash

Application Logic, Business Logic, Data Access Logic

Enterprise Application Integration (EAI)

Governance

Standards, Best Practices/Guidelines

Architecture Review Boards etc.


Design
Patterns

MVC

DAO

Command

Factory

Business Delegate

Business Façade

Decorator

Value Object

*

*


SDLC and Development Tools

XP, Scrum, RUP, Waterfall

Eclipse, IBM WSAD/RAD, NetBeans, JBuilder, IntelliJ

Code Analyzers (Checkstyle, FindBugs), Unit Test Frameworks (JUnit, TestNG)


Open Source

Struts 1.x (MVC)

JSTL (Tag Library)

MyFaces/Sun JSF RI

Apache Commons (Utility)

Apache Log4j (Logging)

Hibernate(Persistence)

iBatis (Persistence)

iText (PDF)

POE (MS Docs)

Quartz (Timer Service)

Castor (XML Framework)

Apache Xerces/Xalan (XML)

Apache Axis (Web Services)

SSO

OSCache/EHCache (Cache)

*


Integration/Middleware

Business Rule Engine

ETL

Messaging/MQ

FTP

Web Services

Proprietary Scripts etc.

Screen Scraping

*


Utilities and Core Services

Logging (Wrapper)

Tracing (Wrapper)

Exception Framework

Base Classes/Frameworks

Alert (like HP Open View)

Cache (Wrapper)

Static Data

Security/SSO

*


24

24

J2EE Platform Observations from 2002
-
2004



>
Leveraged lots of open source libraries to fill in the J2EE specification gaps (like Web MVC
Framework, XML, Web Services). Soon there would be competing and redundant technologies such
as XML, Web Services, Logging, etc.. The Enterprise and Application Architect definitely had their
work cut out for them. What technologies do we use?

>
Some J2EE specifications were of little value to the enterprise (for example, Entity Beans (CMP or
BMP) and Stateful EJB’s…..J2EE 1.2 only supported remote Session Beans!).

>
Enterprise Integration was tightly coupled and reuse of enterprise assets not fully thought out or
realized.

>
Application Servers often provided proprietary (and competing) technologies and frameworks
(Portlets, Web, Security, etc.).

>
Lots of programming models to learn.

>
Governance was often over looked causing lots of inconsistencies in architecture and duplication of
code/frameworks.

>
Most development methodologies were still very “water fall”. XP was just taking off.

>
Development Tools needed improving.

>
Generally there was very high TCO for 1st generation (MVC
-
1) and 2nd generation (MVC
-
2)
applications.

>
De
-
facto Standard Application Servers: WebLogic, WebSphere, and some Oracle.

>
Increasing frustration with J2EE standard (some of it was justified and some was not).

25

J2EE Web 1.5/2.0 Application Architecture (2005
-
present)

J2EE Application Server
(
now some open source)

EE 5

J2SE 5

Java, Ruby, Groovy, Python, Scala

Utilities and Core
Services

Logging/Tracing (Wrapper)

Exception Framework

Base Classes/Frameworks

Alert (like HP Open View)

Cache (Wrapper)

Static Data

Security/SSO

*


Open Source

Struts2 (MVC)

Apache Commons (Utility)

iBatis (Persistence)

iText (PDF)

POE (MS Docs)

Quartz (Timer Service)

Apache Axis (Web Services)

OSCache/EHCache (Cache)

*


Object Model


Application Domain Model



Web Application

Open JDK

Spring

DI

AOP

SpringMVC

WebFlow

Security

Presentation

HTML, CSS, JavaScript, AJAX

JSF
,
SpringMVC
,
JSP, Servlets, JSTL

Facelets
,
Seam
,
Spring WebFlow

Business

POJO (via Spring or Session)

Message Driven Beans

Timer Beans

Web Services


Data Access

JDBC, SQL, SP

JPA/Hibernate
/TopLink/iBatis

Client (not just browser based anymore)

Struts2 Framework

Rails/Grails Framework

GWT Framework

Business Rule Engine


SOA

ESB, BPM

WS
-
*

UDDI

WSDL

XML

OLTP DB

Legacy Systems

And

Legacy DB

Or DW

EAI

JCA

ETL

JMS/MQ

26

26

Observations from 2005
-
2007



>
Move away from Struts 1.x or proprietary frameworks to newer web frameworks like JSF (plus
Facelets, Seam, and Ajax4Jsf) or Struts2 or SpringMVC (with WebFlow).

>
Move toward annotation based configuration (versus mass of XML configuration files).

>
Less Open Source required (due to maturity of EE specification, Spring, and open source application
servers like JBoss, Glassfish, Tomcat 5/6). Apache Foundation, Spring, Craig McClanahan (JSF),

Rod Johnson(String/EJB3), Gavin King(Hibernate/JPA) were really influencing and pushing the
Java/J2EE platform forward.

>
Spring Framework getting lots of traction in the industry (dependency injection (simple but
powerful!), POJO based for simpler programming model, AOP (for security, transactions, tracing,
etc), wrappers for integration with EJB, WS, etc.).

>
NetBeans IDE is becoming a viable and powerful IDE (Eclipse finally has some competition). Eclipse
Foundation followed suite and also released Eclipse Europa. No need to buy a J2EE IDE now.

>
Rather then reinvent we must reuse in the Enterprise, move from vertical applications to Enterprise
wide applications => SOA and leverage full Web Service stack, ESB, BPM.

>
New EE web applications can be built much quicker and with much less code. My last project, using
JSF and Spring and iBatis, was built with 50% less code, delivered on time (actually over delivered
by adding more features requested from our customer), and was 25% under budget.

>
Google influence => Google Web Toolkit, Google Docs, Google Maps, etc.

>
Sun and Microsoft finally working together (WS
-
* in 2006) => that is a good thing for everybody!

27

Course #4

Example Java EE Programming

28

28

Course Objectives

>
Learn about the layers of a Java EE application.

>
Learn a few common/popular design patterns.

>
Walk through a “Hello World” web application.





29

29

The Layers of a Java EE Application





Browser

Desktop browser, mobile
phone, STB, TV

Client Layer

Java EE Application Layers

Presentation Layer

Creates views for
presentation, handling form
data, and navigation

JSP or Web framework
such as JSF, Struts, or
SpringMVC with HTML,
CSS, and JavaScript

Business Layer

Implements business
services and enterprise
integration services

EJB, Web Services,
Message Driven Beans,
Timer Beans, SpringBeans

Persistence Layer

Implements data persistence
services

JPA, Hibernate, iBatis,
SQL, JDBC

30

30

The Presentation Layer





>
Designed using a very popular MVC design pattern
used to build Presentation Layer.

>
Implemented by all major web frameworks.

>
Helps to enforce separation of concerns so you don’t
mix presentation logic, business logic, and persistence
logic together.

>
Used to render HTML (generally) to a browser.

>
M
odel
V
iew
C
ontroller


M
odel: data from business services to display


V
iew: views or web pages


C
ontroller: handles page events and navigation between
pages

31

31

The MVC Design Pattern Diagram 1





Enterprise Servers and Data Sources
Browser
Application Server
JSP
(
V
iew
)
JavaBean
(
M
odel
)
Response
Request
C
ontroller
Services
Forward
32

32

The MVC Design Pattern Diagram 2





Browser
JSP
(
V
iew
)
JavaBean
(
M
odel
)
Response
Request
(
POST
)
C
ontroller
Forward
Business Tier
Error JSP
System
Exception
Application
Exception
Event Handler
To Error JSP
(
from System
Exception
)
Data binding
with tag
lbrary
Include JS
,
CSS
Include Page Fragments
Request
or
Session
xhtml
xhtml
Include Tab Libs
Delegate
33

33

The Business Layer





>
Driven by your business use cases defined by your
business requirements.

>
Implements your business services.

>
Should be designed using interfaces (design by
contract).

>
Can be a façade to other enterprise services deployed
on an ESB or other SOA infrastructure.

>
Acts as façade to persistence layer or enterprise data
services.

>
Supports other responsibilities:


Transaction Management (using a service container)


Security (using a service container)


34

34

The Business Layer Diagram 1





Business Delegate
System
Exception
Application
Exception
Interface
Business Service
1
DAO
1
DAO
2
DAO
3
Service
2
Transaction Mgr
Transaction Boundary
Begin Tx
End Tx
Facade
Interface
Interface
Interface
Interface
Implemtation
Config
Business
Rules
Factory
Client
TO
TO
TO
35

35

The Business Layer Diagram 2





System
Exception
Application
Exception
Business Service
1
DAO
1
DAO
2
DAO
3
Service
2
Transaction Mgr
Transaction Boundary
Begin Tx
End Tx
Facade
Interface
Interface
Interface
Interface
Dependency
Injection
:
DAO
1
,
DAO
2
,
DAO
3
,
and
Service
1
and
2
Interface
+
Implemtation
Business
Rules
Client
TO
TO
Config
or
Annotations
Config
or
Annotations
36

36

The Persistence Layer





>
Designed using the CRUD design pattern.

>
Is simply responsible for persistence of your entity or
domain object model.

>
Should not be aware of transaction boundaries.

>
Supported today by modern Object Relational Mapping
(ORM) frameworks such as JPA, Hibernate, and iBatis.

>
C R U D

operations:


C
reate: add or insert operation


R
ead: read operation


U
pdate: update operation


D
elete: delete operation

37

37

“Hello World” Java EE Web Application





>
Can you really build a working N
-
Tier Hello World web
application in less then 10 classes?


>
Let’s go build a simple web application ………

38

38

“Hello World” Application





>
2 UI Events:


Button click handler for the ‘Test Me’ button


Button click handler for the ‘Save Me’ button

>
2 Business Use Cases:


Validate the Model


Business Rule: If Name is ‘Mark’ then Model can be persisted


Save the Model

>
Model:


Simple JavaBean that just has a Name attribute

39

39

“Hello World” Web Tier Implementation





>
View => JSF Page

>
Controller => JSF Event Handler class


The 2 UI Events are implemented in a JSF Event Handler
class


Business service is injected into this class

>
The Model => clean separation between Web
Application Model and the Domain Model, so we don’t
mix UI data with our Business data

40

40

“Hello World” Business Tier Implementation





>
Uses Stateless EJB 3.0 JavaBeans.

>
Uses Container Managed Transactions

>
DAO is injected into this class

>
Implements our 2 business use cases


Can be designed using Noun’s and Verbs discovered when
you write your use case.


Validate the Model


Validate is the verb and the Noun is Model => validate(Model)


Save the Model


Save is the verb and the Noun is Model => save(Model)

41

41

“Hello World” Data Access Tier Implementation





>
Implements standard CRUD operations via an Interface

>
Uses Stateless EJB 3.0 JavaBeans (DI issue with EE5).

>
Forces Transactions to be declared external to DAO

>
JPA support is injected into this class

>
Implements our single Update CRUD use case


42

42

“Hello World” Conclusion





>
A simple Java EE 5 web application was written using 3
implementation classes, 2 interfaces, 2 model classes, 1
Controller class, and 1 JSF page.

>
This demo application made use of EE 5 dependency
injection and container managed transactions, which
virtually eliminated the need to implement any
infrastructure classes (and lots of old design patterns).

>
This demo application could have been enhanced by
using more elaborate use of Base Classes, which you
develop as part of a standard corporate Application
Framework.

>
It really is that easy (if you are using modern technology)!

43

43

Where Can I Learn More?

>
Go to the Java TCC site to links for lots of good industry
references.

>
Go read the AAA
-
NCNU Java Standards.

>
Go read the AAA
-
NCNU Java Best Practices.

>
Get my Java EE Application Design Template.

>
Get the Java Reference Implementation.

44

Appendix

45

45

References

Anonymous. 2009. Wikipedia. Retrieved April 10, 2009


from http://www.wikipedia.com


Sun Java Tutorials, Retrieved May 14, 2009


from http://java.sun.com/docs/books/tutorial/java/concepts/index.html