Reflection Reflection: The various structures (methods, properties, constructors, class name) Java class mapped to one Java object. Technique using reflection of a class can be dissected, reflecting frame design is the soul
@ Reflection: the various structures (methods, properties, constructors, type) java class java object mapped to one public class ReflecTest { public static void main (String [] args) throws a ClassNotFoundException, an InstantiationException is, IllegalAccessException, an IllegalArgumentException , a InvocationTargetException, a NoSuchMethodException, a SecurityException { // three methods . @ 1 Object .getClass () iphone iphone iPhone new new = (); class iphone.getClass CLZ = (); // class 2 .class CLZ = Iphone.class ; //3.Class.forName ( "package name type.") CLZ = Class.forName ( "server.basic.Iphone"); // create the object Iphone iphone2 = (Iphone) clz.newInstance (); System.out .println (iphone2-); Iphone iphone3 = (Iphone) clz.getConstructor () the newInstance ().; System.out.println (iphone3); } } class {Iphone public Iphone(){ } }
XML: Extensible Markup Language, Extensible Markup Language, as a storage format to store data or parameters for the software, the program parses the configuration file, you can reach the destination without modifying the code will be able to change the program.
java.io.IOException Import; Import javax.xml.parsers.ParserConfigurationException; Import javax.xml.parsers.SAXParser; Import the javax.xml.parsers.SAXParserFactory; Import the org.xml.sax.Attributes; Import in org.xml.sax. a SAXException; Import org.xml.sax.helpers.DefaultHandler; public class XMLTest in { public static void main (String [] args) throws a ParserConfigurationException, a SAXException, IOException { // parse the SAX // 1, for acquiring and analyzing plant SAXParserFactory factory = SAXParserFactory. the newInstance (); // 2, acquired from the parser parses the factory the SAXParser = factory.newSAXParser the parse (); //. 3, the document is loaded document registration processor PersonHandler handler = new PersonHandler (); //. 4, the preparation of the processor parse.parse(Thread.currentThread().getContextClassLoader().getResourceAsStream("server/basic/p.xml"), handler); } } class PersonHandler extends DefaultHandler { @Override public void startDocument() throws SAXException { System.out.println("---解析文档开始---"); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { System.out.println(qName + "--->解析开始"); } @Override public void characters(char[] ch, int start, int length) throws SAXException { String contents = new String(ch, start, length).trim(); if (contents.length() > 0) { System.out.println ( "content:" + Contents); }else{ System.out.println ( "content ->" + "empty"); } } @Override public void the endElement (String URI, the localName String, String the qName) a SAXException {throws System.out.println (the qName + "---> end parsing"); } @Override public void the endDocument () throws a SAXException { System.out.println ( "---- --- end parse the document" ); } }