Advertisment

Java for Web Services

author-image
PCQ Bureau
New Update

Web services is the latest technology for software and service delivery across the Internet. No doubt, Web service has made its debut in a big way. For instance, the Web services offered by Google (to search the web pages indexed by the engine itself) and Amazon.com (to write customized applications that can browse or search the details of the products such as books, without going to the site). With sites like these adopting Web services, it seems Web services do hold some promises in practice. For more on Web services, refer to Web Services (on page 56) in the April 2003 magazine issue of

PCQuest. 

Advertisment

Java has been a popular platform and language to develop Web-based or Internet applications. It became well-liked with the arrival of Applets. Since then, Java’s development kit and library classes are constantly upgraded for the latest in Web and Internet technologies. Java Web Service Development Kit (JWSDK), available for free download, is a one-stop software development kit for coding, deploying and testing Web services. Web services can be coded in languages such as C, C++, Visual Basic and C#. So before we jump into coding a Web service in Java, let us see the pros of Java that makes it more suitable for developing Web services than others. 

Java Web Services in Action

Client

Side

Server side

Cost: The factor



3After hit by the IT slump, companies are (and should be) careful about their investments in IT. This is the main reason why Linux, open source and free software are in limelight. Web services are based on the client-server model. The server part of the Web services may require a server grade OS. You can save money by going for free OS like Linux and FreeBSD. These OS are not plagued by per-user or per-connection licensing. Java Runtime Environment (JRE, also called. Java Virtual Machine) and Java development kits are available for these platforms. JRE and the development kits are free to download, development and deployment. Hence, Java coupled with free OS provides a free software platform for Web services. Note that you can code the Web service client in your preferred language and platform. The client can seamlessly interact with the server component written in Java. 

Advertisment

Now lets consider a real life example: One of the companies we know, is in the process of migrating the server component of their existing product running on a Windows server to a Linux server. The component, which has been coded in Visual C, is very performance efficient. The reason they want to migrate to Linux is to save the licensing fees for Windows servers. Also, they don’t want their customers in-turn to pay for the OS besides the cost of their product. Last but not the least, they have chosen Java to code the server component for Linux. 

Platform Independence



Though claimed, but we have seen that Java is not 100% platform independent. Sometimes tweaking is required on a particular platform. But this is mostly in case of applications with graphical user interface. We haven’t gone across a bare-bone command line application, a Java Servlet or a JSP, which needs to be modified to run across platforms (unless one deliberately uses some platform specific features). Hence, it is a good idea to code the server component of Web services in Java. Down the line you can switch across platforms without hindrances. 

Mobile/Embedded clients



Web services can be consumed by desktop machines or workstations and mobile/embedded devices. This requires the Web service client to be running on the device. Java enabled mobiles, PDAs and embedded devices have made their opening in the market. Vendors like Nokia, Samsung and Motorola are offering Java enabled cell phones and PDAs. Since there are more variants in embedded and mobile devices than PC or server platforms, it makes sense to code the client component in Java. A Java client will be more portable across these devices than the client written in any other language. Java 2 Micro Edition development kit provides the SDK, libraries, emulators and a small footprint virtual machine to develop and test applications for mobile/embedded devices. 

Advertisment

Choice of databases



Web services can be used more for B2B (Business to Business) kind of services. Transaction between businesses would be data intensive. Through the JDBC (Java DataBase Connectivity) technology, a Java Web service can connect to any database, which stores business related data. JDBC drivers are available (free and paid) for all popular databases. Some

databases like Oracle and DB2 come bundled with JDBC drivers. 

Choice of application servers



For easy maintenance and upgradation of large applications, it is recommended to code the application as per the three-tier model. This model suggests to separate the presentation (user interface), business logic (processing) and backend (database).

Web services may be used for large applications and they may interact with databases too. They fit in the middle tier of the model. 

Advertisment

Use of application servers help to realize the three-tier model. They can host one or more of the tiers and also facilitate easy communication between them. With Java, you have a choice of application servers. To name a few: IBM WebSphere, Oracle Application Server, BEA WebLogic, Macromedia JRun and Sun ONE Application Server. Also available for free is Tomcat that can run on Windows as well as Linux/Unix platforms. It can further contribute to reduce the cost. 

Web services and J2EE



Web services are part of the latest specifications for Java 2 Enterprise Edition (J2EE). This specification essentially lays out the guidelines to code enterprise applications in Java. It proposes various Java technologies to realize the three-tier model of application development. Web services can leverage the existing J2EE technologies such as JSPs, servlets, JavaBeans, EJBs (Enterprise JavaBeans) and JDBC 

With the backing of IBM and Apache, Java Web services stand a good chance to be well-liked. Also to be seen is how Java IDEs, such as JBuilder and Sun One Studio, ease down the development of Web services over the years. After all, success of a technology largely depends on the ease of use of tools that help to implement it. Some of early surveys have shown that Java is preferred for Web services as opposed to other languages or platforms such as MS.Net. Surveys done a couple of month’s later say that .Net is catching up but Java is still ahead. Irrespective of the ongoing debates and surveys, there would be no surprises if you would like to go for Java Web services only because of the cost factor. Next month, we will write a single Web service in Java.

Shekhar Govindarajan

Advertisment