Java is a programming language, a runtime system, a set of development tools, and an application programming
interface (API). The relationships between these elements are depicted in Fig. 11 [18].
As illustrated in Fig. 11, a software developer writes programs in the Java language that use predefined software
packages of the Java API. The developer compiles his or her programs using the Java compiler. This results in what
is known as compiled bytecode. Bytecode is in a form that can be executed on the Java virtual machine, the core of
the Java runtime system. The Java runtime system consists of the virtual machine plus additional software, such as
dynamic link libraries that are needed to implement the Java API on operating systems and hardware.
4.1. Classes
Java, C++, Smalltalk, and some other object-oriented languages follow a class-based approach. This approach allows declaring classes that serve as a template from which objects are created. As you would expect, a class defines the type of data that is contained in an object and the methods that are used to access this data. A class also defines one or more methods to be used to create objects that are instances of the class. An instance of a class is a concrete manifestation of the class in a computer’s memory.
4.3. Multithreading
Multithreaded programs are similar to the single-threaded programs that we have been studying. They differ only in the fact that they support more than one concurrent thread of execution–that is, they are able to simultaneously execute multiple sequences of instructions. Each instruction sequence has its own unique flow of control that is independent of all others. These independently executed instruction sequences are known as threads (Fig. 14).
In single-processor s原文请找腾讯752018766优-文^论,文.网http://www.youerw.com ystems, only a single thread of execution occurs at a given instant. The CPU quickly switches back and forth between several threads to create the illusion that the threads are executing at the same time. Logical concurrency is the characteristic exhibited when multiple threads execute with separate, independent flows of control. The important feature of multithreaded programs is that they support logical concurrency, not whether physical concurrency is actually achieved. Multithreading provides concurrency within the context of a single process and multiprogramming provides concurrency between processes [17,18].
In Java, we can create threads in a couple of ways. The simplest way is to take an existing class and turn it into a thread. We do this by modifying the class so that it implements the Runnable interface, which declares the run() method required by all types of threads. (The run() method contains the code to be executed by a thread.)
The second way to create a thread is to write a completely separate class derived from Java’s Thread class. Because
the Thread class itself implements the Runnable interface, it already contains a run() method. However, Thread’s run
() method doesn’t do anything. We usually have to override the method in our own class in order to create the type of
thread we want [19]. 5. Designing Java application We use Java Applets to create an inverted pendulum system and fuzzy controller for this system. In this section we
give the tricks for designing java applications.
5. Designing Java application