Reputation:
So I was talking with a colleague about the point of pointers in C++, and I claimed that Java was the superior language because it handled memory allocation automatically. However, she countered by saying that most of the java packages that handled memory allocation was written in C++. Is this true?
Upvotes: 0
Views: 156
Reputation: 26926
Yes JVM is mostly written in C and C++.
What is different is not how it is handled by the JVM but how the programmer write the code in C and in Java.
In java a coder doesn't need to know problems related to how to handle memory operations (for example you don't need to now how much space allocate, when in C you need to know, you don't have to handle aritmethic on pointers).
What the garbage collections does for you in java is done manually by the programmer in C (and C++).
This doesn't mean that java is superior to C++. It only means that memory is handled differently by the programmer.
Here a list of Pro and Cons of both solutions:
As you can see there are pros and cons for both solutions only considering the equivalent of garbage collection, as you can imagine considering all the aspects of the language is possible to say that there is no a winner but Java is better in some aspect and C++ for others. It is let to you to make the right choice depending on what are you developing.
Upvotes: 3
Reputation: 73558
The JVM is written mainly in C++
so yes, all native operations such as memory allocation is essentially C++ code. However it's still Java's (JVM's) responsibility to implement the automatic allocation and garbage collection, so the fact that it's written in C++
doesn't really mean much. It could be written in any language that allows you to natively access resources, since Java is unable to do that by itself.
Also, talking about which language is "superior" to another is one of the most useless things you can do with your life.
Upvotes: 8