4 April 1996

Learning Java

In the areas that do not matter, Java borrows its syntax from C or C++. Programmers know from debugging that the mind sees what it wants or expects to see and not what is really there. The superficial similarities between Java and C lead experienced programmers to expect that Java has also inherited other features. They then fail to appreciate that Java is a fundamentally different language that must be confronted on its own terms.

If you just want a high level discussion of the language as a distributed Web programming tool, first read the previous PCLT article on Java.

This is not a tutorial. There are a dozen Web sites that will teach you to write a Hello World application in Java. More importantly, any site that tries to be friendly and helpful will not accomplish the job that needs to be done. PCLT will, instead, take a large blunt object and beat a very dead horse repeatedly, until the reader realizes that in all the ways that really matter, Java is not even remotely like C++.

The solution is to present Java in language that is almost unbearably precise. Consider the statement:

int list[]=new int[10];

Almost everyone else will say that it declares "list" to be an array of ten integers. That is certainly the correct way to express this construct in the terms of every other programming language. Unfortunately, it leaves room for many misunderstandings.

With unbearable precision, "list" is a scalar reference variable (a pointer if you prefer) that must designate (point to) objects that are arrays of integers. It is initalized on the right side of the "=" by an expression that uses the new operation to dynamically allocate an object containing an array of ten four byte integer variables. The expression generates a reference (pointer) to the newly allocated array object which is then assigned to the reference variable "list".

Why does this matter? If "list" is an array, what is its dimension? This is an entirely reasonable question to ask in any other programming language. However, in Java dimension is an attribute of the object that "list" points to, not of "list" itself. Throughout the program "list" can point to many different arrays with different lengths, just so long as each array has integer elements. The program can even set "list" to null, in which case any reference to the array length is an error.

By reading a series of topics in turn, this seemingly murky discussion will slowly become first clear, and then reasonable.

Primitive Data Types
Classes
Variables
Object Methods
Inheritance
The Object Class
Arrays
Strings
Public
Final
Interfaces
Constructors
Import
Garbage Collection
Exceptions
Native Classes
Threads
Synchronization

PCLT

Copyright 1996 PC Lube and Tune -- Java H. Gilbert

This document generated by SpHyDir, another fine product of PC Lube and Tune.