Sorry Java, but C++ Wants to Get on the Podium of Programming Languages

原创 精选
In the latest TIOBE Index for June 2022, C++ is ranked fourth, behind Python, C, and Java. Considering how popular C++ has become in the past year, could it soon overtake Java and return to the top th

In the recent TIOBE Index for June 2022, it is Python that tops the charts, followed by C, Java, C++, and C#. Compared to the same period last year, C++ has seen a significant increase in market share, while Java has gradually become less popular. Based on the current trend, C++ may overtake Java in the near future.

A step up for C++, a step back for Java

The software quality company highlighted this significant change in its latest index with the eye-catching headline "C++ is about to surpass Java." First released in 1995, Java has long been regarded as an evergreen language. Despite this, Java is inevitably suffering losses as other languages catch up, so the industry has begun to wonder whether it can maintain its position.

Paul Jansen, TIOBE's CEO, had made some predictions that C++ might be the next language to overtake Java. In the latest index, C++ holds a 9.63% share with a 2.26% increase to catch up to Java, which is down 1.07% to 10.47% and has also reduced the gap with C++ to 0.84%.

As Jansen said, "High level programming with performance is C++'s key reason why it is doing so well. The C++ language is revised every 3 years. Such revisions contain ground-breaking new features, which get the language on par with C# and Java, but without the performance penalty of a garbage collector. Let's see where C++ is heading the next few months."

Moreover, it is noteworthy that C++'s share of the TIOBE programming language index from April to June 2022 increased. From April to June, C++'s growth rates were 1.14%, 1.01%, and 2.26%, while Java's was -0.41%, -0.74%, and -1.07%.

Feature comparison between C++ and Java

It is interesting to note that C++ is the predecessor of Java. Thirty years ago, James Gosling, an engineer at Sun, led his team in reshaping C++. A few impractical aspects of C++ have been removed and combined with the real-time requirements of embedded systems to develop Oak, an object-oriented programming language. A three-year process of iterations and upgrades coincided with the rise of the Internet, which led to the renamed Java's success as an object-oriented, "Write Once, Run Anywhere" programming language. Java's object model is almost a simplified version of C++. Despite this, there are some significant differences between the two.

Table 1: C++ features that Java lacks





Multiple inheritance (MI)



Java introduces the concept of interfaces, and it is possible to implement various interfaces simultaneously. Because interfaces also possess polymorphic properties, multiple interfaces can be implemented in Java to accomplish similar goals as MI in C++.




Java does not include a preprocessor but provides an import mechanism similar to the C++ preprocessor.

GoTo statement



GoTo is a reserved keyword in Java.

Automatic type conversion



The Java programming language does not support automatic type conversion, which may result in unsafe programs. It utilizes explicit type conversion, which can be enforced by the programmer.

Struct and Union



All members of Struct and Union are public in C++, which can cause security problems. While Java does not contain Struct or Union, everything is encapsulated inside types.

Default arguments



Operator overloading



Table 2: Java features that C++ lacks





Automatic garbage collection



There is an automatic garbage collection feature in Java that eliminates the need for the program to explicitly manage the allocation of memory. 

While C++ requires developers to handle memory allocation (including requesting and releasing), this means placing resource-releasing codes into the destructor. 

A finalize() method is introduced in Java, and when the garbage collector is about to release memory of a useless object, it will call its finalize() method, preventing developers from having to worry about when memory space will be released.

Standard libraries



There are a number of standard libraries included with Java that perform specific tasks. For example, Java provides a JDBC API for accessing databases and RMI for implementing distributed objects.

In contrast, C++ relies on non-standard libraries provided by other vendors.

Reflection mechanism



A reflection mechanism in Java allows self-checking at runtime as well as manipulation of internal members, while a similar mechanism does not exist in C++.

String class



Java's string class is not an add-on extension but a part of it, and the method of creating and accessing string elements is consistent throughout the system. In C++, string variables are not supported; instead, Null is used as the string terminator.

Built-in support for annotation documentation



Language Type



Java is an interpreted language whose source code is compiled into bytecode by the Java compiler and then interpreted and executed by the Java Virtual Machine. 

C++ is a compiled language in which the source code is compiled and linked to produce executable binary code. Therefore, Java executes slower than C++, but it can be executed across platforms, while C++ cannot.

Programming model

Object-oriented programming

Object-oriented and procedural programming

All Java code (including functions, variables, etc.) must be implemented in classes, and every type except for basic data types (such as int, float, etc.) resides in a class. 

Moreover, Java does not support global variables or global functions, whereas C++ supports both object-oriented and procedural-oriented programming, and can define global variables and global functions.




Java does not have the concept of pointers, eliminating the potential problems associated with manipulating pointers in C++, thus making the program safer.

What features of C++ cannot be replaced by Java?

A thorough understanding of the future trends of both languages requires an examination of their irreplaceability. Programmer Xiao Can offers his opinion on which C++ features cannot be replaced by Java. "The work I do involves the development of game servers. Many people with limited or no experience in this area may not comprehend the sense of accomplishment that comes from knowing that the program you developed runs on a computer and offers a pleasant gaming experience to thousands of users."

From his working experience, he noted that you could predict how much memory will be required, how much network traffic will be needed, how each bit of data flows between the server and the client, and how each int will be distributed in memory.

"It is very elegant, like an infinitely differentiable function." Xiao Can commented, "C++ is like a sharp knife, cutting through tough rocks like butter, enabling you to gracefully break them apart."

Another programmer, whose nickname is West, believes that each language's performance makes a difference. Despite Java's years-long efforts to make its performance closer to C or C++, there remains a gap between Java and native applications. This is not evident in common applications. However, it is crucial for applications with high-performance requirements.

According to him, 3D games like to use up the hardware capacity, so besides the hardware, we have to take Java's performance into account. Most games are still written in C++, even though it is a Java-based platform such as Android.

Comments from Developers


C++ and Java are constantly evolving and improving to be more efficient, offering their advantages for different tasks. In terms of mastering a language, C++ has a steep learning curve, but few people are determined to learn it as a result. It is true that Java is easier to learn and use, but its competition is fierce. Thus, it is a matter of personal preference. It will be interesting to see whether C++ will succeed in overtaking Java in the coming years.

责任编辑:庞桂玉 来源: 51CTO

2022-08-31 14:41:53


2011-07-20 17:48:07


2011-07-20 17:31:12


2015-07-07 11:03:15

Java C++JavaCPP

2009-09-10 14:52:55

C# get

2009-09-11 09:15:06

C# get方法

2013-05-27 15:38:37


2011-04-06 08:57:07


2011-07-14 17:45:06


2011-06-21 15:00:07


2010-01-26 15:51:06


2010-01-28 13:45:06


2011-07-15 00:47:13


2010-01-21 14:07:14


2010-01-21 09:34:57


2010-01-27 16:05:06


2010-01-18 11:05:24


2009-05-22 11:01:53


2009-04-10 13:57:50


2009-09-11 09:15:32

C# get set