See: http://www.javasoft.com
and http://java.sun.com/docs/books/tutorial
The impact of Java has been enormous, not only in terms of its adoption in the software industry, but also in terms of the number of books written and sold. Java has also become the language of choice for introductory programming courses.
The original design purpose stated for Java was to provide a safe environment for executing so-called applets, written in a general purpose programming language, in a Web-browser. For that reason Java programs are executed by a virtual machine, in which the programs can be executed as in a sandbox protecting the environment from possibly malicious programs. In addition, the virtual machine gives a high degree of platform independence. The slogan that has accompanied the introduction of Java, write once, run everywhere does nevertheless not completely hold true when it concerns user interfaces, since the particularities of the various platforms have proved to be hard to master.
Whatever one may think of Java as a language, a lot of effort is put into coming to an agreement about the numerous APIs that are part of the Java platform. These include the Swing GUI framework, the component Beans, the reflection API, the native code interface, the multimedia framework, not forgetting the Java3D and VRML classes. This makes the Java platform indeed a very powerful and productive environment.
Java is very well documented.
Apart from the many books about Java, there
is also an excellent tutorial online, for free.
See the URLs in slide appendix-java.
Terminology
Also new is the keyword synchronized, reflecting the built-in support for concurrency in Java. A synchronized method excludes multiple invocations of that method, which might otherwise occur in a multi-threaded program.
The keyword final may be used to indicate that a particular value may not be changed. In this sense it is similar to the C++ keyword const. It must be noted that Java is even more elaborate in the use of the keywords private, protected and public than C++. They are used to indicate access restrictions for the methods of an object for objects inside and outside the package in which the objects' class is defined. The language features offered by Java resemble those of C++. However, in many respects Java is much simpler than C++. Most notably, the absence of pointers, a sure source of errors, makes programmers' lives easier. In particular since Java offers automatic garbage collection, programmers need not to worry about disposing objects created dynamically. Resource management, however, may be done by defining a method finalize. The counterpart, however, of that is that all objects in Java come into existence by explicit dynamic creation.
The availability of interfaces
compensates for the restriction to single inheritance, which must
be indicated by the keyword extends
instead of the colon.
It has often been argued that multiple inheritance
is not really necessary.
This holds true, however, only for
implementation inheritance.
Multiple (interface) inheritance is a powerful feature
that has interesting applications once one has discovered
how to use it.
Expressions
The operators defined for the built-in types
do sometimes behave in an unexpected way.
For example, whereas the
As logical operators Java includes, as C++, conjunction (&&) and disjunction (), as well as a number of bitwise logical operators. Also, we have an indexing operator which, unlike for C++, may be not defined for arbitrary types. Access to both static and dynamic methods involves the use of the dot operator.
The increment and decrement are defined only for the scalar types. Also, we have a conditional expression of the form b?: testing the condition b to deliver when it evaluates to true and otherwise.
Assignments in Java, like in C++, are written as var = expression with a single = symbol. As remarked previously, this convention is known to cause mistakes by programmers raised with languages such as Pascal or Modula-2.
In addition, Java offers, like C++, modifying assignments,
which may be used as, for example, in n += 1,
which is identical in meaning to n = n + 1.
Control
To illustrate the use of interface definitions, slide Java-objects-2 presents a slightly modified version. The actual HelloWorld class announces that it implements the World interface.
The following members of Object, however,
cannot be overridden:
getClass, notify, notifyAll, wait.
The latter three reflect Java's support for threads;
they should not be used when the object is not a thread.
Perhaps the most well-known feature of Java
is its support for so-called applets,
light weight applications that may enrich your Web-browser
with graphics, multimedia and additional communication
facilities.
Browsers such as Netscape and Microsoft Internet Explorer
have an embedded Java Virtual Machine that enables them
to execute Java applets.
Applets may also be executed by the Java
plugin that has been provided by Sun Microsystems
as an alternative to the browsers' built-in virtual machines.
Java offers a number of facilities for networking,
including support for retrieving resources by URL,
sockets, and remote method invocation.
Remote method invocation (RMI) may be considered a
light weight alternative for CORBA distributed
programming.
In contrast with CORBA (version 2.0),
Java allows for sending objects over the network
due to its powerful Reflection API
that gives runtime access to the properties
of objects, including class types and methods.
The Beans framework offers
component technology, that allows developers to
exchange (beans) objects and inspect their properties
in a uniform manner. For example GUI elements,
written as beans, can be incorporated at runtime
to add the desired functionality to a user interface.
Another well-designed and powerful feature of Java is
its native interface,
which enables the experienced programmer to embed
native code in Java applications.
No need to say that from a purists' point of view one should avoid this.
Last but not least, the javadoc
facility must be mentioned.
The javadoc tool allows for creating documentation
directly from the class definitions, that may be annotated
with signature descriptions, and
information about its author, possible exceptions
and comments.
It described how Java differs from C++,
gave an Hello World example of
an ordinary program, an object that implements
an interface and an applet.
Also, we discussed briefly the libraries,
frameworks and extensions comprising
the Java platform.
draft version 0.1 (15/7/2001)Hello World - class
Inheritance
Hello World -- Java (2)
Technology
Java -- techniques
Summary
The language Java
[]
readme
course
preface
1
2
3
4
5
6
7
8
9
10
11
12
appendix
lectures
resources
eliens@cs.vu.nl