Java vs. C++ architecture, C++ memory model

 Java Architecture             C++ Language Architecture
+--------------------+         +--------------------+
|                    |         |                    |
|   Source Code      |         |   Source Code      |
| (e.g., Hello.java) |         | (e.g., hello.cpp)  |
|                    |         |                    |
+--------------------+         +--------------------+
          |                              |
          |                              |
          v                              v
+--------------------+         +--------------------+
|                    |         |     Compiler       |
|   Java compiler    |         +--------------------+
|                    |                   |
+--------------------+                   |
          |                              v
          |                    +--------------------+
          v                    |    Object code     |
+---------------------+        |  (e.g., hello.obj) |
|                     |        +--------------------+
|      Byte code      |                  |
| (e.g., Hello.class) |                  v
|                     |        +--------------------+
+---------------------+        |      Linker        |
          |                    +--------------------+
          |                              |
          v                              v
+---------------------+        +--------------------+
|Java Virtual Machine |        |    Machine code    |
|        (JVM)        |        +--------------------+
|  +---------------+  |                  |  
|  |       OS      |  |                  v
|  |  +---------+  |  |          +-----------------+   
|  |  |   CPU   |  |  |          |       OS        |
|  |  +---------+  |  |          |  +-----------+  |
|  +---------------+  |          |  |   CPU     |  |
+---------------------+          |  +-----------+  |
                                 +-----------------+
Java has both a compiler and a Virtual machine (an interpreter). The compiler takes source code and translates it into another simpler (but less human readable) language called byte code. The byte code is executed during run time (while the program is running) by the Java Virtual Machine (JVM).

C++ is purely compiled. The source code is translated into object code, which is similar in nature to byte code. Whereas all Java byte code is the same, there are no rules for what C++ object code looks like. Each C++ source code file produces its own object code file. Because code in a file may reference code in another file, all the object code is sent to a linker which resolves any missing addresses (when different files refer to each other). Then this object code is translated into machine code (what the machine can actually execute) and one executable file is created.

The C++ memory model
The C++ memory model differs from the Java memory model. In C++, memory comes from two places, the run time stack and the memory heap.

In C++, when you invoke a function a chunk of memory, called an activation record or stack frame, is allocated that includes all necessary things for that function: memory for the parameters, memory for locals, address of where to return when the function finishes, etc. This memory is pushed on to the run time stack, a collection of these activation records. When the function finishes, the record is popped off the stack, i.e., the memory is released, so it can be reused.

In C++, when you dynamically allocate memory using the new operator, the memory comes off the memory heap.