java Implement reflection//first define an interface Ishow.javapublic interface ishow () { void show ( STRING STR);} Establish an Demo.java file implementation interface Public class demo implements ishow{ public void show (STRING STR) { ssytem.out.println (str); }}//build Test.java file to test Public class test{public static void main (string args[]) { string str = "P1.demo"; //Package name + reflected class name try () { class c1 =class.forname (str); try () { ishow a =c1.newinstance (); // class loading mechanism a.show ("QQ"); }catch ( Instantiationexception e) {        E.PRINTSTACKTRAce (); }catch (illegalaccessexception e) { e.printstacktrace (); }catch (classnotfoundexception e) { e.printstacktrace (); } } }}//java Implementing Dynamic Configuration Implement reflection//ishow and demo invariant Public interface ishow () { void show ( STRING STR);} Public class demo implements ishow{ public void show ( STRING STR) { ssytem.out.println (str); }} Build propertiesutil.javaimport java.util.properties;public class propertiesutil{ properties p = new properties (); //new a Properties object &nBsp; try () { p.load ( PropertiesUtil.class.getResourceAsStream ("show.properties")); load Show.properties }catch ( Ioexception e) { e.printstacktrace (); } return p;} Build show.properties file show=p1.demo//build Test.java file to test public class test{public static Void main (string args[]) {///Here the package + class name is loaded through the dynamic file Show.properties properties p =properties.getshowproperties (); string str = p.getproperty ("show"); try () { class c1 =class.forname (str); try () { ishow a =c1.newinstance (); // class loading mechanism a.show ("QQ"); }catch (INSTANTIATIONEXCEPTion e) { e.printstacktrace (); } catch (illegalaccessexception e) { e.printstacktrace (); }catch (classnotfoundexception e) { e.printstacktrace (); } } }}
Java implementation reflection, dynamic configuration