Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Comparison of Java and C++
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Runtime === {| class="wikitable" ! style="width:50%;"| C++ ! style="width:50%;"| Java |- | C++ is compiled directly to [[machine code]] which is then executed directly by the [[central processing unit]]. | Java is compiled to [[byte-code]] which the [[Java virtual machine]] (JVM) then [[interpreter (computing)|interprets]] at runtime. Actual Java implementations do [[just-in-time compilation]] to native machine code. |- |} * Due to its unconstrained expressiveness, low level C++ language features (e.g. unchecked array access, raw pointers, [[type punning]]) cannot be reliably checked at compile-time or without overhead at run-time. Related programming errors can lead to low-level [[buffer overflow]]s and [[segmentation fault]]s. The [[Standard Template Library]] provides higher-level RAII abstractions (like vector, list and map) to help avoid such errors. In Java, low level errors either cannot occur or are detected by the [[Java virtual machine]] (JVM) and reported to the application in the form of an [[exception handling|exception]]. * The Java language requires specific behavior in the case of an out-of-bounds array access, which generally requires [[bounds checking]] of array accesses. This eliminates a possible source of instability but usually at the cost of slowing execution. In some cases, especially since Java 7, [[compiler analysis]] can prove a bounds check unneeded and eliminate it. C++ has no required behavior for out-of-bounds access of native arrays, thus requiring no bounds checking for native arrays. C++ standard library collections like std::vector, however, offer optional bounds checking. In summary, Java arrays are "usually safe; slightly constrained; often have overhead" while C++ native arrays "have optional overhead; are slightly unconstrained; are possibly unsafe."
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)