Java notes, java. Lang. boolean.

Source: Internet
Author: User

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

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.