Wednesday, May 14, 2008

Differences between C++ and Java


No programming language is good for all the work. Of course, it holds true to both Java and C++. Both have their own suitable domains, where they are better than possibly any other language. For example, C++ is more suitable for the work which involves more OS/Hardware interaction or the task which requires very efficient execution of some highly complex mathematical or logical expressions. So, Device Drivers, System Tools, Database Drivers etc. are preferred to be coded in C++.

Java, on the other hand, is suitable to write more secure and portable code with significant ease. Automatic memory management, extensive exception handling, very rich system libraries, etc. make Java one of the best languages for application development.

Enhancement, Maintenance, and Debugging of the applications written in Java is easier and far more effective as compared to the applications written in C++. Java was initially designed to support network programming and it’s possibly the best language to design and develop any network-intensive application, especially Web Applications. The only major competitor of Java/J2EE in this area is the .Net platform, which actually seem to be highly influenced by Java/J2EE.

Both the languages – C++ and Java have been developed following different set of goals, so the tradeoffs will always remain irrespective of the enhancements or newer releases :-)

Please find below the listing of few of the apparent differences between the two languages:

  • C++ isn’t a strictly type-safe language and hence it supports automatic conversion/truncation whereas Java is a strictly type-safe language. Only automatic widening is allowed in Java.
  • C++ has no support for enforced bounds-checking whereas Java enforces a strict bounds-checking mechanism.
  • C++ allows multiple inheritance whereas Java doesn’t allow it, not at least directly :-)
  • C++ has a comparatively limited set of standard libraries as compared to the extensive standard libraries available in Java
  • C++ allows direct calls to the native system libraries whereas Java uses Java Native Interface to achieve the same
  • C++ has comparatively a far better support for the use of low-level system routines than that in Java
  • C++ has a support for native unsigned arithmetic whereas Java doesn’t have any such support
  • C++ accepts the parameters passed by value and reference both whereas Java has support only for ‘Pass by Value’. In case of object references also, they are passed by value only. Since both the copies (main copy and the passed copy) point to the same object, so the changes made to the object become visible for both the copies.
  • C++ requires explicit memory management whereas Java has automatic garbage collector to handle the same
  • C++ has a support for Operator Overloading whereas Java has no such support



Share/Save/Bookmark


No comments: