
December 12th, 2012, 01:12 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
The execution of Java programs is quite different than the execution of C++ programs, as are their executables.
Java compiles to bytecode, which is based on a non-existent virtual machine, which must be executed by a special interpreter. That interpreter is designed to expect each class to have its own .class file, so each class must have its own compiled .class file. The design of the interpreter dictates the overall structure of your program and hence dictates that you create a separate .java file for each class.
C++ compiles to native code (in general; some environment such as .NET have their own intermediate languages) and the end result of a C++ build is a native-code executable file no different from one created by C or Pascal or FORTRAN or assembly. All the classes that that C++ program will use are contained within that single executable file.
Therefore, the actual organization of the source code of a C++ program is entirely up to the programmer. Rather than having that overall structure be dictated to him by the programming language, the C++ programmer is free to organize his source code files in response to concerns and considerations of readability, reusability, etc.
|