Some Standard Classes Chapter 13 1
For Next Time Read Chapter 13 2
Packages Classes can be organized into packages The core classes reside in the java.lang package No import is needed Classes include System , String , Math , and the primitive type wrapper classes java.util is another useful package 3
System class The public out constant object provides the printing methods print() , println() , and printf() currentTimeMillis() returns the system time as milliseconds since midnight, January 1, 1970 The exit() method terminates a running Java program 4
String class 5
Wrapper classes 6
Useful wrapper methods 7
DecimalFormat class An alternative to System.out.printf() Allows numbers to be formatted as strings Define a format template string # a number placeholder; number appears if necesssary 0 a number placeholder; zero always appears Create a DecimalFormat object from the format template string Use the format() method to create a string 8
Math class 9
A Math -worthy problem 10
Random class Use to create pseudorandom number generator objects Good enough for most purposes Useful in games, simulations, and testing nextInt() method returns a pseudorandom integer If r is a Random object, r.nextInt( n ) returns a psuedorandom integer from the range 0 … n – 1 11
Next . . . The object class . . . 12
Recommend
More recommend