FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Java
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
TABLE OF CONTENTS
December 11, 2006

Java SE 6 Hits the Streets

(Page 2 of 3)

Web Services

One of the biggest new features of Java SE 6 is the built-in support for web services. This release introduces JAX-WS version 2.0, which includes the Java API for XML Web Service (JAX-WS), the SOAP with Attachments API for Java (SAAJ), and web services metadata (the javax.jws package). These enhancements make it easier than ever to build web services with Java. For instance, the following class translates into a SOAP-enabled web services:

package salestax;

import java.util.*;
import javax.jws.WebService;

@WebService

public class SalesTax {
    private HashMap taxTable = new HashMap();
    public double getFinalPrice(String state double price) 
    {
        double tax = taxTable.get(state).doubleValue();
        price += (price * (tax/100));
        return price;
    }
    public void static main(String[] args)
    {
        Javax.xml.ws.Endpoint.publish(
           "http://localhost:8080/salesTaxService", new SalesTax);
    }
}

To use this service from a Java application, the code looks like the following:

public static void main(String[] args) 
{
    try { 
        // Call Web Service 
        ws.salesTaxService taxService =
          new ws.salesTaxService();
        
        ws.SalesTax port = service.getSalesTaxPort();
        
        double price = port.getFinalPrice("New York", args[0]);
        System.out.println("Final price = " + price);
    } 
    catch (Exception ex) {
        ex.printStackTrace();
    }
}


The addition of JSR-223 adds scripting support to the Java platform. Jave SE 6 is the first release of Java that includes built-in JavaScript support with the Rhino JavaScript engine. The scripting language framework allows your Java code to load and execute scripts, and inversely allows script code to access and execute Java classes. This marriage of Java and scripting enables you to choose the right tool for the right job. For instance, if you're more comfortable using Perl for string manipulation, you can do so right from within your Java code. Additionally, if you're using a Ruby framework to build a web application, you can use Java's new JDBC 4 support by calling Java classes from Ruby. Java SE 6 includes an API to easily plug new script engines into Java.

The JavaDB

Standard Java now ships with an enterprise database called JavaDB. Built on Apache Derby, the version of JavaDB that ships with Java SE 6 includes a complete JDBC version 4 driver for the best in Java/database integration and performance. Although the feature set is the same, the version of JavaDB that ships with Java EE does not include the new JDBC 4 driver and associated internal engine tweaks.

The version of NetBeans 5.5 currently available provides full support for Java SE 6 and its new features. In fact, there are tools and wizards that make building and using web services even easier than the example above. You can try this for yourself at netbeans.org.

Previous Page | 1 Introduction | 2 Web Services | 3 Conclusion Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK