Journal of Software Engineering and Applications
Vol. 5  No. 8 (2012) , Article ID: 21960 , 4 pages DOI:10.4236/jsea.2012.58072

Time Comparing between Java and C++ Software

As’ad Mahmoud Alnaser1, Omar AlHeyasat2, Ashraf Abdel-Karim Abu-Ein2, Hazem (Moh’d Said) Hatamleh1, Ahmed A. M. Sharadqeh2

1Computer Science Department, Ajlun University College, Al-Balqa’ Applied University, Amman, Jordan; 2Computer Engineering Department, Faculty of Engineering Technology, Al-Balqa’ Applied University, Amman, Jordan.


Received May 11th, 2012; revised June 18th, 2012; accepted June 27th, 2012

Keywords: Java; C++; Algorithm Speed; Code Flexibility


This paper construct a comparison between two main software’s used in programming applications that are Java and C++, the comparison operation includes the time needed to perform some algorithm i.e. speed of operation, flexibility to adjusting some code, and efficiency. The same code is used to compare between the two software to determine which one is better. It is found that C++ needs less time to execute the same code comparing with Java. Java needs about 10% excess time to execute the same code segment comparing to C++.

1. Introduction

Java and C++ are the most used languages in programming for most of programmers and system designers. Java has a structure called an “Interface”. Java interface is almost identical to a C++ class that has nothing but pure virtual functions. Inherent in java is not efficient from more than one base class; even if the base classes have nothing but abstract methods or pure virtual functions. The differences between Java and C++ can be summarized as in Table 1.

The time needed to execute some code, algorithm, program or complete system program is considered critical in any programming language, in this paper the time needed to execute some same code in both Java and C++ is used to compare between such two languages. The minimum time needed to execution is an advantage because it reflects how much is the language is powerful and efficient. The minimum time of execution means more speed of execution which is the main goal of any designer or programmer.

Many researches and studies discussed this issue, Lutz Prechelt, (1999), discussed the relative efficiency of Java programs, in particular in comparison to well established implementation languages such as C or C++. Java is often considered very slow and memory-intensive. Most benchmarks, however compare only a single implementation of a program in, say, C++ to one implementation in Java, neglecting the possibility that alternative implementations might compare differently. In contrast, the current article presents a comparison of 40 different implementations of the same program, written by 40 different programmers. The inter-personal program differences are larger than those between the languages and the performance gap between Java and other languages is still shrinking rapidly, [1].

Peter Sestoft, 2010, they compare the numeric performance of C, C# and Java on three small cases. Managed languages such as C# and Java are easier and safer to use than traditional languages such as C or C++ when manipulating dynamic data structures, graphical user interfaces, and so on, [2]. Dirk E. et al. (2011), discussed the RC++ package simplifies integrating C++ code with R. It provides a consistent C++ class hierarchy that maps various types of R objects (vectors, matrices, functions, environments, ...) to dedicated C++ classes. Object interchange between R and C++ is managed by simple, flexible and extensible concepts which include broad support for C++ Standard Template Library idioms. C++ code can be compiled, linked and loaded on the y, or added via packages. Flexible error and exception code handling is provided. RC++ substantially lowers the barrier for programmers wanting to combine C++ code with R. [3,6].

Michi H. et al. 2012, compared between Windows Communication Foundation and Java: Remote Method Invocation which are currently seen as major contenders in the middleware space, performance is often taken as the sole evaluation criterion, despite the fact that performance is only one of many factors that influence the choice of middleware. They provided a performance and scalability comparison of the three middleware platforms, and discussed when performance and scalability matter and when they do not, including their likely impact alongside other factors on the overall cost of a project. Finally, for those applications that indeed require high performance and scalability, the article points out a few techniques you can use to get the biggest bang for your buck, [7].

2. Results and Discussion

From last comparing between Java and C++, the main thing that may reveal which software is better is the time to execute the same algorithm. So as an example consider the following Java code:

public class RealTime


public void Do()//must complete in 500 μs


Clock c = new Clock; //might collect!

// diddle with clock for 100 μs



If this code is executed using both Java and C++, Java takes 500 μs to be complete such algorithm. This is a typical constraint in a hard real time system. Those functions that call {Real Time. Do()}depend on the fact that it will take no longer than 500 μs to execute. While the same function takes just 450 micro seconds to be executed using C++. The goal of the experiment is to measure the time needed to execute the same code on both Java and C++. 

Figure 1 shows a time of execution comparison between Java and C++. It is clear that C++ is faster than Java which can be represented as:


where TJava: time needed to execute some given code using

Table 1. Differences between Java and C++, [1,2,4,5].

Figure 1. Comparing the execution time of Java and C++.

Figure 2. Java runtime vs C++ [].

Figure 3. Java vs C++ and .NET, [7].

Java SW.

TC++: time needed to execute some given code using C++ SW.

To compare the current study with previous studies, Figure 2 comparing Java runtime for different algorithms with that of C++, it is clear that the Java runtime is more in almost algorithms than that of C++.

Figure 3 comparing between Java requests/sec and that for C++ and .NET, it is clear that the C++ requests per unit of time is more. Which told us that C++ is more efficient.

3. Conclusion

Java is a powerful language. While C++ has a relatively easy time to be learned, and will find that the programmers enjoy using it. It is noted that a few problems with the language in the above discussion. Language design always involves some disadvantages or shortcomings that displease someone. C++ is an interesting language that enable us to write codes easily with more flexibility and with little time needed to execute some code comparing to Java.


  1. P. Lutz, “Comparing Java vs C/C++ Efficiency Differences to Inter-Personal Differences,” Communications of the ACM, Fakult at fur Informatik University, Karlsruhe, 1999.
  2. S. Peter, “Numeric Performance in C, C# and Java Peter Sestoft,” IT University of Copenhagen, Copenhagen, 2010.
  3. E. Dirk and F. Romain, “Rcpp: Seamless R and C++ Integration,” 2010.
  4. W. Peng, M. Sam, M. J. Moreira and G. Manish, “Efficient Support for Complex Numbers in Java,” ACM 1999 Java Grande Conference, San Francisco, 12-14 June 1999, pp. 109-118.
  5. J. E. Moreira, S. P. Midkiff, M. Gupta, P. V. Artigas, M. Snir and R. D. Lawrence, “Java Programming for High Performance Numerical Computing,” IBM Systems Journal, Vol. 39, No. 1, 2000, pp. 21-56.
  6. J. Glenn, C. M. Clement, S. Q. Snell and G. Vladimir, “Design Issues for Efficient Implementation of MPI in Java,” ACM 1999 Java Grande Conference, San Francisco, 12-14 June 1999, pp. 58-65.
  7. H. Michi and S. Mark, “Choosing Middleware: Why Performance and Scalability Do (and Do Not) Matter,” ZeroC, Inc., Palm Beach Gardens, 2011.