What are the primary differences between C++ and Java in terms of memory management, compilation, and execution?