Java C and C++


1.       Interpreted Language: Java is an interpreted language, not a compiled language as is C++. This means that compiling is done by an interpreter before execution.

2.       Preprocessor: There are no #defines in Java because the development team felt that using #defines advocates coding that is hard to read.

3.       Header Files: Java has no header files. Instead, Java uses interfaces that show only the methods and final, or constant, variables instead of the entire structure.

4.       Pointers: one of the primary features that introduce bugs and memory leaks into programs, are removed in Java.

5.       Multiple Inheritance: Java has replaced multiple inheritance by interfaces to avoid problems with fragile super-classes.

6.       Functions: To ensure a purely object-oriented structure, there are no individual functions in Java. Functions must be encapsulated in a class(known as method).

7.       Goto: While Java retain goto as a reserved word, it is not implemented or supported by the Java language.

8.       Operator Overloading: Java has strict definition of operators. It doesn't allow for operator overloading.

9.       Garbage Collection: Java implements a new function called automatic garbage collection. The Java runtime system keeps track of all references to an object until the object is no longer needed. When there are no more references to an object, it makes it available for garbage collection.

10.   Structures & Unions: There are three types of complex data types in C++: classes, structures, and unions. Java only implements one of these data types: classes.

11.  Strings: C and C++ have no built-in support for text strings. The standard technique adopted among C and C++ programmers is that of using null-terminated arrays of characters to represent strings. In Java, strings are implemented as first class objects (String and StringBuffer), meaning that they are at the core of the Java language.

12.    Casting: Automatic coercion refers to the implicit casting of data types that sometimes occurs in C and C++. For example, in C++ you can assign a float value to an int variable, which can result in a loss of information. Java does not support C++ style automatic coercions. In Java, you must always explicitly cast the data element to the new type.