Major differences between C++ and Java

Here is a list of difference and comparisons between C++ and Java:

S.No. C++ Java
1. Pointer is an important feature of C++. Pointers do not exist in Java due to security reasons. Unauthorized access of memory address is possible while using pointers.
2. Supports operator overloading. Does not support operator overloading.
3. Uses structures and unions. Does not use structures and unions.
4. Performs automatic type conversions. Automatic type conversions are not supported.
5. Uses preprocessor and it supports preprocessor directives. No preprocessor is used and it doesn’t supports preprocessor directives.
6. Default arguments are used. It does not allow default arguments.
7. Global variables and functions are supported. Global variables and functions are not supported.
8. It has destructors. It doesn’t have destructors.
9. Supports inheritance of multiple super classes by a subclass. It does not support inheritance of multiple super classes by a subclass.
10. Unsigned integers can be declared Unsigned integers cannot be declared
11. It supports typedef. It doesn’t support typedef.
12. It uses goto keyword. It doesn’t use goto keyword.
13. << and >> are overloaded for I/O operations. << and >> are not overloaded for I/O operations.
14. It has delete operator. It doesn’t have delete operator.
15. Objects can be passed by value or by reference. Objects are passed only by reference.
16. Multithreading can be achieved only manually using operating system functions. Supports multithreading.
17. Supports abstract class. Supports implementation of interface.
18. Doesn’t have packages. Uses libraries. Supports concept of packages.
19. Only some C++ libraries are object-oriented. All of Java API library is object-oriented.
20. Uses delete keyword for memory de-allocation. It doesn’t use delete keyword for memory de-allocation. When last reference to an object is destroyed, object is automatically deleted.
21. Size of char in C++ is 8 bits. char in Java is 16 bit Unicode characters.
22. It does not have a >>> operator. It uses >>> operator for unsigned right shift.
23. In C++, String is not a built-in type. It has a built-in string type called String.
24. C++ doesn’t use documentation comment. Java uses documentation comment.
25. For a Boolean data type, C++ automatically converts non zero values in to true and zero values in to false. In Java, true and false are predefined literals. Java doesn’t converts non zero values in to true and zero values in to false.
For exception handling, in C++ there is no requirement that a thrown exception be caught. It is required that a thrown exception
26. It doesn’t uses throws keyword. In exception handling, throws keyword is used to throw an exception out of a particular method.
27. When a class is created, access specifiers apply to groups of statements. Access specifiers are applied only to declarations that they immediately precede.


Leave a Reply