Knowing Why Java and XML Mesh
Java and XML are the foundations of a new generation of applications and Web services. In case you're not convinced that both XML and Java enjoy cross-platform portability, look over these facts about the two technologies:
- In its brief lifetime, XML has become the worldwide standard for representing structured, self-describing data.
- The XML registry lists more than a hundred XML data formats, including ones for financial data, health care, arts and entertainment, human resources, multimedia, and many other domains. The XML standard encapsulates almost any kind of data in a way that's flexible, extensible, and easy to maintain.
- Java runs as bytecode on a virtual machine.
- A "compiled" Java class file that runs on Windows runs the same way on Linux, on Macintosh, or on whatever platform supports the Java Virtual Machine.
- With Java, there's no such thing as platform-specific code. When you go from a .java source file to a .class bytecode file, you don't lose portability. To run the .class file, all you need is an operating system that can support a Java Virtual Machine. And versions of the Java Virtual Machine are available for at least 20 different operating systems.
- Java is based on object-oriented programming technology.
- Java code is reusable. You can call methods from existing classes, extend classes, or stretch and bend classes to meet your specialized needs. If someone writes a wonderful XML-handling package in Java, and the package has bits and pieces that you can use in your own work, you can import the package and extend the classes to solve exactly the problems that you need to solve.
- This cooperative model works both ways. When you create a package for your own anticipated needs, other developers can adopt your package, enhance your package, and spread the good word about your code.
Taken together, these factors eventually ensure that software written in one environment can run in all other environments. Instead of reinventing the wheel, programmers reuse the wheel. This ideal — the seamless integration of parts from many sources to build large, reliable software systems — has been the Holy Grail of computing for the past several decades. Now portable code and portable data put the ideal within reach.
Java and XML work well together. Taken together, Java and XML form the virtual equivalent of a well-oiled machine. Much of the code created for processing XML is written in Java. There are no hard statistics to prove this, but one XML Web site showed references to 79 utilities, of which 10 were written in C++, 7 were written in Python, 6 were written in Perl, and 9 were written in other non-Java languages. A whopping 47 utilities were written in Java. Clearly the XML developer community has an investment in Java — for many good reasons, of which the likely best one is that both Java and XML are streamlined for the Internet.
Since its humble beginnings in the 1990s, Java has been an Internet-ready language. When it first hit the scene, Java was viewed primarily as a tool for building applets and other Web-client applications. Java's core API (Application Programming Interface) included a package named java.net. This package contained support for URLs, sockets, authentication, and other necessities of network coding.
As time went on, people saw more and more uses for server-side Java.
- The first big push came in 1997, when Sun released the Java Servlet API. With a servlet, you respond dynamically to a request for your Web site's services. (For example, you can build a customized Web page on the fly to accommodate a particular visitor's needs.)
- In 1998, Sun Microsystems started developing the JavaServer Pages specifications. With JavaServer Pages, you create a Web page that includes both HTML tags and Java program logic.
- In 1999, Sun announced support for JavaServer Pages as part of the ever-popular Apache Web server.
XML was developed (in part) to address the weaknesses of HTML, the common language of the Internet. The whole push for XML has been based on the desirability of sharing of data. Company A's software examines the data made public by Company B. Company A's software can read Company B's data because the data is stored in an XML document. The infrastructure for the exchange of data becomes the entire Internet.
Starting with version 1.4, Java's core API includes packages devoted exclusively to the processing of XML documents. These packages help solidify the bond between Java and XML.