You are on page 1of 2

Lesson 4

Using Prewritten Classes and Methods

Using Automatically Imported, prewritten Constants and Methods


There are nearly 500 classes available for you in Java. You already used several of the prewritten classes
without being aware of it. System, Character, Boolean, Byte, Short, Long, Float and double are actually classes
from which you create objects. These classes are stored in a package, which is simply a folder that provides a
convenient grouping of classes, which is sometimes called library of classes. There are many Java packages
containing classes that are available only if you explicitly name them within your program but the group of
classes that contains the previously listed classes is used so frequently that it is available automatically to every
program you write. The package that is implicitly imported in to every Java program is named java.lang. The
classes it contains are the fundamental classes, or basic classes as opposed to the optional classes that must be
explicitly named.
The class java.lang. Math constants and methods that you can use to perform common mathematical
functions. Commonly used contains is PI. Within the Math class, the declaration for PI is public final static
double PI = 3.14159265359793.PI is:

public so any program can access it


final so it cannot be changed
static so only one copy exists
double so it holds a large floating-pt value

all of the constants and methods in the Math class are static, which means they are class variables and method.
Some of the common Math class methods are listed below.

You might also like