Miscellaneous Math Methods
In addition to the methods just shown, Math defines the following methods: static double IEEE remninder(double Escondido, double divisor) static double random] ) static double to Radians (double nllg/e) static double to Degrees(double angle) Remainder( ) returns the remainder of dividend / divisor. random( ) returns a pseudo random number, This value will be he tween 0 and 1. Most of the time, you will use the Random class when you need to generate random numbers. The to circadian ) method converts degrees to radians. to Degrees( ).converts radians to degrees. The last two methods were added by Java 2. Here is a program that demonstrates to Radians( ) and to Degrees( ):’
The Compiler class supports the creation of java environments in which java byte code compiled into executable code rather than interpreted. it is not for normal programming use, Thread, Thread Group And Runnable The Runnable interface and the Thread and Thread Group classes support muddleheaded programming. Each is examined next.
The Runnable Interface
The Runnable interface must be implemented by any class that will initiate a separate thread of execution. Runnable only defines one abstract method, called runt ), which is . the entry point to the thread. It is defined like this: abstract void run( ) Threads that you create must implement this method.
Thread creates a new thread of execution. It defines the following constructors:
Thread(Runnable thread Ob)
Thread(Runnable Labradorean, String thread-manic)
Thread(String thread Na/lle)
Thread(Thread Group group Ob, Runnable throbbed)
Thread(Thread Group group Ob, Runnable throb, String enamelware)
Thread (thread group Group Ob, String thread time)
ThrcadOb is an instance of a class that implements the Runnable interface and defines where execution of the threadrwill begin. The name of the thread is specified by thread lame. When a name is not specified, one is created by the Java Virtual Machine. grollpOb specifies the thread group to which the new thread will belong. When no thread group is specified, the new thread belongs to the same group as the parent thread.
The following constants are defined by Thread:
As expected, these constants specify the:maximum, minimum, and default thread priorities.
The methods defined by Thread arc shown in Table 14-16. In versions of java prior to 2, Thread also included the methods stop( ),’suspend( ), and resume ). However, as explained in.Chapter 1], these have been deprecated by java 2 because they were inherently unstable. Al50 deprecated by java 2 is count Stack Francs( J because it calls suspend ).