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