Comparison of Java and C++: Difference between revisions

Content deleted Content added
Line 393:
* The term "[[modular programming|module]]" refers to different things. In Java, a [[Java package#Modules|module]] is used to group several packages together, meanwhile in C++ a [[precompiled header#Modules|module]] represents a single [[translation unit]].
** <code>import</code> in Java is used to alias classes to avoid fully qualifying them. <code>import</code> in C++ imports a module, however in C++, modules do not dictate the namespace which a symbol belongs to.
* A Java source file must match the namespace which of the public class it declares (it may be named anything if there are no public classes), and the package it belongs to must match the path it is located in. A package may only declare at most one public class (but may have multiple non-public classes).
* A C++ source file (whether a header or module) may have any arbitrary name, and may contain as many classes as the programmer desires. Modules have no requirement to match the path of its ___location.
* Compiled Java code files are generally smaller than code files in C++ as [[Java bytecode]] is usually more compact than native [[machine code]] and Java programs are never statically linked.
* C++ compiling features an added textual [[preprocessor|preprocessing]] phase, while Java does not. Thus some users add a preprocessing phase to their build process for better support of conditional compiling.