I\'m preparing for an exam in Java and one of the questions which was on a previous exam was:\"What is the main difference in object creation between Java and C++?\"
I t
Assuming that c++ uses alloc() when the new call is made, then that might be what they are looking for. (I do not know C++, so here I can be very wrong)
Java's memory model allocates a chunk of memory when it needs it, and for each new it uses of this pre-allocated area. This means that a new in java is just setting a pointer to a memory segment and moving the free pointer while a new in C++ (granted it uses malloc in the background) will result in a system call.
This makes objects cheaper to create in Java than languages using malloc; at least when there is no initialization ocuring.
In short - creating objects in Java is cheap - don't worry about it unless you create loads of them.