user2743227
user2743227

Reputation:

Are java packages written in C++?

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

Answers (2)

Davide Lorenzo MARINO
Davide Lorenzo MARINO

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:

  • Easy to develop (Pro Java, Cons C++)
  • Decide when to deallocate memory (Pro C++, Cons Java)
  • Decide how to deallocate memory in detail (Pro C++, Cons Java)
  • Possibility to lost to deallocate memory (Pro java, Cons C++)
  • Quantity of memory to handle the deallocation process (Pro C++, Cons java)

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

Kayaman
Kayaman

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

Related Questions