The path to learning from the Java EE---javabean and dom

Source: Internet
Author: User
Tags xml parser

What is JavaBean

JavaBean is a reusable component written in the Java language. Plainly, it is a class, the members are private, each member has its own GetXXX method and Setxxx method.

What is DOM

The Document Object model, or DOM, is the standard programming interface recommended by the Organization for the processing of extensible flag languages. To be blunt, it is a way for the organization to parse XML that is recommended by the consortium. We write the program to parse the XML, first call the parsing development package (JAXP,DOM4J), parse the development package called the parser (crimson,xerces), parser and Dom deal with.

Write a JavaBean?

The code is as follows:

 PackageCn.itcase.domain; Public classBook {PrivateString ID; PrivateString title; PrivateString Price;  PublicBook (string ID, string title, String price) {Super();  This. ID =ID;  This. title =title;  This. Price =Price ; }     PublicBook () {Super(); } @Override PublicString toString () {return"Book [id=" + ID + ", title=" + title + ", price=" + Price + "]"; }         PublicString getId () {returnID; }         Public voidsetId (String id) { This. ID =ID; }         PublicString GetTitle () {returntitle; }         Public voidSettitle (String title) { This. title =title; }         PublicString GetPrice () {returnPrice ; }         Public voidSetprice (String price) { This. Price =Price ; }         Public Static voidMain (string[] args) { book Book=NewBook (); Book.setid ("B001"); Book.settitle ("Java Core"); Book.setprice ("98");                SYSTEM.OUT.PRINTLN (book); Book Book2=NewBook ("B002", "C + +", "99");    System.out.println (BOOK2); }    }

It is worth mentioning that in MyEclipse, you can use shortcut keys (Alt + Shift +s) to invoke quick set get and set methods, constructors, override ToString () methods, and so on.

Dom How to use it?

Look at the code again:

    /*      *     Throw all exceptions * /     privatestaticvoidthrows  Exception {        = documentbuilderfactory.newinstance ();                 = Factory.newdocumentbuilder ();                System.out.println (builder);            }

Here is the use of documentbuilderfactory this abstract class, you know, abstract class can not go to new, we find the JDK document, we find a static in documentbuilderfactory, to obtain such an instance of a method, Called Newinstance (), we call this method, we get the example, similarly, documentbuilder, that is, we say the XML parser is also an abstract class, not new, find the document, and then use this instance of Newdocumentbuilder (), You can get a parser for the XML file.

Today's study is here, tomorrow is to use the parser and parsing the development package, read the contents of the file in the XML and obtained.

The path to learning from the Java EE---javabean and dom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.