Java
  Home arrow Java arrow Page 5 - Using XML in a Java Context
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Using XML in a Java Context
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2006-06-22

    Table of Contents:
  • Using XML in a Java Context
  • Modifying an XML Document
  • Formatting an XML Document
  • Evaluating XOM
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using XML in a Java Context - Summary


    (Page 5 of 5 )

    Today, you learned about working with data stored in popular database formats such as Microsoft Access and MySQL. Using either Java Database Connectivity (JDBC) or a combination of JDBC and ODBC, you can incorporate existing data-storage solutions into your Java programs.

    You can connect to several different relational databases in your Java programs by using JDBC or ODBC and Structured Query Language (SQL), a standard language for reading, writing, and managing a database.

    You also learned the basics of another popular format for data representation: Extensible Markup Language (XML).

    In many ways Extensible Markup Language is the data equivalent of the Java language. It liberates data from the software used to create it and the operating system the software ran on, just as Java can liberate software from a particular operating system.

    By using a class library such as the open source XML Object Model (XOM) library, you can easily create and retrieve data from an XML file.

    A big advantage to representing data using XML is that you will always be able to get that data back. If you decide to move the data into a relational database or some other form, you can easily retrieve the information.

    You also can transform XML into other forms such as HTML through a variety of technology, both in Java and through tools developed in other languages.

    Q&A

    Q.  Can the JDBC-ODBC bridge driver be used in an applet?

    A. 
    The default security in place for applets does not allow the JDBC-ODBC bridge to be used because the ODBC side of the bridge driver employs native code rather than Java. Native code can't be held to the security restrictions in place for Java, so there's no way to ensure that this code is secure.

    JDBC drivers that are implemented entirely in Java can be used in applets, and they have the advantage of requiring no configuration on the client computer

    Q.  Why is Extensible Markup Language called XML instead of EML?

    A. 
    None of the founders of the language appears to have documented the reason for choosing XML as the acronym. The general consensus in the XML community is that it was chosen because it "sounds cooler" than EML. Before anyone snickers at that distinction, Sun Microsystems chose the name Java for its programming language using the same criteria, turning down more technical-sounding alternatives such as DNA and WRL.

    There is a possibility that the founders of XML were trying to avoid confusion with a programming language called EML (Extended Machine Language), which predates Extensible Markup Language.

    Quiz

    Review today's material by taking this three-question quiz.

    Questions

    1. What does a Statement object represent in a database program?

    1. A connection to a database

    2. A database query written in Structured Query Language

    3. A data source

    1. Which Java class represents SQL statements that are compiled before they are executed?

    1. Statement

    2. PreparedStatement

    3. ResultSet

    1. When all the start element tags, end element tags, and other markup are applied consistently in a document, what adjective describes the document?

    1. Validating

    2. Parsable

    3. Well-formed

    Answers

    1. b. The class, part of the java.sql package, represents an SQL statement.

    2. b. Because it is compiled, PreparedStatement is a better choice when you're going to execute the same SQL query numerous times.

    3. c. For data to be considered XML, it must be well-formed.

    Certification Practice

    The following question is the kind of thing you could expect to be asked on a Java programming certification test. Answer it without looking at today's material or using the Java compiler to test the code.

    Given:

    public class ArrayClass {
    public static ArrayClass newInstance() { count++; return new ArrayClass(); }
    public static void main(String arguments[]) { new ArrayClass(); }
    int count = -1; }

    Which line in this program prevents it from compiling successfully?

    1. count++;

    2. return new ArrayClass();

    3. public static void main(String arguments[]) {

    4. int count = -1;

    The answer is available on the book's Web site at http://www.java21days.com. Visit the Day 20 page and click the Certification Practice link.

    Exercises

    To extend your knowledge of the subjects covered today, try the following exercises:

    1. Modify the CoalTotals application to pull fields from the Country Oil Totals table instead of the Coal table.

    2. Create two applications: one that retrieves records from a database and produces an XML file that contains the same information and a second application that reads data from that XML file and displays it.

    Where applicable, exercise solutions are offered on the book's Web site at http://www.java21days.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Sams Teach Yourself Java 2 in 21 Days, 4th...
     

    Buy this book now. This article is excerpted from chapter 20 of the book Sams Teach Yourself Java 2 in 21 Days, 4th Edition, written by Rogers Cadenhead and Laura Lemay (Sams; ISBN: 0672326280). Check it out today at your favorite bookstore. Buy this book now.

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT