Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE...
Transcript of Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE...
![Page 1: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/1.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 1
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Ease of Development in theJava™ Platform, EnterpriseEdition 5
Roberto ChinniciSenior Staff Engineer
Sun Microsystems, Inc.
![Page 2: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/2.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 2
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Contents
Why the focus on Ease of Development?
The challenge
The solution
Selected examples from Java™ Platform,
Enterprise Edition 5 (“Java™ EE 5”)
Are we done?
![Page 3: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/3.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 3
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Caveat
All new Java™ API go through the Java
Community Process
Java™ EE 5 is not final yet
Anything you see here may still change
On the plus side, if you send us your
feedback,it may change the way YOU want!
![Page 4: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/4.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 4
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Why Ease of Development?
People get used to the most amazing things
Still, we have to admit too much is too much
For the longest time, we said that bettertools were the answer
Isn't it better to have great tools and an easyto understand technology?
![Page 5: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/5.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 5
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
You Know You Have a ProblemWhen...
A beginner Enterprise JavaBeans™ (EJB)
programmer runs intoPortableRemoteObject.narrow on day one
Long JNDI names have to be kept in sync inthree places – and what's with the
“comp/env”?
The HelloWorld web service takes 80 lines and
3 deployment descriptors to work
![Page 6: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/6.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 6
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Goals
Make Java™ EE programming easier to learn
Improve developer productivity
Enable better tools
Attract new developers to Java™ EE
Expand the Java™ EE market
![Page 7: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/7.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 7
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Developer Segmentation
Content
}}}
Enterprise
Corporate
(n tier)
CompositeModeling &Integration
TransactionalBusiness
Logic (3 tier)
Applications:data access + webservices (2 tier)
Applicationswith data access
Web pages:+ dynamic content
Web pages
AppComplexity
![Page 8: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/8.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 8
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Why Is It So Challenging?
It's hard to make something simpler by
adding things to it
Yet compatibility with J2EE™ 1.4 is essential
All existing applications must still run
Moreover, migration to the new technologies
should be as painless as possible
![Page 9: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/9.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 9
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Some of the Complaints
Very powerful, but complex to use
Too many classes, interfaces
JNDI lookups everywhere
Checked exceptions galore
Deployment descriptors
Entity beans
![Page 10: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/10.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 10
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Tools at Our Disposal
New language features
Annotations, generics
Better understanding of how components inthe platform are used
e.g. No scriptlets, no remoting for entity beans
Guideline: “make simple things easy,complex things possible”
80-20 rule
![Page 11: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/11.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 11
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Sometimes Tools Bite Back
List<E>.iterator() returns Iterator<E>
List<E>.addAll(Collection<? Extends E>)
Class Enum<E extends Enum<E>>
Set<Entry<? extends String, ? extends Object>> props = map.entrySet();
found: java.util.Set<java.util.Map.Entry<capture of ? extendsjava.lang.String,capture of ? extends java.lang.Object>>
required: java.util.Set<java.util.Map.Entry<? extends java.lang.String,?extends java.lang.Object>>
Good
Bad
![Page 12: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/12.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 12
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
The Approach We Took
POJO-based programming
More freedom, fewer requirements
Extensive use of annotations
Reduced need for deployment descriptors
Lots of defaults
Dependency Injection for resources
Inversion of control
New APIs and frameworks when needed
![Page 13: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/13.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 13
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Benefits to Beginners
Java™ EE programming closer to the SE
model
More intuitive programming model
Less to be learnt on day one
Hide creation/lookup of resources
What you need (e.g. database) is “right there”
Reduce references to “hard” APIs
Code is more readable
![Page 14: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/14.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 14
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Benefits to Intermediate/Experts
Build on existing knowledge
Less boilerplate code
Focus on what is important
Fewer mandated interfaces = more freedom
More uniformity across the platform
Easier to create unit tests
![Page 15: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/15.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 15
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Big Ticket Items
Simplified component model
EJB 3.0 session beans
New unified object persistence
EJB 3.0 entities
New web services stack:
JAX-WS 2.0, JAXB 2.0, JSR-181, JSR-109.next
JavaServer™ Faces 1.2 and JSTL 1.2 now
standard in the platform
![Page 16: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/16.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 16
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 2.1 vs 3.0
Examples
![Page 17: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/17.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 17
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 2.1 Session Bean
public class PayrollBeanimplements javax.ejb.SessionBean {
SessionContext ctx;DataSource empDB;
public void setSessionContext(SessionContext ctx) {this.ctx = ctx;
}
public void ejbCreate() {Context initialContext = new InitialContext();empDB = (DataSource)initialContext.lookup(
“java:comp/env/jdbc/empDB”);}
![Page 18: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/18.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 18
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 2.1 3.0 Session Bean@Statelesspublic class PayrollBeanimplements javax.ejb.SessionBean {
@Resource SessionContext ctx;@Resource DataSource empDB;
public void setSessionContext(SessionContext ctx) {this.ctx = ctx;
}
public void ejbCreate() {Context initialContext = new InitialContext();empDB = (DataSource)initialContext.lookup(
“java:comp/env/jdbc/empDB”);}
![Page 19: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/19.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 19
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 2.1 Session Bean (Continued)
public void ejbActivate() {}public void ejbPassivate() {}public void ejbRemove() {}
public void setBenefitsDeduction(int empId,double deduction) {
...Connection conn = empDB.getConnection();...}
...}
![Page 20: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/20.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 20
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 2.1 3.0 Session Bean (Continued)
public void ejbActivate() {}public void ejbPassivate() {}public void ejbRemove() {}
public void setBenefitsDeduction(int empId,double deduction) {
...Connection conn = empDB.getConnection();...}
...}
![Page 21: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/21.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 21
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 2.1 Session Bean (Continued)<session>
<ejb-name>PayrollBean</ejb-name>
<local-home>PayrollHome</local-home>
<local>Payroll</local>
<ejb-class>com.example.PayrollBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref>
<res-ref-name>jdbc/empDB</res-ref-name>
<res-ref-type>javax.sql.DataSource</res-ref-type>
<res-auth>Container</res-auth>
</resource-ref>
</session>
...
<assembly-descriptor>...</assembly-descriptor>
![Page 22: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/22.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 22
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 2.13.0 Session Bean (Continued)<session>
<ejb-name>PayrollBean</ejb-name>
<local-home>PayrollHome</local-home>
<local>Payroll</local>
<ejb-class>com.example.PayrollBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref>
<res-ref-name>jdbc/empDB</res-ref-name>
<res-ref-type>javax.sql.DataSource</res-ref-type>
<res-auth>Container</res-auth>
</resource-ref>
</session>
...
<assembly-descriptor>...</assembly-descriptor>
![Page 23: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/23.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 23
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Dependency Injection
Applies to all container-managed objects
Class-, field- or method-based
Marked using:
@Resource, @EJB, @WebServiceRef
Common elements:
name, type, description, mappedName
Plus type-specific ones:
authenticationType, beanName, wsdlLocation, ...
![Page 24: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/24.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 24
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Resolving Dependencies – Beforetry {Context initial = new InitialContext();
Object objref = initial.lookup("java:comp/env/ejb/Request");
RequestHome home = (RequestHome)PortableRemoteObject.narrow(objref,
RequestHome.class);Request request = home.create();
// ... use the request bean ...
} catch (NamingException ex) {// ...
} catch (CreateException ex) {// ...
}
![Page 25: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/25.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 25
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Resolving Dependencies – Now
@EJB Request request;
![Page 26: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/26.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 26
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Behind the Scenes
Resource type inferred from the field type
JNDI name defaulted
Automatic resolution of EJB link based ontype
Injection happens at construction time
Exceptions prevent the component from
being constructed
If any of these assumptions are invalid,
developer can take control
![Page 27: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/27.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 27
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Why Three Kinds of Injection?
Good reasons for all of them
Class: declare a resource but don't inject it
@Resource(type=EntityManager.class)
class MyManagedBean { ... }
Method: need to initialize the resource
@Resource void setDB(DataSource mydb) { ... }
Field: reasonable default
@Resource(name=”jms/airline/queue”)
Queue myQueue;
![Page 28: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/28.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 28
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Lifecycle Events – On Demand
@Statelesspublic class PayrollBean {
@Resource SessionContext ctx;@Resource DataSource empDB;
public void ejbCreate() {}public void ejbActivate() {}public void ejbPassivate() {}public void ejbRemove() {}
@PostConstructvoid initialize() { ... }
}
![Page 29: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/29.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 29
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 2.1 Transaction Attributes
<container-transaction><method><ejb-name>PayrollBean</ejb-name><method-intf>Local</method-intf><method-name>setBenefitsDeduction</method-name><method-params><method-param>int</method-param><method-param>double</method-param></method-params></method><trans-attribute>Required</trans-attribute></container-transaction>
![Page 30: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/30.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 30
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 3.0 Transaction Attributes
@TransactionAttribute(MANDATORY)public void setBenefitsDeduction(int empId,
double deduction) { ... }
![Page 31: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/31.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 31
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
EJB 3.0 Entities
Concrete classes, no required interfaces
Support inheritance
Usable in “detached” mode, replacing theData Transfer Object (DTO) antipattern
Created via an EntityManager
“Home” for all entities in a persistence unit
Also factory for Query objects
Usable on Java™ EE and Java™ SE
![Page 32: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/32.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 32
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Quick Check
We got rid of:
Deployment descriptors
JNDI lookups
PortableRemoteObject.narrow
Several try/catch blocks
Boilerplate ejbXYZ() methods
DTOs
Session vs. entity bean dilemma
![Page 33: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/33.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 33
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
What Happened to DDs?
Deployment descriptors optional
Format similar to previous version
Ease of migration
New elements for injection, etc.
“Full” bit for descriptors that capture all the
information for a module
Think of it as “compiling annotations”
![Page 34: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/34.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 34
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Descriptors Are Optional
Still useful for assembler, deployer
In general, descriptors override annotations
Made distinction between overridable andnon-overridable annotations
e.g. Cannot make a session bean into an entity
Some descriptors were not brought forward
e.g. jaxrpc-mapping-info.xml
![Page 35: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/35.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 35
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Web Services
Examples
![Page 36: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/36.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 36
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JAX-RPC 1.1 WebService
public interface HelloService extends Remote {public String sayHello(String name) throws RemoteException;
}
public class HelloServiceBean implements SessionBean {public String sayHello(String name) {return "Hello "+ name + " from HelloServiceBean";
}public HelloServiceBean() {}public void ejbCreate() {}public void ejbRemove() {}public void ejbActivate() {}public void ejbPassivate() {}public void setSessionContext(SessionContext sc) {}
}
![Page 37: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/37.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 37
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JAX-WS 2.0 WebService
public interface HelloService extends Remote {public String sayHello(String name) throws RemoteException;
}
@WebService @Statelesspublic class HelloServiceBean implements SessionBean {public String sayHello(String name) {return "Hello "+ name + " from HelloServiceBean";
}public HelloServiceBean() {}public void ejbCreate() {}public void ejbRemove() {}public void ejbActivate() {}public void ejbPassivate() {}public void setSessionContext(SessionContext sc) {}
}
![Page 38: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/38.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 38
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – Descriptors
<?xml version='1.0' encoding='UTF-8' ?><webservices xmlns='http://java.sun.com/xml/ns/j2ee'version='1.1'><webservice-description><webservice-description-name>HelloService</webservice-description-name><wsdl-file>WEB-INF/wsdl/HelloService.wsdl</wsdl-file><jaxrpc-mapping-file>WEB-INF/HelloService-mapping.xml</jaxrpc-mapping-file><port-component xmlns:wsdl-port_ns='urn:HelloService/wsdl'><port-component-name>HelloService</port-component-name><wsdl-port>wsdl-port_ns:HelloServiceSEIPort</wsdl-port><service-endpoint-interface>endpoint.HelloServiceSEI</service-endpoint-interface><service-impl-bean><servlet-link>WSServlet_HelloService</servlet-link>
</service-impl-bean></port-component>
</webservice-description></webservices>
<?xml version='1.0' encoding='UTF-8' ?><configuration
xmlns='http://java.sun.com/xml/ns/jax-rpc/ri/config'><service name='HelloService'
targetNamespace='urn:HelloService/wsdl'typeNamespace='urn:HelloService/types'packageName='endpoint'>
<interface name='endpoint.HelloServiceSEI'servantName='endpoint.HelloServiceImpl'>
</interface></service>
</configuration>
JAX-RPC 1.1 JAX-WS 2.0
![Page 39: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/39.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 39
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Simplified!
No need to define an interface
No more RMI-like markers
No more generated stubs, ties
Annotations used to customize WSDL
mapping
No mapping file needed
Data binding done by JAXB 2.0
No webservices.xml descriptor needed
@WebService annotation declares an endpoint
![Page 40: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/40.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 40
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – Web Service
@WebService(name=”CreditRatingService”,targetNamespace=”http://example.org”)
@Statelesspublic class CreditRating {
@WebMethod(operationName=”getCreditScore”)public Score getCredit(@WebParam(name=”customer”)
Customer c) {...}}
![Page 41: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/41.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 41
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Web Service Packaging
WSDL is optional
If missing, generated at deployment time
No need for a descriptor to point to the WSDL:
@WebService(wsdlLocation=”META-INF/wsdl/my.wsdl”)
public class PayrollService { ... }
Within an EAR file, web service clients andendpoints are tied together by qualified name
No more port-component/ejb-link elements
![Page 42: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/42.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 42
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JAX-RPC 1.1 Client
try {Context ic = new InitialContext();MyHelloService myHelloService = (MyHelloService)ic.lookup("java:comp/env/service/MyJAXRPCHello");
HelloIF helloPort = myHelloService.getHelloIFPort();
// ... use the service ...
} catch (NamingException ex) {// ...
} catch (RemoteException ex) {// ...
}
![Page 43: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/43.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 43
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JAX-WS 2.0 Client
@WebServiceRefMyHelloService helloService;
HelloIF helloPort = myHelloService.getHelloIFPort();
@WebServiceRef(MyHelloService.class)HelloIF helloPort;
Inject a service reference:
Or inject a port reference directly:
![Page 44: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/44.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 44
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JAX-RPC 1.1 Client (SE)
try {ServiceFactory factory = ServiceFactory.newInstance();MyHelloService myHelloService =factory.loadService(MyHelloService.class);
HelloIF helloPort = myHelloService.getHelloIFPort();
// ... use the service ...
} catch (ServiceException ex) {// ...
} catch (RemoteException ex) {// ...
}
![Page 45: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/45.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 45
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JAX-WS 2.0 Client (SE)
MyHelloService myHelloService = new MyHelloService();HelloIF helloPort = myHelloService.getHelloIFPort();
// ... use the service ...
![Page 46: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/46.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 46
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
JAXB 2.0
Supports all of XML Schema
No need to drop down to DOM
Can use complex, industry-standard schemas
directly
Class-first model in addition to schema-first
Integrated with JAX-WS 2.0
Generated code is portable
Structural mapping captured in annotations
![Page 47: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/47.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 47
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JAXB 2.0
Source code
@XmlType
public class Trade {
@XmlElement(
name=”tickerSymbol”)
public String symbol;
@XmlAttribute
int getQuantity() {...}
void setQuantity() {...}
}
XML Schema
<complexType name=”trade”>
<sequence>
<element name=”tickerSymbol”
type=”xs:string”/>
</sequence>
<attribute name=”quantity”
type=”xs:int”/>
</complexType>
![Page 48: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/48.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 48
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
RESTful Web Service ClientJAXBContext jc = JAXBContext.newInstance("com.acme.foo");Service svc = Service.create(serviceName);svc.addPort(portName, HTTP_BINDING, address);Dispatch<Object> d = svc.createDispatch(
portName,jc,Service.Mode.MESSAGE);
AcmeFooRequest request = new AcmeFooRequest();
// ... stuff some data into the request ...
AcmeFooResponse response = (AcmeFooResponse)d.invoke(request);
// ... process the response ...
![Page 49: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/49.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 49
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Other Technologies
Examples
![Page 50: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/50.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 50
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Injection Available Everywhere
EJB container
Beans, interceptors, handlers
Web container
Servlets, servlet filters, event listeners
Tag handlers, tag library event listeners
Managed beans
JAX-RPC/JAX-WS endpoints, handlers
Client
Main class, login callback handler
![Page 51: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/51.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 51
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
JavaServer™ Faces 1.2
UI component model using familiar patterns
Tool-friendly
Logic mostly in managed beans
Plain JavaBeans™ objects
Instantiated on-demand
With injection, even simpler to write!
Next version will use annotations to declare
beans
![Page 52: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/52.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 52
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – Managed Bean Config
<managed-bean><!-- Customer Bean created on demand --><managed-bean-name>logonBean</managed-bean-name><managed-bean-class>mypackage.LogonBean</managed-bean-class><managed-bean-scope>request</managed-bean-scope><managed-property><property-name>creditLimit</property-name><value>#{initParam.defaultCreditLimit}</value></managed-property></managed-bean>
![Page 53: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/53.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 53
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
JDBC 4.0
Not part of Java™ EE 5, but available when
running on Mustang (Java™ SE 6)
Introducing DataSet:
Type-safe view of the result of a SQL Query
Used with user-defined data classes and query
objects
Can be connected or disconnected
Akin to ResultSet, CachedRowSet
Big improvement in ease of use
![Page 54: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/54.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 54
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JDBC 3.0
String query = "SELECT NAME, PRICE FROM COFFEES";ResultSet rs = stmt.executeQuery(query);while (rs.next()) {String s = rs.getString("NAME");float n = rs.getFloat("PRICE");System.out.println(s + " " + n);
}
![Page 55: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/55.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 55
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JDBC 4.0
public class CoffeeInfo {String name;float price;
}
public class CoffeeQuery {@Query("SELECT NAME, PRICE FROM COFFEES")DataSet<CoffeeInfo> getAllInfo();
}
CoffeeQuery q = con.createQueryObject(CoffeeQuery.class);DataSet<CoffeeInfo> data = q.getAllInfo();for (info : data) {System.out.println(info.name + " " + info.price);
}
![Page 56: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/56.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 56
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Scripting in the Java™ Platform
JavaScript support in Java™ SE 6
Optional web container API
Many languages potentially available:
JavaScript
Groovy, BeanShell
Jython, JRuby
PHP
Mix scripting and Java™ components
![Page 57: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/57.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 57
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Example – JavaScript “servlet”
// hello script
response.setContentType("text/html");writer = response.getWriter();writer.println("<html><head><title>Hello</title></head>” +
“<body>Hello!</body></html>");
![Page 58: Colorado Software Summit: October 23 – 28, 2005 ... · Benefits to Beginners Java™ EE programming closer to the SE model More intuitive programming model Less to be learnt on](https://reader031.fdocuments.us/reader031/viewer/2022013023/5fcdb96417f2b85ea044d13c/html5/thumbnails/58.jpg)
Roberto Chinnici – Ease of Development in the Java™ Platform, Enterprise Edition 5 Page 58
Colorado Software Summit: October 23 – 28, 2005 © Copyright 2005, Sun Microsystems, Inc.
Summary
Java™ EE is becoming easier
No silver bullet
Pick our battles
Coordinate across multiple JSRs
Still room for improvement, in Java™ EE 5
we focused on key areas
Ease of development not a one-time effort