Start learning Java and write some code to demonstrate the main functions and function usage of each class.
The basic idea is to create a package structure based on the Java source code package structure and write a demo class for each class.
My basic classes:
Package tjava. testlang; </P> <p> Import Java. lang. reflect. constructor; <br/> Import Java. lang. reflect. field; <br/> Import Java. lang. reflect. method; </P> <p> public class basicclasstest <br/> {<br/> static string classname = NULL; </P> <p> Public static void showclassinfo (string classname) throws classnotfoundexception <br/>{< br/> If (classname = NULL | classname. isempty () <br/>{< br/> logprintln ("no class Test. "); <br/> return; <br/>}< br/> class <?> CLS = Class. forname (classname); </P> <p> logprintln ("package name:" + Cls. getpackage (). getname (); <br/> logprintln ("Class Name:" + Cls. getname (); <br/> logprintln ("super class name:" + Cls. getsuperclass (). getname (); </P> <p> logprintln ("include method:"); <br/> for (method: Cls. getmethods () <br/>{< br/> logprintln ("" + method. getname (); <br/>}</P> <p> logprintln ("include field:"); <br /> For (field: Cls. getfields () <br/>{< br/> logprintln ("" + field. getname (); <br/>}</P> <p> logprintln ("include constructor:"); <br/> for (constructor <?> CTR: Cls. getconstructors () <br/>{< br/> logprint ("" + Ctr. getname () + "("); <br/> for (class <?> P: Ctr. getparametertypes () <br/>{< br/> logprint ("" + P. getname (); <br/>}< br/> logprintln (")"); <br/>}</P> <p> Public static void logprintln (string s) <br/>{< br/> system. out. println (s); <br/>}</P> <p> Public static void logprint (string s) <br/>{< br/> system. out. print (s); <br/>}< br/>
DEMO code of the Boolean class:
Package tjava. testlang; </P> <p> Import Java. lang. boolean; </P> <p> public class testboolean extends basicclasstest <br/>{< br/> static string classname = "Java. lang. boolean "; <br/> Public static void test () throws classnotfoundexception <br/> {<br/> logprintln (" test show :"); <br/> logprintln ("Boolean (/" false/") =" + new Boolean ("false ")); <br/> logprintln ("Boolean (/" True/") =" + new Boolean ("true"); </P> <p> logprintln ("Boolean. parseboolean (null) = "+ Boolean. parseboolean (null); <br/> logprintln ("Boolean. valueof (null) = "+ Boolean. valueof (null); <br/> logprintln ("Boolean. type = "+ Boolean. type); <br/>}</P> <p> Public static void showclassinfo () throws classnotfoundexception <br/>{< br/> basicclasstest. showclassinfo (classname); <br/>}< br/>
Verification class:
Import tjava. testlang. *; </P> <p> public class testmain <br/> {<br/> Public static void main (string [] ARGs) <br/> {<br/> // todo auto-generated method stub <br/> try <br/> {<br/> testboolean. showclassinfo (); <br/> testboolean. test (); <br/>}catch (classnotfoundexception e) <br/>{< br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}< br/>
Other classes will be demonstrated later, hoping to stick to the afternoon.
Running result:
Package name: Java. Lang
Class Name: Java. Lang. Boolean
Super Class Name: Java. Lang. Object
Include method:
Hashcode
Compareto
Compareto
Getboolean
Equals
Tostring
Tostring
Valueof
Valueof
Booleanvalue
Parseboolean
Wait
Wait
Wait
Getclass
Notify
Policyall
Include field:
True
False
Type
Include constructor:
Java. Lang. boolean (Java. Lang. String)
Java. Lang. boolean (Boolean)
Test show:
Boolean ("false") = false
Boolean ("true") = true
Boolean. parseboolean (null) = false
Boolean. valueof (null) = false
Boolean. type = Boolean