http://debut.cis.nctu.edu.tw/~chi
Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,
: POSITIVE_INFINITY NEGATIVE_INFINITY NaN 1.0 / 0.0-1.0 / 0.0 0.0 / 0.0 Nan not a number, Nan!= Nan true Nan zero = 0.0 ; d = 1.0 / zero ; if( d == Double.POSITIVE_INFINITY ) System.out.println( 0 ) ; Float.isNaN( ( ) ; Double.isNaN( ( )
: java.lang.math method,, Math Math.E (2.71828 ) Math.PI (3.14159 ) method Math.abs( ( a ) Math.acos(a) Math.asin(a) Math.atan(a) Math.atan2(a,b) Math.ceil(a) Math.cos(a) Math.floor(a) Math.exp(a) Math.log(a) int,, long, float, Cos Sin tan a Cos a e a a
method Math.max(a,b) Math.min(a,b) Math.pow(a,b) Math.random() Math.rint(a) Math.round(a) Math.sin(a) Math.sqrt(a) Math.tan(a) int,, long, float, int,, long, float,, float a b a Sin() Tan() : log(), pow(), sqrt(), ArithmetricException : irrational=math.sqrt(2.0); int bigger=math.max(3,4); long one=math.round(1.125789);
: java.math long, java.math BigInteger BigDecimal try{ BigDecimal twentyone=new BigDecimal( 21 ) ; BigDecimal seven = new BigDecimal( 7 ) ; BigDecimal sum = twentyone.add(seven) ; int answer = sum.intvalue( ); } catch ( NumberFormatException nfe) { } catch ( ArithmeticException ae) { }
java.util.properties hash table String Key / Value pair Properties props = new Properties(); props.put( myapp.xsize, 52 ); props.put( myapp.ysize, 79 ); : getproperty( ) String xsize=props.getproperty( myapp.xsize ); Properties: propertynames( ) for(enumeration e=props.propertynames(); e.hasmoreelements( property {, getproperty() String Name=e.nextElement(): null }
key, Properties ; Properties props=new Properties( ); getproperty(), String xsize=props.getproperty( =props.getproperty( myapp.xsize, 50 );
Properties save() method OutputStream ASCII props.save save(system.out, : Application Parameters ); FileOutStream out=new FileOutStream(.txt ); props.save(out, : Application Parameters );! # : Application Parameters #Mon Feb 12 09:24:23 CST 1999 myapp.ysize=79 myapp.xsize=52
properties load() InputStream FileInputStream fin; Properties props=new Properties(); props.load( fin );
System property Java.lang.System System.getProperty() System property java.vendor java.vendor.url java.version java.home java.class.version java.class.path os.name os.arch os.version file.separator path.separator URL Java System property Java line.separator Java user.name user.home user.dir ( /, \ ) (\n \r\n)
Applet properties: java.home; java.class.path; user.name; user.home; user.dir System.setProperty() () java, C:> java Dfoo=bar -Dcat=Boojum MyApp Boolean, Integer, Long, Color get Ex: Integer.getInteger( foo foo ); // foo Color.getColor( foo foo ); // Color
Java.util.Observer ( ) Java.util.Observable ( ) ( ), ( ) : 1. (Observable) 2. (Observer) 3., Observable ( update () method)
(MessageBoard) Observable( ) method addobserver() public String getmessage(){ method notifyobserver() return message; } import java.util.*; public class MessageBoard extends Observable { } blic void static main(string []args){ MessageBoard board = new MessageBoard(); Student bob= new Student(); Student joe = new Student(); board.addobserver(bob); board.addobserver(joe); board.changemessage( public void changemessage(string Message){ this.message=message; setchanged(); notifyobservers(message); } ); class Student implements Observer { public void update(obserable o, Object arg) System.out.println( + arg ) }