I\'m in a job hunting. And in my CV I placed a skill list like: Skills: C/C++/Ja
ID: 654953 • Letter: I
Question
I'm in a job hunting. And in my CV I placed a skill list like:
Skills: C/C++/Java/...
The most common question I got is: "hem, since you are familiar with both C++ and Java, can you tell some similarities or difference between the two languages."
And I just don't know how to answer, what I said is basically some language level details like they have some different keywords like Interface,abstract and so on. I want to see some comparison in high level like the difference in generics, the garbage collector and so on.
At least I want to go deep into one side, that is the resource management. Java has no lifetime for an object, this is managed by the garbage collector, and in C++ you need to carefully manage your resource especially for the heap. In C++ we can greatly reduce the memory leak by introducing RAII, using object to manage the heap memory, and so is for the other resources like connection,lock and so on. I am not sure what to do in Java, because the garbage collector can only be a nice tools for the management of heap memory (AFAIK ).
Question: How can we manage other resources in an situation that we do not have a destructor to do all these automatically? Do we need to manually guarantee that the resources be returned in a right place. And how?
Explanation / Answer
Java 7 has try-with-resources to handle non-memory resources. You can implement java.lang.AutoCloseable to use it with your own objects. RAII wasn't an original design intent for destructors, it was "discovered" later and only came into vogue in the late 90s, early 2000s, after Java was created. That's why Java 1-6 didn't have any RAII-like construct.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.