May 25, 2007
Java Programming Language Basics
Thanks to Julie for this great handout.
Even those of you who’ve never seen a lick of Java before will have an easy time
learning the basics.
Much of Java syntax will be quite familiar to you since it is highly
derivative of C++.
However, it is not true that Java is a superset of C++, or even a
superset of C. Many good additions were made, but to simplify, improve safety, and
eliminate redundancy, many things were removed.
James Gosling, chief architect of
Java, states they omitted "many rarely used, poorly understood, confusing features of C
and C++ that in our experience bring more grief than benefit."
overloading, multiple inheritance,
functions, extensive automatic coercions,
s, have been excluded from the language from day one.
And even some
straightforward language constructs were axed in the name of simplicity—for example,
Java has no exposed
s or global variables.
In pursuit of guaranteed portability,
various "implementation details" usually left to the compiler are fully specified in Java:
the size of various data types, layouts of objects, order of evaluation of sub-expressions,
This handout isn't the end-all Java resource (instead check out Javasoft's web site at
, in particular, all the standard packages and classes are documented at
Here's a quick list of some basic
Java language facts, expressed as deltas from C++:
Java is case-sensitive, like C++.
This fact is sometimes exploited in the system
libraries to use the same name with different capitalization schemes (
The comment characters include the
from C to mark an entire region and
from C++ which marks the rest of the current line as a comment.
The primitive data types include
There is a true built-in
, a data type that can hold
It is not
the case that all non-zero values are true in Java; you must use explicit
values in test expressions.
All primitive types are signed, they have no unsigned variants.
In the name of portability, the size of each type is fully specified.
is always 2
s are 4 bytes,
s are 8, etc.
This can lead to
some inefficiency when the mandated sizes aren't a best fit for the underlying