C++ vs. Java: The differences

  • By reComparison Contributor
  • comments 3
  • views5962

Difference between C++ and Java

C++ was developed in 1979 at Bell Labs by Bjarne Stroustrup as an extension of language C. It introduced a number of new features such as multi-paradigm programming including object orientation, inheritance, operator overloading, virtual functions and many more. Java on the other hand was released in 1995 by Sun Microsystems. With its syntax similar to C++, Java has a complete simpler object model. No doubt Java is today’s most popular programming language built with aim of complete platform independence. Large numbers of application software and web applications are built in Java. Its inbuilt class libraries not only make programming flexible but also reduce the length of code making overall program precise enough to comprehend. 

C++
Java

Compilation/Execution

C++ program needs a compiler for code to be first compiled and then executed. Compilers for C++ are provided by many groups like GNU, Microsoft or Intel. It is designed to function without any sophisticated environment for programming. Java, on the other hand, achieves platform independence with the help of java virtual machine (JVM). A java program is first converted (compiled) to a byte code – a class file. This byte code can be executed by any JVM irrespective of underlying platform.  

Performance

Java programs are generally slower and consume larger space than those written in C++. But then portability of application, object oriented class based approach and many other remarkable features compensate for its time and space consumption. Significant improvements have been observed in execution time by optimization of JVM or with JIT (just in time) compiler. JIT converts byte code into native machine code. In general, Java programs invoked with a JIT compiler run much faster. Sun leveraged technologies like adaptive optimization and improved garbage collection models to improve the speed of the Java VM and implemented the next-generation virtual machine called The Java HotSpot VM. Java Hotspot VM removes the need for a JIT compiler in most cases.

Memory management

C++ supports dynamic memory allocation with the help of new and delete. It doesn't support automatic garbage collection, one of the most important features introduced in Java.  Once the object is destroyed that is it’s no longer in use, the memory allocated to it is to be freed. In contrast to C++, where this job is to be done by the programmer, Java runs a special routine called Garbage Collector which automatically frees the unused allocated memory. 

Applications

C++ and Java are very popular among programmers throughout the world. C++ is used to build system software, application software, device drivers, servers and even entertainment software such as video games. Java on the other hand has its wide application in Internet. Java applets are embedded in web pages with the help of tag as far as HTML is concerned. Web servers promote their functionality with the help of servlets written in Java. Servlets can be seen as applets that run on the server side.

Summary

C++

  • C++ was developed in 1979 at Bell labs by Bjarne Stroustrup.
  • Compilers for C++ are provided by many groups like GNU, Microsoft or Intel.
  • C++ supports dynamic memory allocation with the help of new and delete.
  • C++ is used to build system software, application software, device drivers, servers and even entertainment software such as video games.

Java

  • It was released in 1995 by Sun Microsystems.
  • Java achieves platform independence with the help of java virtual machine (JVM).
  • JIT (just in time) compiler improves execution speed of java application.
  • Garbage Collector automatically frees the unused allocated memory.
  • Applets and servlets are embedded Java applications in web pages and servers respectively and are used to increase their functionalities.

Which is better for server side programming?
  • C++
  • Java
 
 

Discuss It: comments 3

  • Guest
  • Chris wrote on August 2010

The fact that the article says "or with upcoming of JIT (just in time) compiler", shows how old this must be.

How about a more up to date comparison!!!

  • Guest
  • Sandeep wrote on January 2011

Great article

That's good compilation dude and I guess biggest advantage of java is not having pointer which makes it easy to read and easy to write language also provide security by not exposing memory location to program.

Thanks

Javin

Why String is immutable in Java

Post a Comment
  • Name*
  • Email*
  • Website (optional)
  • arrow You are commenting as a Guest
  • arrow Your email will not be public
  • arrow Login or Sign Up and post using your reComparison account
  • arrow Facebook Connect