Monday, 7 January 2013

Juxtaposing Java and C++

Juxtaposing Java and C++

By Steve Tait Graham

If you have been working on C++ for a while and have some basic knowledge about object oriented programming (OOP), then working with Java will be smooth sailing for you. The syntax of Java is quite similar to that of C++ and this makes sense, as Java has been derived from C++ itself. However, surprisingly enough, there are several striking contrasts between the two languages. These differences are intended towards the significant improvisations, and as you comprehend these changes, you will perceive why Java software development is far beneficial than any other OOP language. This article walks you through the noticeable features that set Java apart from C++:

1. Java incorporates three kinds of comments, namely- /* text */, // text and /** documentation */. On the other hand, C++ has only single type of comment, namely- /* comments here */.

2. Enumerations in C++ are primitive in nature. Java enumerations extend as java.lang.Enum

3. In order to provide type-safe containers, Java utilizes generics. C++, on other hand, provides extensive support for generic programming by the means of templates.

4. Garbage collection in Java is automated. It facilitates memory allocation and memory deallocation. In C++, memory management depends upon CLR- destructors, constructors and smart pointers.

5. Java is bounds checked while C++ is not bounds checked.

6. Java compilations run on the Java Virtual Machine (JVM), which makes the Java compilation byte code portable with all major processors and operating systems. On other hand, C++ runs on the same platform on which it is compiled, and thus is non-portable.

7. Compilation in C++ involves a phase called preprocessors. At this stage, the definitions are stored in the header files which are complementary to the original source code files. Java compilation doesn't involve any preprocessor phase. It doesn't make use of the header files either. Class definitions in Java compiler are built directly from the source code files.

8. In C++, dynamic data structures are created and maintained using pointers. This method is compelling, yet can be intricate at times. It can cause bugs in the system as an unguarded access is available to the memory. In Java, the entire process of maintaining data structures is much simplified. Java uses references, which do not allow any unauthorized access to the application memory. This makes the application reliable and secure.

9. C++ encourages multiple inheritances whereas Java doesn't support multiple inheritances directly. To achieve multiple inheritance functionality in Java you need to rely upon interface implementation.

On a whole, Java is more robust and scalable as compared to C++ for the following reasons:

All array accesses in Java are analyzed for violation of bounds.
Object handles are always initialized to null.
Exception handling in Java is relatively error-free and clean.
Memory loss is preventable, thanks to automated garbage collection.
Multithreading is backed with simple language support.
Regular check is maintained on handles and exceptions are passed on for failures.

The contrasts within Java and C++ are definitely noteworthy, but Java clearly surpasses C++ with its robust and scalable user-friendly features.

Steve Graham is a Java expert who has industry expertise in Java Software development and Hire Java Developers. He is currently supervising Enterprise Java development projects as a senior developer at Xicom Technologies ltd, an offshore software development company.

Article Source:



Post a Comment