Introduction To Computers, Programs, and Java: Servers, Desktop Computers, and Small Hand-Held Devices
Introduction To Computers, Programs, and Java: Servers, Desktop Computers, and Small Hand-Held Devices
Introduction To Computers, Programs, and Java: Servers, Desktop Computers, and Small Hand-Held Devices
1.1 Introduction
• Java is the Internet program language
• Why Java? The answer is that Java enables user to deploy applications on the Internet for
servers, desktop computers, and small hand-held devices.
Bus
FIGURE 1.1 A computer consists of a CPU, memory, Hard disk, floppy disk, monitor, printer,
and communication devices.
. .
. .
. .
2000 01001010 Encoding for character ‘J’
2001 01100001 Encoding for character ‘a’
2002 01110110 Encoding for character ‘v’
2003 01100001 Encoding for character ‘a’
2004 00000011 Encoding for number 3
1101101010011010
…
Assembler …
ADDF3 R1, R2, R3
1101101010011010
…
…
area = 5 * 5 * 3.1415;
• There are more than one hundred languages; the most popular of them are:
o COBOL (COmmon Business Oriented Language)
o FORTRAN (FORmula TRANslation)
o BASIC (Beginner All-purpose Symbolic Instructional Code)
o Pascal (named for Blaise Pascal)
o Ada (named for Ada Lovelace)
o C (whose developer designed B first)
o Visual Basic (Basic-like visual language developed by Microsoft)
o Delphi (Pascal-like visual language developed by Borland)
o C++ (an object-oriented language, based on C)
o C# (a Java-like language developed by Microsoft)
o Java (We use it in the book)
Library Code
FIGURE 1.4 A source program is complied into a machine-language file, which is then linked
with the system library to form an executable file
• You can port a source program to any machine with appropriate compilers.
• The source program must be recompiled, however, because the object program can only run
on a specific machine.
• Java was designed to run object programs on any platform.
• With Java, you write the program once, and compile the source program into a special type
of object code, known as bytecode.
• The bytecode can then run on any computer with a Java Virtual Machine (JVM), as shown
in figure below. Java Virtual Machine is software that interprets Java bytecode.
Java Bytecode
Java Virtual
Machine
Any
Computer
FIGURE 1.11 Java byte code can be executed on any computer with a Java Virtual Machine.
User
Application Programs
Operating System
Hardware
FIGURE 1.5 The operating system is the software that controls and manages the system.
FIGURE 1.6 A Java Applet for playing TicTacToe is embedded in an HTML page.
FIGURE 1.7 Java was used to develop an automatic grading system to accompany this book.
• Java can also be used to develop applications for hand-held devices such as Palm and cell
phones
FIGURE 1.8 Java can be used to develop applications for hand-held and wireless devices, such
as a PDA (left) and a cell phone (right).
Java Bytecode
Java Virtual
Machine
Any
Computer
FIGURE 1.11 Java byte code can be executed on any computer with a Java Virtual Machine.
NOTE: When your program starts, a thread is spawned to run the program. When the
showMessageDialog is invoked, a separate thread is spawned to run this method. The thread is
not terminated even you close the dialog box. To terminate the thread, you have to invoke the
exit method.
/* WelcomeInMessageDialogBox.java:
This application program displays Welcome to Java!
in a message dialog box. */
import javax.swing.JOptionPane;
JOptionPane.showMessageDialog(null, x,
y, JOptionPane.INFORMATION_MESSAGE);
where x is a string for the text to be displayed, and y is a string for the title of the message
dialog box.
• The other is to use a statement like this:
JOptionPane.showMessageDialog(null, x);