A least five major C++ features that were intentionally removed from JAVA


C++ Features Not Found in Java
C++ supports multiple inheritance of method implementations from more than one superclass at a time. While this seems like a useful feature, it actually introduces many complexities to the language. The Java language designers chose to avoid the added complexity by using interfaces instead. Thus, a class in Java can inherit method implementations only from a single superclass, but it can inherit method declarations from any number of interfaces. 

C++ supports templates that allow, for example, to implement a Stack class and then instantiate it as Stack or Stack to produce two separate types: a stack of integers and a stack of floating-point values. Java does not allow this, but efforts are underway to add this feature to the language in a robust and standardized way. Furthermore, the fact that every class in Java is a subclass of Object means that every object can be cast to an instance of Object. Thus, in Java it is often sufficient to define a data structure (such as a Stack class) that operates on Object values; the objects can be cast back to their actual types whenever necessary.

C++ allows to  define operators that perform arbitrary operations on instances of  our classes. In effect, it allows to extend the syntax of the language. This is a nifty feature, called operator overloading, that makes for elegant examples. In practice, however, it tends to make code quite difficult to understand. After much debate, the Java language designers decided to omit such operator overloading from the language. Note, though, that the use of the + operator for string concatenation in Java is at least reminiscent of operator overloading. 

C++ allows to define conversion functions for a class that automatically invoke an appropriate constructor method when a value is assigned to a variable of that class. This is simply a syntactic shortcut (similar to overriding the assignment operator) and is not included in Java. 

In C++, objects are manipulated by value by default; we must use & to specify a variable or function argument automatically manipulated by reference. In Java, all objects are manipulated by reference, so there is no need for this & syntax.

0 comments: