Question:
C++ vs. Java. Which is better to learn and why?
anonymous
2013-04-03 14:38:48 UTC
C++ vs. Java. Which is better to learn and why?
Nine answers:
The Shadowman
2013-04-03 14:43:35 UTC
A true programmer doesn't war 2 languages, he learns as much language as possible.



Edit: I'm pretty sure all the thumbs down are coming from python people who are scare to show up with a comment.
justme
2013-04-04 20:59:26 UTC
Neither one is better, in general, than the other. What it comes down to is what do you want to do with the language you learn. If you need something that will run on multiple platforms, then Java is the preferred language. If its meant to run on only one platform, or speed is a requirement then C++ would be preferred.



If you can, learn both.



I learned C++ before Java, therefore I hate Java.
Andrew
2013-04-05 19:03:04 UTC
Short answer: C++ is a superset of Java, thus learning C++ first would help to understand what Java actually is. However, Java is more than a language so read on.



Long answer:

A programming language is merely a tool just like a drill machine is a tool. You won't use ground drilling machine on a wall and won't use a wall drilling machine on the ground as they have different applications and capabilities. I believe this will give you an idea of what I am heading toward.



Coming down to specific details:

1) C++ and Java are similar in terms of syntax. That is, if you learn one language you automatically learn 98% of the other.

2) Both these languages are object oriented programming (OOP) languages. OOP is a paradigm and it is intended to force the programmer to write the program in a better way meaning commit less errors from a high level or design point of view. It is better then structured programming, which is what C is. However, once in executable (binary) form there is no C++ and C it is just plain machine instructions. Java executables are different, see below.

3) C++ inherited syntax from C and continued to allow low level programming possibilities like low level control over the underlying hardware. As such you will see pointers and multiple inheritance and what not which Java designers decided to remove when they sat down to make Java.

4) A C++ compiler generates the executable using the designated processor's or a group of processors' instruction set. For example you have to tell it to generate an executable for pentium or 386 or AMD or ARM or PPC or MIPs etc and multiple versions of them! By default it generates executable for the host machine's processor. When the executable is generated for a designated processor (and OS) it will naturally run faster. However, the problem is that it won't execute on any non-compatible processors or OSes. Thus, if the programmer wishes to support the program on multiple platforms (processor + OS combination) he will have to add conditional code and conditionally compile for each platform he wants to support and thus he would end up with one executable per supported platform. Conditional compilation requires a lot of hard work. Anyways, I believe 50% or more programmers work on one platform at a time and they do not need to worry about multiple platforms.

5) Java designer wanted to solve the problem of supporting multiple platforms. That is, a single executable should run on any platform. So the solution was to generate what they call byte code. All executables generated with Java are made of byte codes. A byte code is equivalent to a processor instruction. And then they made what they call the virtual machine, which is basically equivalent to a processor/OS combination (in other words a platform). And they make virtual machines for each platform they want Java to run on. (BTW, these VMs are made in C/C++). The VM run in the background. When it is given a Java executable (byte codes) to execute, it reads the byte code one by one and executes them on the real hw processor underneath. Thus, Java executables are naturally slow because of the interpretation step in between. However, you can execute the same Java executable on any platform where you have a JVM.



So you see, it depends on what you are doing that will tell you which language to use.



BTW, it is very much possible to create a VM, lets name it XVM, that simulates a unique platform. Then enhance all C++ compilers to generate executables for the same. That way you can make can executable using all the features of C++ and execute the same on any platform that has XVM installed. However, it would naturally execute at a slower speed compared to a native executable. This is similar to what Java does but the difference is that you get all the C++ features which also includes low level access to the underlying hardware.



Alternatively, if we had only one platform in the world then there was need to for a Java like thing and it would have been easy to make one executable and run on any device (computer, smartphone, satellite, rovers, you name it.
Jacob
2013-04-03 21:44:06 UTC
You are going to get lots of mixed answers. ones from java programmers who think it is better because of this and that, etc. And those from C++ programmers. Personally I like the C++ syntax better, and it is great for console applications, but it is lacking when it comes to Graphical applications. Java is much better for Graphics, but the console commands are long and unnecessary. Good Luck!
godfatherofsoul
2013-04-05 04:20:45 UTC
Java is a MUCH better learning language as its syntax is cleaner. With C++ new programmers spend more time struggling to learn the syntax.
Calvin K
2013-04-04 07:05:24 UTC
I was told that a good programmer should learn one language each year.

Therefore, order of languages to learn is strictly personal preference.
?
2013-04-03 22:00:04 UTC
C++ is alot harder languege to learn

even thought i am a java software developer do c++ first

then you can start learning java from here http://docs.oracle.com/javase/tutorial/index.html

i am trying to learn c++ but am struggling cause l laened java first
Moji
2013-04-04 06:32:32 UTC
Wrong question ;)



it would be better, if you asked which platform:



Android



iOS



Web developing



Desktop Developing



Game Developing



and so on
Michael
2013-04-05 00:48:48 UTC
Java. It is used a lot more and you get more pay. It also has more things in it without external APIs and stuff like that.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...