Comparison of Java and C++: Difference between revisions

Content deleted Content added
m remove broken wikilink
Line 290:
// LEGAL, the object can still be modified</syntaxhighlight>
|}
* C++ supports <code>[[goto]]</code> statements, which may lead to [[spaghetti code]] programming. With the exception of the goto statement (which is very rarely seen in real code and highly discouraged), both Java and C++ have basically the same [[control flow]] structures, designed to enforce [[Structured programming#Low-level structure programming|structured control flow]], and relies on [[Control flow#Early exit from loops|break and continue]] statements to provide some <code>goto</code>-like functions. Some commenters point out that these labelled flow control statements break the single point-of-exit property of structured programming.<ref name="Martin">{{cite web|url=http://www.objectmentor.com/resources/articles/javacpp.pdf|title=Java vs. C++: A Critical Comparison|date=January 1997|author=Robert C. Martin|access-date=15 December 2007|archive-url=https://web.archive.org/web/20080511205821/http://www.objectmentor.com/resources/articles/javacpp.pdf|archive-date=11 May 2008|url-status=dead}}</ref>
* C++ provides low-level features which Java mostly lacks (one notable exception being the <code>sun.misc.Unsafe</code> API for direct memory access and manipulation). In C++, pointers can be used to manipulate specific memory locations, a task necessary for writing low-level [[operating system]] components. Similarly, many C++ compilers support an [[inline assembler]]. Assembly language code can be imported to a C program and vice versa. This makes C language even faster. In Java, such code must reside in external libraries, and can only be accessed via the [[Java Native Interface]], with a significant overhead for each call.