API Packages • The classes of the Java standard class library are organized into packages • java.lang • java.net java.util • java.awt • javax.swing • When you want to use a class from a package, you can import one class or all classes from the package into your program
API Packages • All classes of the java.lang package are imported automatically into all programs • Other classes should be explicitly imported. Examples: import javax.swing.JOptionPane; import javax.swing.*;
Method printf() method in System.out can be used to specify how many digits for a floating-point number should be display. Ex: double number = 1.0/3.0; System.out.printf("%.2f\n", number); //0.33 System.out.printf("%7.3f\n", 89.123456789); //89.123
Method • %d à to print an integer • %5d à to print an integer with width 5 • %7.2f à to print a floating point number with 2 digits after the decimal point and with width 7 (including the decimal point) • %s à to print a string