Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Comparison of Java and C++
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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."
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Comparison of Java and C++
(section)
Add topic