Why is Java more popular than C++

Pages: 123... 6
:[

Also, what's the difference between C++ and Java classes?
It seems a little different in Java. I just started learning
Java.
In Java, inner-classes can either be attached to an instance of the outer class, or they can be static. There are also no constructors.

The main difference is that Java is single-inheritance (extend only one class) multiple-implementation (implement multiple interfaces). Interfaces are like pure virtual classes in C++ but you cannot have data members or concrete methods.
Java isn't more popular than C++, especially in commercial applications. Perhaps as a beginner language in some computer science courses, but not as much in the real world. It is gaining popularity though, so its definitely good to know it.

Difference between the classes... Well, the syntax mainly, and Java has lots of other specific rules regarding classes (makes sense as the whole language is classes) and n Java, everything is a class.
grrrr..... java..... almost as evil as system()
I personally dislike Java, but there is really nothing horribly, macabrely wrong with it.

As to answer the title question, I did a quick Google and found some nice answers.
I started out disliking Java, having learned C++ first, but I eventually realized I was trying to compare and contrast it to C++ - after that I started to accept Java as a language built to support specific design patterns whereas C++ is very general.
closed account (S6k9GNh0)
I don't like Java as a language. I also don't like any general implementation of a language that forces a memory model. I also seem to have gone Java, C, C++, C with hatred of Java. C++ really made me see the complications of OOP programming and how its used in many unnecessary situations. I don't like everything being represented as an Object in Java.
The reason why its so popular is that Java doesn't compile like c++.

When you compile c++ the program compiles into machine code designed to run on a specific chipset. This makes the code not very portable; you cannot compile a c++ program on a x86 machine and reasonably expect it to run on an Apple. What you would need is some kind of "bridge" that connects the code the programmer writes into a system that interprets for the machine that its running on.

This is the concept of Java. You don't really compile a Java program, but instead send it to the actively running Java machine that then, at the time of use, complies the program and runs it on the machine that the user is operating. This machine is called the Java "virtual machine", and you probably have experience with it any time you load a Java program, its the program that loads in the background.

This is why Java is more popular. You can write code that can reasonably run on any machine.

There are limitations to this however. One of the biggest and a major reason why people don't use Java is that Java does not provide access to the memory or the chipset. There's a whole layer that you as the programmer do not have access. And this irritates people!
closed account (S6k9GNh0)
You still need a separate implementation of the standard libraries for each platform that Java supports. The same can be done for a library in C++ and is done all the time (OpenGL, SDL, SFML, OpenAL, udev, several games, the STL, almost all of the Boost libraries, so on).

An application may have to be recompiled for a library update but there are ways to manage this on the library side (position independence).

Also, you compile Java into bytecode, much like how you compile C++ into something the OS you're compiling for can understand. The implementation is different (and probably simplified) but the concept is very similar.

The JVM in concept is actually pretty cool. I just don't see a lot of realistic use for it compared to alternatives.
Last edited on
There are lots of reasons why Java is very popular:

1. Managed memory model. No dangling pointers. No buffer overruns. Much harder to create memory leaks than in C or C++.
2. Security. You can precisely control, what code can and what can't do. Private is private, you can't e.g. set a private property of an object, if you don't have rights to.
3. Huge standard library. Lots of third-party libraries.
4. Well standardized and portable, no problems with non-standard compilers.
5. High performance, great support for multicore.
6. Simple language, much fewer caveats and sharp-edges than in C++.
7. Awesome tooling.
8. Compile times orders of magnitude faster than for C++.
9. If you can't do something with Java, you can still call native code from your program.
10. Can be used to create mobile-apps and web-apps, while with C++, although possible, it is not that easy.



There are limitations to this however. One of the biggest and a major reason why people don't use Java is that Java does not provide access to the memory or the chipset. There's a whole layer that you as the programmer do not have access. And this irritates people!


Not true. I can call to OS from Java anytime I wish. I can even call malloc, wrap it into direct ByteBuffer and use it directly from Java code, without a single line of C. We use it all the time in Apache Cassandra - therefore lots of data is kept off-heap. And as far as I know, although it is pure Java, considering performance and scalability, it beats all the other big data NoSQL database engines, including those written in C++, e.g. MongoDB.


after that I started to accept Java as a language built to support specific design patterns whereas C++ is very general.


In reality it is just the other way round. People use C++ only for very specific reasons now: legacy systems, low latency systems with low memory (low latency with enough memory is not a problem for Java, though), AAA 3D games, sometimes some scientific HPC stuff, some desktop apps (but this era is over, too; e.g. Firefox frontend is already using lots of JS). For all the rest, there are better, more general purpose languages and Java is one of them. For 99% cases you don't need to fit in 10MB RAM, nor have <10 ms guaranteed latency.
Last edited on
2. Using reflection you can get and set private and protected data members and call private and protected methods. Though, it does require you to call setAccessible() on the Field instance.
6. Read "Java Puzzlers"?

As for your response to me, I was talking about the way you write code, not the way you use code.
There are a lot of reasons why a programming language becomes popular. Luck, timing, marketing of the language - all these play a role.

Given that the luck factor is right, IMHO, how easy it is to learn a programming language is the most important ingredient which makes up for the popularity of a programming language. The technical merits of the language itself has very little to do with its popularity. As long as it has no first degree technical defects, a language that is very easy to learn is likely to become more widely used.

Bigots++ and JBigots have argued the relative technical merits, specific features that the languages support etc. endlessly, in endless debates; bigots tend to suffer from verbal diarrhea. Though this is a C++ site, we do have a resident JBigot, and if we so wish, we can continue the debate here too.

Extracts from an interview that appeared in 'The C++ Report' and 'The Java Report' in July 2000:

Q: The C family of languages - C, C++, and Java - has dominated commercial programming for over 30 years. Why has the C family of languages become so successful and so widely used?

Dennis Ritchie: This has always been a bit of a mystery to me to understand in any kind of detail. Obviously the use of C was during early times considerably encouraged by its use as the lingua franca of Unix during the period that Unix was growing in the research and academic community, and then when Unix was taken up as the software basis for the workstation industry of the '80s. This in turn had to do in part with the non-political nature of C and Unix (not tied to a power) ....

Bjarne Stroustrup: C and C++ became popular because they were flexible, cheap, and more efficient than alternatives. C owes much of its initial popularity to the popularity of Unix. C++ owes much of its initial popularity to its high degree of compatibility with C. ...

James Gosling: I think that the number one reason is that it's been generally a very pragmatic family of languages. By and large they weren't experiments in language design; they were put together as tools by people who wanted to do something ...



Q: In your experience, how long does it take for a novice programmer to become a reasonably proficient C/C++/Java developer, capable of writing nontrivial production code? How long for a programmer with experience in one or more other languages? How can this time be shortened?

Ritchie: I don't know the answer to this question either - my stock joke on similar ones is, "Well, I never had to learn C...."

Stroustrup: For a novice programmer, a year and a half seems appropriate; for a programmer who is a novice to C++ and the techniques it supports half a year seems more likely.

Gosling: I know that for somebody who is a pretty talented C++ programmer, an afternoon pretty much does it for lots of folks. You'll probably spend a lot of time going through the library manual. The language itself tends to be a snap to learn; it's all the library stuff that takes the time.


2. Using reflection you can get and set private and protected data members and call private and protected methods. Though, it does require you to call setAccessible() on the Field instance.


If I set up a SecurityManager you can shove your setAccessible() call up your ass. You'd have to break up from JVM sandbox by exploiting some vulnerability, but these are rare and fixed very fast.

6. You can create puzzlers for any language. I didn't say there aren't any caveats in Java, but that there are much less than in C++. The language is much, much simpler and smaller and additionally, unlike C++, Java has decidable, context-free (exactly LL(k)) grammar.
Last edited on
I agree except for this part:
rapidcoder wrote:
Java has decidable, context-free (exactly LL(k)) grammar.
Why can't inner classes have static members? http://ideone.com/HuZvB
Last edited on
Checking syntactic correctness is context free for most programming languages.

Checking semantic correctness in any programming language which is not type-less and allows creation of user defined types, is by definition, not context-free.

Gosling is right when he says:
I think that the number one reason is that it's been generally a very pragmatic family of languages. By and large they weren't experiments in language design; they were put together as tools by people who wanted to do something ...
Last edited on
Java suxxx....long compilation, heavy IDE, not instinctive too far from real hardware :)
More personally i dont like object that can look himself without knowing how..
But it's an opinion cause there are a lot of usefull frameworks that can help for specific application(JavaBeans,EJB) and native library binding (like jogl for 3D) that are very efficient.
All depend on what you focus to create : a heavy factory or a light weight and efficient application...
Last edited on
For starters, Java is not more popular than C++.
The only reason anyone uses it at all could be for three popular reasons:

