Java and C++ are the most popular Programming Languages Worldwide. Although Java is newer, still it has managed to gain immense popularity. Both of these languages have wide variety of applications and have become an important part of the Cyber world.
If you are not familiar with both these programming Languages, and are confused with which one to start with, then I would recommend that you learn C first, and then you can dive into OOPs either with Java or C++, depending on your requirements, which the rest of this post will explain.
For those who are already familiar with both or one of these languages, must be here to see if they really picked up the right language. Let’s Find Out.
Speed:
C/C++ is Faster than Java, always. This is simply because the when we compile a Java Program all the Classes have to be loaded first and then the program is compiled. Secondly, JVM(Java Virtual Machine), is itself written in C. So, its Obvious that C or C++ programs will run/compile quicker than a Java Program. This difference becomes insignificant in case of Larger Applications or Softwares.
So, if you are thinking of participating in a Programming Competition, you do not want to use Java.
Performance:
The Performance of both these Languages is excellent. Isn’t it obvious, for such hugely popular languages. If you pick up any of these languages you won’t face any performance issues at all. C/C++ and Java are both sufficiently old languages, and are being constantly updated with more and more features/functions and while debugging the bad ones.
Applications:
Java and C/C++ have wide variety of applications. And this is what you should consider while choosing which language to pursue between Java and C++.
Software Development
If you are Looking to Build Softwares for Windows or any Operating System, Java is a much better Language to use. Mainly, Because of its Portability. Your single Java Code/Application will run in all Operating Systems(Windows, Mac, Linux) without making any major changes in the code. Java Also offers many Exciting GUI libraries which are easy to use and help you build some exciting user interface for your applications.
Android Applications
Android Applications are written in Java. There is nothing there for C/C++ Developers. So, if Android Development is a part of your plan you should really dive into Java.
Windows/iOS Applications
Although, the Newer Windows Phones and iOS 6 use C# and Objective-C. But, if you are a C++ Developer there are certain provisions for you too as well. But, You won’t be able to do much with C++. So, it will be better to learn the respective languages(C#, O-C) instead.
Server Side Programming/Website Developement
You can do the Server side Programming for a Website with both Java and C++. Although, Java is more popular and you will find more support for it. Whenever you see a website which uses .jsp as extension for most of their pages, you should conclude that its server-side is programmed in Java.
But, for Other Server Side Processes which do not directly affect your websites front-end, C++ is better recommended due to its speed for smaller applications. Google uses a lot of C++ for its Search Algorithms.
Btw, PHP is the Most Popular Server Side Languages with over 60-65% Websites using it.
Operating System
If you are into Development of Operating system, I do not really mean, writing your own Os. But, if you like to get into the core of Linux, or build Linux applications or derive/build your own OS based out of Linux, then C++ is going to be of Great Help. Being able to do this might land you really good jobs, probably as a Server Administrator at a Web Hosting Company. 😛
You can never Build an Operating system purely with Java. But it is possible with C or C++.
Game Development
C++ and Java both are Good languages for Game Development. But, I feel Python will overtake both these languages at a later time as a preferred language for Game Dev. Most Games for PC, are written in C/C++. Mobile Games are Generally Written in Java. Complex Games for Consoles are Also written in C/C++. Your Games like Call of Duty, Modern Warfare, etc are all C++.
But, the Main Component of a Game Development is a Graphics Library(e.g OpenGL) and not the Programming Language. So, if you are willing to do Game Development, you should pick up C++ or Java(anyone) and also learn using OpenGL. Support for OpenGL is available with most programming languages, including Java & C++. But, if You choose Java your games can be easily ported on Android which is the most popular Gaming Platform for Handheld Devices.
Awesome tutorial….it gives a lot of knowledge about uses of various programming languages .
if You choose Java your games can be easily ported on Android which is the most popular Gaming Platform for Handheld Devices.
I cannot agree on this. Android has a totally different framework on which a game has to be built.
That’s true. Android is indeed a totally different framework. Especially with the changes in last 2 years, it has become a little more advanced with bigger and more powerful library. But, still as of today, it would be realtive much easier to port a Java Game to Android rather than something which is in C++.
I agree with your general statement that C will be faster than Java but there are conditions where it is not. For example I recently ran tests that had to parse about 500 million doubles from a 800 megabyte CSV file. The standard library for strtod in C is relatively slow and actually under performed Java. This wasn’t really a language issue but an instance of where a great library can overcome the differences between languages. When found a faster function for parsing float C went from slower to 4X faster.
The main performance issue in Java applications stems from wasteful allocation and destruction of objects especially in some of the common libraries but most of the C++ code I see also has very similar waste problems and degrades under the burden of new / deletes. I have seen instances where under this kind of idiomatic waste that the Java GC actually out performs the C++ interaction with the OS memory system due to heap fragmentation. I am not claiming this is endemic to either language but the idiomatic use of either tends to create the issue.
The main advantage I have found with C is that the engineers I hire for high performance C rather than general purpose C++ are also guru’s in how to think about minimizing object allocation / destruction. This also tends to make them GURUs for avoiding wasteful copying and wasteful multi-step transformations. This is where we see the main performance gains for larger applications. On the other hand these same engineers can apply similar techniques in GO and Java and get similar results.
It is actually funny to watch the code reviews where the typical Java engineers object because the performance GURU didn’t use a wasteful library or they violated typical design patterns. Unless they have good protection from the senior architects and directors they just give up and follow the idiomatic patterns or quit and leave the team both of which result in products that run slower.
I know that wasteful early optimization can be a issue in engineering but being too wasteful is a great way to ensure a product fails. Users have a minimum expectation for performance and now days that is compounded where wasteful code correlates almost directly to more CPU cycles which correlates to shorter battery life. As a person commonly hired to salvage projects that are in trouble I know that at least 60% of these issues stem from poor performance which is then compounded when product management makes really odd decisions for features to work around the performance problems. If you catch it late in the cycle it can be expensive to fix. If I can catch it early in the life cycle then it can be relatively inexpensive to avoid but it does require education and senior sponsorship.
Thanks Joe, for your insight. I am sure, readers will find your insight useful.
you can program for android with c or c++! AFAIK i think you can do it in some otherlanguages!
Yes You Can! But, There are too many restriction. More Modern Frameworks are being made to help you code in any language. Right Now, you can use Apple’s SpriteKit to Build an Android app as well. But, the things you can do with native apps, can not be done with others.
Well I haven’t used it, but there is NDK for Android which let you develop app in c or c++ as well. I think we can use Qt or some other software to develop app. Not sure