Saturday, October 3

Difference between C/C++ and Java

1. A Java string is not implemented as a null-terminated array of characters as it is in C and C++.
2. Most of the Java operators work much the same way as their C/C++ equivalents except for the addition of two new operators, >>> and ^.
3. The comparison operators in Java return a Boolean true or false but not the integer one or zero.
4. The modulo division may be applied to floating point values in Java. This is not permitted in C/C++.
5. The control variable declared in for loop is visible only within the scope of the loop. But in C/C++, it is visible even after the loop is exited.
6. Methods cannot be declared with an explicitly void argument list, as done in C++.
7. Java methods must be defined within the class. Separate definition is not supported.
8. Unlike C/C++, Java checks the range of every subscript and generates an error message when it is violated.
9. Java does not support the destructor function. Instead, it uses the finalize method to restore the memory.
10. Java does not support multiple inheritance.
11. C++ has no equivalent to the finally block of Java.
12. Java is more strictly typed than C/C++ language. For example, in Java, we cannot assign a floating point value to an integer (without explicit type casting).
13. Unlike C/C++ which allows the size of an integer to vary based on the execution environment, Java data type have strictly defined range and does not change with the environment.
14. Java does not support pointers.
15. Java supports labeled break and labeled continue statement.
break has been designed for use only when some sort of special situation occurs. It should not be used to provide the normal means by which a loop is terminated.
16. The use of final to a variable is similar to the use of const in C/C++.
17. Overridden methods in Java are similar to virtual functions in C++.
18. Java does not have a generalized console input method that parallels the scanf in C or cin in C++.
19. Integer types are always signed in Java. There are no unsigned qualifiers.
20. Java does not define escape codes for vertical tab and the bell character.
21. In Java multidimensional arrays are created as arrays. We can define variable size array of arrays.

No comments: