Some differences between C++ with Java and Smalltalk

Although the Java language is modeled on C++, it has several fundamental differences. It is important to keep in mind (for now) one fact: Java was designed to allow portable applications to be safely downloaded over a network. In its current form, it is not designed to replace C or C++ as a systems programming language. (this will not be true pretty soon). There are a number of C++ features that Java does not support. Perhaps the single biggest difference between Java and C++ is that Java does not support pointers. (Haven't we all already know that!) In C++, pointer is one of C++ most important language features. It is also one of the most dangerous if used improperly. Pointers don't exist in Java for two reasons. First, pointers are inherently insecure. For example, using a C++ pointer, it is possible to gain access to memory addresses outside a program's code and data. Second, the designer of Java probably think that they were too troublesome. Since pointers don't exist in Java, neither does the -> operator. Smalltalk, like Java, does not have the notion of pointers. Everything in Smalltalk is passed by reference. Java does not include structures or unions. These were felt to be redundant since the class encapsulates them. Java does not support operator overloading as does C++. C++ includes a preprocessor or support the preprocessor directives but Java does not. C++ does perform automatic type conversions that result in a loss of precision. Java does not.    For example, a conversion from long integer to integer must be explicitly cast. C++ allows default arguments. This means that you may specify a value that a parameter will have when there is no argument corresponding to that parameter when the function is invoked. Java does not allow default argument. C++ supports inheritance of multiple superclasses by a subclass which Java and Smalltalk do not. To derive a class, the keyword "extends" is used in Java as ":" is used in C++. Smalltalk uses the keyword "subclass" instead. The keyword "super" can be used to access the super class in Smalltalk and Java. In C++, super is being replaced with ::. Also, in Smalltalk the keyword "self" is "this" in Java and C++. Although Java supports constructors, it does not have destructors. It does, however, add the finalize() function which can be used to reclaim resources other than memory such as a file or a handle to another object. Therefore, Java does not have the delete operator. In C++ and Java all variables are typed, but in Smalltalk all variables are typeless and can point to any object or class. Polymorhism can be turned on or off in C++ by a keyword virtual. In Java, polymorphism is always on by default. If one does not want it, the keyword "final" can be used. Smalltalk's polymorphism is always on by default. You can still write a procedural program using C++, but not in Java and Smalltalk. Smalltalk is a interactive environment and lets the programmer view all of the source code. As you guessed, this is not the case for the other languages. In C++ and Java the programmer can specify the access attributes for the variables and methods. In Smalltalk those are fixed: all variables are protected and all methods are public.

New features added by Java
Java adds several features that C++ has no equivalent: packages, interfaces, and multithreading. There is no feature in C++ that directly corresponds to a Java package. The closest similarity is a set of library functions that use a common header file. The Java interface is somewhat similar to a C++ abstract class. Multithreading allows two or more pieces of the same program to execute concurrently. There is no parallel for this in C++. If you need to multithread a C++ program, you will need to do so manually. Java "remove" the C++ standard library, replacing it with its own set of API classes. Java contains a built-in string type called String. String is somewhat similar to the standard string class type provided by C++. Of course, in C++ string is only available if you include its class declarations in you program. It is not a built-in type. While both C++ and Java support a Boolean data type, Java does not implement true and false in the same way as C++. In C++, true is any nonzero value. False is zero. In Java, true and false are predefined literals, and these are the only values boolean expression may have. C++ supports exception handling that is fairly similar to Java's. However, in C++ there is no requirement that a thrown exception be caught. In Java, most exceptions must be caught.

Methods Versus Functions
In the languages of Java and Smalltalk, the word function is seldom used. Instead, what a C++ programmer normally calls a member function, a Java programmer calls a method. One reason for the different terms is to emphasize the fact that Java and Smalltalk do not support global functions. All functions (that is, methods) are members of a class.