This is a very brief overview of Java that will be of most value to those who are familiar with both Smalltalk and C++. As the tutorial is developed further tha more complete introduction to Java will be included.
In general, Java has Smalltalk semantics and C++ syntax. There are no pointers, because there is no static data. All objects must be allocated (with the operator new), but there is no explicit deallocation. Instead, there is a garbage collector that runs continuously as a thread in the background. All classes are descended from the general class Object.
Unlike Smalltalk, Java contains both primitive data types (int, boolean, etc.) similar to those in C++ and classes whose instances are objects. There are also classes that are "wrappers" for the primitive data types, which allows primitive data values to be used as objects.
One aspect of Java that can cause difficulty for a C++ programmer is that variables whose value is an object actually contain a reference to the object, rather than the object itself. Thus an assignment statement can result in two variables that reference the same object, as in Smalltalk. In this sense, the variables (except for those whose values are primitive types) of Java are more like pointers in C++, and the assignment of one variable to another is similar to the assignment of one pointer to another in C++. (Instead of saying that there are no pointers in Java, some prefer to say that there are only pointers in Java.)
Parameters are passed by value (as in Smalltalk and C), but it is important to remember that for objects (as opposed to primitive values), a reference is passed by value. So if the value of a variable is passed as a parameter, the object that is the value of a variable will remain the value of the variable after the method (function) returns. However, if the object has a method that can be used to change the object's value then the value of the object may be changed in the method.
Java is a lot like C++ in syntax. For instance, the language contains the standard ++ and += operators that so many C/C++ users use. But Java does not allow operator overloading as C++ does. Most of the C/C++ control structures (if, for, while, etc.) are available in Java, and the syntax is mostly the same in Java as in C.
One of the most important aspects of Java is its standard libraries (packages). Java has a package for Threads, another for Networking, and another for Windowing (the AWT). The base (Sun standard) language is platform independent and free!!!
In order to have access to the public components of a class in another file, the class must be imported, unless the class is in the same directory in a file that follows the required naming conventions, or the class has been compiled and is in the same directory.
instead of the C++
In C++ terms, all methods in Java are virtual.
The primitive types in Java (int, char, ...) are not objects, and they are passed by value.
can be used as an application. "Executing" the application causes the main method to be invoked with the command line argument string as its parameter, just as in C/C++.
The method main above is declared static. This designates that it is a class method rather than an instance method (in Smalltalk terminology). The static keyword can be used with any field (variable) or method to make it a class field or method. For a field, this means that there is only one copy of the field that is shared by all instances of the class (or all methods of all classes if it is public -- yes, C hackers, you can still have your global variables if you really insist upon it!). A static method essentially becomes a global function that does not operate on an object, so in this sense it is like a function in C. Note that static methods and fields are accessed by treating them as fields and methods of the class. For example, for the class definition indicated by
The static members foo and bar could be used as indicated by
Note that this capability is not intended to allow C-style code to be
written in Java.