Differences between Java and C++

  1. In C++, you can first define the "header stub" for a function without implementing the body, which is given elsewhere. In Java, you cannot do this (too bad).
  2. In C++, you can specify the access type (public, private, etc) for a whole group of methods and variables (using the label "public:"). In Java, you must precede each method or variable with the access type.
  3. In C++, each class has a corresponding destructor method (named with the tilde convention). In Java, you do not have destructors because of automatic garbage collection. Still, you may need to use Java's "finalize" method to dispose of non-Java resources (e.g., opened files) that your object may be hogging.