1. They don't know that there are more efficient languages out there like C# or C++.
2. They are learning the basics of object oriented programming.
3. They are using the JVM for what it's meant for: portable (cross-platform) applications

The third reason is the only reason why a logical programmer would use Java. But C/C++ applications are starting to become more portable by shipping the application in make-able source code form, so you can make it on any platform you have.

In all honesty, Java isn't that good for general purpose programming. But if you're making a fun little app (e.g. Minecraft), then go ahead.
closed account (3hM2Nwbp)
If I set up a SecurityManager you can shove your setAccessible() call up your ass.


I would be very curious to interview java programmers regarding security management. My guess would be that they would be as oblivious to them as they are to items in the java.lang.ref package. Also, be very careful about boasting to have direct access to native resources, as there is a significant overhead involved in most cases...

P.S. What overhead is incurred by a "properly" set up SecurityManager? Has anyone ever benchmarked the approximate cost of running in a sandbox?

P.P.S.
low latency with enough memory is not a problem for Java, though


Might as well put in the rest of the story here. low latency with enough memory and slow enough garbage production

I just love it how Java enthusiasts frequently only paint half of the real picture to make Java look better than it really is...
Last edited on

For starters, Java is not more popular than C++.


It is and I can prove this. Go to any big site offering programming jobs. The demand for Java programmers, as well as for .NET programmers is more than two fold higher than for C++ programmers. This means there is more code written in Java than in C++. The similar thing is if you compare the numbers of open source projects by language. Java is certainly more popular than C++ now.
rapidcoder wrote:
This means there is more code written in Java than in C++.
Are you sure it is not that they want it that way? Surely you don't hire someone to produce something you already have enough of.
Pages: 123... 6