The JavaTM programming
language is a general-purpose,
concurrent, class-based, object-oriented
language. It is designed to be simple
enough that many programmers can achieve
fluency in the language. The Java
programming language is related to C and
C++ but is organized rather differently,
with a number of aspects of C and C++
omitted and a few ideas from other
languages included. It is intended to be
a production language, not a research
language, and so, as C. A. R. Hoare
suggested in his classic paper on
language design, the design has avoided
including new and untested features.
The Java programming language is
strongly typed. This specification clearly
distinguishes between the compile-time
errors that can and must be detected at
compile time, and those that occur at run
time. Compile time normally consists of
translating programs into a
machine-independent byte code
representation. Run-time activities
include loading and linking of the classes
needed to execute a program, optional
machine code generation and dynamic
optimization of the program, and actual
program execution.
The Java programming language is a
relatively high-level language, in that
details of the machine representation are
not available through the language. It
includes automatic storage management,
typically using a garbage collector, to
avoid the safety problems of explicit
deallocation (as in C's free or C++'s
delete). High-performance
garbage-collected implementations can have
bound----ed pauses to support systems
programming and real-time applications.
The language does not include any unsafe
constructs, such as array accesses without
index checking, since such unsafe
constructs would cause a program to behave
in an unspecified way.
The Java programming language is
normally compiled to the bytecoded
instruction set and binary format defined.
Example Programs
Most of the example programs given in
the text are ready to be executed and are
similar in form to:
class Test {
public static void main(String[] args)
{
for (int i = 0; i < args.length; i++)
System.out.print(i == 0 ? args[i] : "
" + args[i]);
System.out.println();
}
}
On a Sun workstation using Sun's JDK or
Java 2 SDK software, this class, stored in
the file Test.java, can be compiled and
executed by giving the commands:
javac Test.java
java Test Hello, world.
producing the output:
Hello, world.
Sample Program:
Program # 1 |
Integers |
Program # 2 |
Floating Point |
Program # 3 |
Characters |
Program # 4 |
Character behaves like
Integers |
Program # 5 |
Boolean |
Program # 6 |
Dynamic Initialization |
Program # 7 |
The Scope and Lifetime
of Variables |
Program # 8 |
Life Time Variables |
Program # 9 |
Type
Conversion and Casting |
Program # 10 |
Automatic Type Promotion
in Expressions |
Program # 11 |
Using Arrays |
Program # 12 |
Average an array of values |
Program # 13 |
Multidimensional Arrays |
Program # 14 |
Allocate differing size
second |
Program # 15 |
|
|