Introduction to Java EE 5 Technology

Java EE 5 Tutorials

NetBeans IDE 6.0 has been developed in close cooperation with the Java EE and Glassfish teams to provide the tightest integration and easiest possible use of the Java EE 5 specification. NetBeans IDE 6.0 is the best way to quickly learn and become productive in Java EE 5 programming.

This document provides an introduction to the major concepts of the Java EE 5 specifications and how they relate to your hands-on programming. The following topics are covered:

You can find more information about developing and deploying Java EE 5 applications on the Sun Java System Application Server Platform Edition 9 in the Java EE 5 Tutorial.

Annotations Instead of Deployment Descriptors

The Java EE 5 platform simplifies deployment by removing the need for deployment descriptors, except for the deployment descriptor required by the servlet specification, the web.xml file. Other deployment descriptors, such as ejb-jar.xml and entries related to web services in web.xml, are obsolete. J2EE 1.4 deployment descriptors were often complex and it was easy to make mistakes in filling them out. Instead, the Java EE 5 platform makes use of "annotations". Annotations are Java modifiers, similar to public and private, that you specify in your code. For example, the EJB 3 specification, which is a subset of the Java EE 5 specification, defines annotations for the bean type, interface type, resource references, transaction attributes, security, and more. A similar set of annotations is provided for web services by the JAX-WS 2.0 specification. Some annotations are used for generating artifacts. Other annotations are used for documenting your code. Still others provide enhanced services such as security or runtime-specific logic. In summary, the Java EE 5 platform provides annotations for the following tasks, among others:

Annotations are marked with a @ character. In the IDE, when you create a type that makes use of annotations in Java EE 5, related placeholders are provided in the generated code. For example, when you use the IDE to create a stateless session bean, the following code is generated, which includes the @Stateless() annotation:

package mypackage;

import javax.ejb.*;

public class HelloWorldSessionBean implements mypackage.HelloWorldSessionLocal {

Code completion provides access to annotation attributes specific to the item under the cursor. For example, when you press Ctrl-Space in the brackets of a @WebService() annotation, you see the following: annotation in ws

Each attribute has default values. Therefore, you do not need to specify any attributes unless you want to use a value other than the default value. In simple cases, the default value is sufficient, which means that you do not even need to provide attributes at all.

Simplified EJB Software Development

The new EJB 3.0 API makes software development easier by reducing and simplifying the amount of work required from the developer. In other words, fewer classes and less code. This is possible because more of the work is now performed by the container. Here are some of the features and benefits of the new EJB 3.0 API:

In the IDE, you can code enterprise beans just as you would code other Java classes, using code completion and editor hints to implement the correct methods and keep the classes in synch with their interfaces. You do not need to use special commands and dialog boxes to generate things like business methods or web service operations, although the commands are still available to help acquaint you with the syntax of Java EE 5 code.

Use Dependency Injection to Access Resources

Dependency injection enables an object to use annotations to request external resources directly. This results in cleaner code because you no longer need to clutter your code with resource creation and lookup code. You can use resource injection in EJB components, web containers, and clients.

To request injection of a resource, a component uses the @Resource annotation or, in the case of some specialized resources, the @EJB and @WebServiceRef annotations. Resources that can be injected include:

In the IDE, the Source Editor provides full code completion for resources injection annotations provided by the Java EE 5 platform. In addition, the IDE automatically injects resources into your files when you run commands like Call EJB and Use Database.

Java Persistence API Model

The Java EE 5 platform introduces the new Java Persistence API, which was developed as part of JSR-220. The Java Persistence API can also be used outside of EJB components, for example, in web applications and application clients, and also outside the Java EE platform, in Java SE applications.

The Java Persistence API has the following key features:

The IDE provides tools to work with the new Java Persistence API. You can generate entity classes automatically from a database, or code entity classes by hand. The IDE also provides templates and graphic editors for creating and maintaining persistence units.

Web Services

In the Java EE 5 platform, the use of annotations has greatly improved and simplified web services support. The following specifications contributed to this area: JSR 224, Java API for XML-Based Web Services (JAX-WS) 2.0; JSR 222, Java Architecture for XML Binding (JAXB) 2.0; and JSR 181, Web Services Metadata for the Java Platform.

JAX-WS 2.0

JAX-WS 2.0 is the new API for web services in the Java EE 5 platform. As a successor to JAX-RPC 1.1, JAX-WS 2.0 retains the natural RPC programming model while improving on several fronts: data binding, protocol and transport independence, support for the REST style of web services, and ease of development.

A crucial difference from JAX-RPC 1.1 is that all data binding has now been delegated to JAXB 2.0. This allows JAX-WS-based web services to use 100 percent of XML Schema, which results in improved interoperability and ease of use. The two technologies are well integrated, so users no longer have to juggle two sets of tools. When starting from Java technology classes, JAXB 2.0 can generate XML Schema documents that are automatically embedded inside a Web Service Description Language (WSDL) document, saving users from performing this error-prone integration manually.

Out of the box, JAX-WS 2.0 supports the SOAP 1.1, SOAP 1.2, and XML/HTTP protocols. Protocol extensibility has been a goal from the very beginning, and JAX-WS 2.0 allows vendors to support additional protocols and encodings for better performance -- for example, the FAST Infoset -- or for specialized applications. Web services that use attachments to optimize the sending and receiving of large binary data can take advantage of the MTOM/XOP (short for message transmission optimization mechanism/XML-binary optimized packaging) standard from W3C without any adverse effect on the programming model. (See this page for information on MTOM/XOP.) Before Java EE 5 technology, defining a web service required long, unwieldy descriptors. Now it's as easy as placing the @WebService annotation on a Java technology class. All the public methods on the class are automatically published as web service operations, and all their arguments are mapped to XML Schema data types using JAXB 2.0.

Asynchronous Web Services

Because web service invocations take place over a network, such calls can take unpredictable lengths of time. Many clients, especially interactive ones such as JFC/Swing-based desktop applications, experience serious performance degradation from having to wait for a server's response. To avoid such performance degradation, JAX-WS 2.0 provides a new asynchronous client API. With this API, application programmers no longer have to create threads on their own. Instead, they can rely on the JAX-WS runtime to manage long-running remote invocations for them.

Asynchronous methods can be used in conjunction with any WSDL-generated interfaces as well as with the more dynamic Dispatch API. For your convenience, when importing a WSDL document, you can require asynchronous methods to be generated for any of the operations defined by the web service.

There are two usage models:

Note that asynchronous invocation support is entirely implemented on the client side, so no changes are required to the target web service.

The IDE provides tools to work with JAX-WS. You can use templates in the New File wizard to generate JAX-WS artifacts. Asynchronous web services can be created by means of a Web Service Customization editor. The code completion functionality includes annotations that you can use in your web services.

Send Us Your Feedback

Next Steps

For more information about using NetBeans IDE 5.5 to develop Java EE applications, see the following resources:

To send comments and suggestions, get support, and keep informed on the latest developments on the NetBeans IDE Java EE development features, join the mailing list.