CINXE.COM

Comparison of Java and C++ - Wikipedia

<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <title>Comparison of Java and C++ - Wikipedia</title> <script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy", "wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"b096cb3f-6b84-402c-ae60-5f95fc77b3a8","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"Comparison_of_Java_and_C++","wgTitle":"Comparison of Java and C++","wgCurRevisionId":1259576150,"wgRevisionId":1259576150,"wgArticleId":42922,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Webarchive template wayback links","Articles with short description","Short description is different from Wikidata","Articles needing more viewpoints from May 2016","Articles with self-published sources from September 2010","All articles with self-published sources","Articles that may contain original research from August 2012","All articles that may contain original research","Articles with multiple maintenance issues","Use dmy dates from January 2021", "Articles needing additional references from September 2010","All articles needing additional references","All articles with specifically marked weasel-worded phrases","Articles with specifically marked weasel-worded phrases from March 2012","Comparison of individual programming languages","Java (programming language)","C++"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Comparison_of_Java_and_C++","wgRelevantArticleId":42922,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":false,"wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby": true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":70000,"wgRelatedArticlesCompat":[],"wgCentralAuthMobileDomain":false,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage","wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q907151","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","ext.pygments":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready", "jquery.makeCollapsible.styles":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.interlanguage":"ready","wikibase.client.init":"ready","ext.wikimediaBadges":"ready"};RLPAGEMODULES=["ext.cite.ux-enhancements","ext.pygments.view","ext.scribunto.logs","site","mediawiki.page.ready","jquery.makeCollapsible","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.gadget.ReferenceTooltips","ext.gadget.switcher","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.popups","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.interface","ext.cx.eventlogging.campaigns","ext.cx.uls.quick.actions","wikibase.client.vector-2022","ext.checkUser.clientHints","ext.quicksurveys.init","ext.growthExperiments.SuggestedEditSession","wikibase.sidebar.tracking"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=ext.cite.styles%7Cext.pygments%2CwikimediaBadges%7Cext.uls.interlanguage%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediamessages.styles%7Cjquery.makeCollapsible.styles%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles%7Cwikibase.client.init&amp;only=styles&amp;skin=vector-2022"> <script async="" src="/w/load.php?lang=en&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.4"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=1120"> <meta property="og:title" content="Comparison of Java and C++ - Wikipedia"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="alternate" media="only screen and (max-width: 640px)" href="//en.m.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B"> <link rel="alternate" type="application/x-wiki" title="Edit this page" href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit"> <link rel="apple-touch-icon" href="/static/apple-touch/wikipedia.png"> <link rel="icon" href="/static/favicon/wikipedia.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="Wikipedia (en)"> <link rel="EditURI" type="application/rsd+xml" href="//en.wikipedia.org/w/api.php?action=rsd"> <link rel="canonical" href="https://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en"> <link rel="alternate" type="application/atom+xml" title="Wikipedia Atom feed" href="/w/index.php?title=Special:RecentChanges&amp;feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="//login.wikimedia.org"> </head> <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject mw-editable page-Comparison_of_Java_and_C rootpage-Comparison_of_Java_and_C skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Main menu</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Main menu</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navigation </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/Main_Page" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-contents" class="mw-list-item"><a href="/wiki/Wikipedia:Contents" title="Guides to browsing Wikipedia"><span>Contents</span></a></li><li id="n-currentevents" class="mw-list-item"><a href="/wiki/Portal:Current_events" title="Articles related to current events"><span>Current events</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Special:Random" title="Visit a randomly selected article [x]" accesskey="x"><span>Random article</span></a></li><li id="n-aboutsite" class="mw-list-item"><a href="/wiki/Wikipedia:About" title="Learn about Wikipedia and how it works"><span>About Wikipedia</span></a></li><li id="n-contactpage" class="mw-list-item"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us" title="How to contact Wikipedia"><span>Contact us</span></a></li> </ul> </div> </div> <div id="p-interaction" class="vector-menu mw-portlet mw-portlet-interaction" > <div class="vector-menu-heading"> Contribute </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-help" class="mw-list-item"><a href="/wiki/Help:Contents" title="Guidance on how to use and edit Wikipedia"><span>Help</span></a></li><li id="n-introduction" class="mw-list-item"><a href="/wiki/Help:Introduction" title="Learn how to edit Wikipedia"><span>Learn to edit</span></a></li><li id="n-portal" class="mw-list-item"><a href="/wiki/Wikipedia:Community_portal" title="The hub for editors"><span>Community portal</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes to Wikipedia [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_upload_wizard" title="Add images or other media for use on Wikipedia"><span>Upload file</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/Main_Page" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/wikipedia.png" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="Wikipedia" src="/static/images/mobile/copyright/wikipedia-wordmark-en.svg" style="width: 7.5em; height: 1.125em;"> <img class="mw-logo-tagline" alt="The Free Encyclopedia" src="/static/images/mobile/copyright/wikipedia-tagline-en.svg" width="117" height="13" style="width: 7.3125em; height: 0.8125em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Search Wikipedia [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search Wikipedia" aria-label="Search Wikipedia" autocapitalize="sentences" title="Search Wikipedia [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page&#039;s font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Appearance" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Appearance</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=C13_en.wikipedia.org&amp;uselang=en" class=""><span>Donate</span></a> </li> <li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:CreateAccount&amp;returnto=Comparison+of+Java+and+C%2B%2B" title="You are encouraged to create an account and log in; however, it is not mandatory" class=""><span>Create account</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&amp;returnto=Comparison+of+Java+and+C%2B%2B" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o" class=""><span>Log in</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="Log in and more options" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Personal tools</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=C13_en.wikipedia.org&amp;uselang=en"><span>Donate</span></a></li><li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:CreateAccount&amp;returnto=Comparison+of+Java+and+C%2B%2B" title="You are encouraged to create an account and log in; however, it is not mandatory"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Create account</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&amp;returnto=Comparison+of+Java+and+C%2B%2B" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li> </ul> </div> </div> <div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" > <div class="vector-menu-heading"> Pages for logged out editors <a href="/wiki/Help:Introduction" aria-label="Learn more about editing"><span>learn more</span></a> </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [y]" accesskey="y"><span>Contributions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [n]" accesskey="n"><span>Talk</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><!-- CentralNotice --></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contents</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">(Top)</div> </a> </li> <li id="toc-Design_aims" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Design_aims"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>Design aims</span> </div> </a> <ul id="toc-Design_aims-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Language_features" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Language_features"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Language features</span> </div> </a> <button aria-controls="toc-Language_features-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Language features subsection</span> </button> <ul id="toc-Language_features-sublist" class="vector-toc-list"> <li id="toc-Syntax" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Syntax"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1</span> <span>Syntax</span> </div> </a> <ul id="toc-Syntax-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Semantics" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Semantics"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.2</span> <span>Semantics</span> </div> </a> <ul id="toc-Semantics-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Resource_management" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Resource_management"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3</span> <span>Resource management</span> </div> </a> <ul id="toc-Resource_management-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Libraries" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Libraries"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.4</span> <span>Libraries</span> </div> </a> <ul id="toc-Libraries-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Runtime" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Runtime"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.5</span> <span>Runtime</span> </div> </a> <ul id="toc-Runtime-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Templates_vs._generics" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Templates_vs._generics"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.6</span> <span>Templates vs. generics</span> </div> </a> <ul id="toc-Templates_vs._generics-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Miscellaneous" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Miscellaneous"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7</span> <span>Miscellaneous</span> </div> </a> <ul id="toc-Miscellaneous-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Performance" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Performance"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>Performance</span> </div> </a> <ul id="toc-Performance-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Official_standard_and_reference_of_the_language" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Official_standard_and_reference_of_the_language"> <div class="vector-toc-text"> <span class="vector-toc-numb">4</span> <span>Official standard and reference of the language</span> </div> </a> <button aria-controls="toc-Official_standard_and_reference_of_the_language-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Official standard and reference of the language subsection</span> </button> <ul id="toc-Official_standard_and_reference_of_the_language-sublist" class="vector-toc-list"> <li id="toc-Language_specification" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Language_specification"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1</span> <span>Language specification</span> </div> </a> <ul id="toc-Language_specification-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Trademarks" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Trademarks"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2</span> <span>Trademarks</span> </div> </a> <ul id="toc-Trademarks-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-References" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#References"> <div class="vector-toc-text"> <span class="vector-toc-numb">5</span> <span>References</span> </div> </a> <button aria-controls="toc-References-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle References subsection</span> </button> <ul id="toc-References-sublist" class="vector-toc-list"> <li id="toc-Citations" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Citations"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1</span> <span>Citations</span> </div> </a> <ul id="toc-Citations-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Sources" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Sources"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.2</span> <span>Sources</span> </div> </a> <ul id="toc-Sources-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-External_links" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#External_links"> <div class="vector-toc-text"> <span class="vector-toc-numb">6</span> <span>External links</span> </div> </a> <ul id="toc-External_links-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">Comparison of Java and C++</span></h1> <div id="p-lang-btn" class="vector-dropdown mw-portlet mw-portlet-lang" > <input type="checkbox" id="p-lang-btn-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-lang-btn" class="vector-dropdown-checkbox mw-interlanguage-selector" aria-label="Go to an article in another language. Available in 5 languages" > <label id="p-lang-btn-label" for="p-lang-btn-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--action-progressive mw-portlet-lang-heading-5" aria-hidden="true" ><span class="vector-icon mw-ui-icon-language-progressive mw-ui-icon-wikimedia-language-progressive"></span> <span class="vector-dropdown-label-text">5 languages</span> </label> <div class="vector-dropdown-content"> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li class="interlanguage-link interwiki-ko mw-list-item"><a href="https://ko.wikipedia.org/wiki/%EC%9E%90%EB%B0%94%EC%99%80_C%2B%2B%EC%9D%98_%EB%B9%84%EA%B5%90" title="자바와 C++의 비교 – Korean" lang="ko" hreflang="ko" data-title="자바와 C++의 비교" data-language-autonym="한국어" data-language-local-name="Korean" class="interlanguage-link-target"><span>한국어</span></a></li><li class="interlanguage-link interwiki-ja mw-list-item"><a href="https://ja.wikipedia.org/wiki/Java%E3%81%A8C%2B%2B%E3%81%AE%E6%AF%94%E8%BC%83" title="JavaとC++の比較 – Japanese" lang="ja" hreflang="ja" data-title="JavaとC++の比較" data-language-autonym="日本語" data-language-local-name="Japanese" class="interlanguage-link-target"><span>日本語</span></a></li><li class="interlanguage-link interwiki-no mw-list-item"><a href="https://no.wikipedia.org/wiki/Forskjeller_mellom_C%2B%2B_og_Java" title="Forskjeller mellom C++ og Java – Norwegian Bokmål" lang="nb" hreflang="nb" data-title="Forskjeller mellom C++ og Java" data-language-autonym="Norsk bokmål" data-language-local-name="Norwegian Bokmål" class="interlanguage-link-target"><span>Norsk bokmål</span></a></li><li class="interlanguage-link interwiki-fi mw-list-item"><a href="https://fi.wikipedia.org/wiki/Java-_ja_C%2B%2B-ohjelmointikielten_vertailu" title="Java- ja C++-ohjelmointikielten vertailu – Finnish" lang="fi" hreflang="fi" data-title="Java- ja C++-ohjelmointikielten vertailu" data-language-autonym="Suomi" data-language-local-name="Finnish" class="interlanguage-link-target"><span>Suomi</span></a></li><li class="interlanguage-link interwiki-zh mw-list-item"><a href="https://zh.wikipedia.org/wiki/Java%E5%92%8CC%2B%2B%E7%9A%84%E5%B0%8D%E7%85%A7" title="Java和C++的對照 – Chinese" lang="zh" hreflang="zh" data-title="Java和C++的對照" data-language-autonym="中文" data-language-local-name="Chinese" class="interlanguage-link-target"><span>中文</span></a></li> </ul> <div class="after-portlet after-portlet-lang"><span class="wb-langlinks-edit wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q907151#sitelinks-wikipedia" title="Edit interlanguage links" class="wbc-editpage">Edit links</a></span></div> </div> </div> </div> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Namespaces"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-main" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Comparison_of_Java_and_C%2B%2B" title="View the content page [c]" accesskey="c"><span>Article</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Talk:Comparison_of_Java_and_C%2B%2B" rel="discussion" title="Discuss improvements to the content page [t]" accesskey="t"><span>Talk</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Change language variant" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Views"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Comparison_of_Java_and_C%2B%2B"><span>Read</span></a></li><li id="ca-edit" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Tools</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" > <div class="vector-menu-heading"> Actions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Comparison_of_Java_and_C%2B%2B"><span>Read</span></a></li><li id="ca-more-edit" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=history"><span>View history</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/Comparison_of_Java_and_C%2B%2B" title="List of all English Wikipedia pages containing links to this page [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/Comparison_of_Java_and_C%2B%2B" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_Upload_Wizard" title="Upload files [u]" accesskey="u"><span>Upload file</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q"><span>Special pages</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;oldid=1259576150" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&amp;page=Comparison_of_Java_and_C%2B%2B&amp;id=1259576150&amp;wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlShortener&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FComparison_of_Java_and_C%252B%252B"><span>Get shortened URL</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Special:QrCode&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FComparison_of_Java_and_C%252B%252B"><span>Download QR code</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Print/export </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&amp;page=Comparison_of_Java_and_C%2B%2B&amp;action=show-download-screen" title="Download this page as a PDF file"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li> </ul> </div> </div> <div id="p-wikibase-otherprojects" class="vector-menu mw-portlet mw-portlet-wikibase-otherprojects" > <div class="vector-menu-heading"> In other projects </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-wikibase" class="wb-otherproject-link wb-otherproject-wikibase-dataitem mw-list-item"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q907151" title="Structured data on this page hosted by Wikidata [g]" accesskey="g"><span>Wikidata item</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Appearance</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">hide</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div class="mw-indicators"> </div> <div id="siteSub" class="noprint">From Wikipedia, the free encyclopedia</div> </div> <div id="contentSub"><div id="mw-content-subtitle"></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">Comparison between two programming languages</div> <style data-mw-deduplicate="TemplateStyles:r1251242444">.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}</style><style data-mw-deduplicate="TemplateStyles:r1248332772">.mw-parser-output .multiple-issues-text{width:95%;margin:0.2em 0}.mw-parser-output .multiple-issues-text>.mw-collapsible-content{margin-top:0.3em}.mw-parser-output .compact-ambox .ambox{border:none;border-collapse:collapse;background-color:transparent;margin:0 0 0 1.6em!important;padding:0!important;width:auto;display:block}body.mediawiki .mw-parser-output .compact-ambox .ambox.mbox-small-left{font-size:100%;width:auto;margin:0}.mw-parser-output .compact-ambox .ambox .mbox-text{padding:0!important;margin:0!important}.mw-parser-output .compact-ambox .ambox .mbox-text-span{display:list-item;line-height:1.5em;list-style-type:disc}body.skin-minerva .mw-parser-output .multiple-issues-text>.mw-collapsible-toggle,.mw-parser-output .compact-ambox .ambox .mbox-image,.mw-parser-output .compact-ambox .ambox .mbox-imageright,.mw-parser-output .compact-ambox .ambox .mbox-empty-cell,.mw-parser-output .compact-ambox .hide-when-compact{display:none}</style><table class="box-Multiple_issues plainlinks metadata ambox ambox-content ambox-multiple_issues compact-ambox" role="presentation"><tbody><tr><td class="mbox-image"><div class="mbox-image-div"><span typeof="mw:File"><span><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/b/b4/Ambox_important.svg/40px-Ambox_important.svg.png" decoding="async" width="40" height="40" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/b/b4/Ambox_important.svg/60px-Ambox_important.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/b/b4/Ambox_important.svg/80px-Ambox_important.svg.png 2x" data-file-width="40" data-file-height="40" /></span></span></div></td><td class="mbox-text"><div class="mbox-text-span"><div class="multiple-issues-text mw-collapsible"><b>This article has multiple issues.</b> Please help <b><a href="/wiki/Special:EditPage/Comparison_of_Java_and_C%2B%2B" title="Special:EditPage/Comparison of Java and C++">improve it</a></b> or discuss these issues on the <b><a href="/wiki/Talk:Comparison_of_Java_and_C%2B%2B" title="Talk:Comparison of Java and C++">talk page</a></b>. <small><i>(<a href="/wiki/Help:Maintenance_template_removal" title="Help:Maintenance template removal">Learn how and when to remove these messages</a>)</i></small> <div class="mw-collapsible-content"> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1251242444"><table class="box-Unbalanced plainlinks metadata ambox ambox-content ambox-unbalanced" role="presentation"><tbody><tr><td class="mbox-image"><div class="mbox-image-div"><span class="skin-invert" typeof="mw:File"><span><img src="//upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Unbalanced_scales.svg/45px-Unbalanced_scales.svg.png" decoding="async" width="45" height="40" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Unbalanced_scales.svg/68px-Unbalanced_scales.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Unbalanced_scales.svg/90px-Unbalanced_scales.svg.png 2x" data-file-width="400" data-file-height="354" /></span></span></div></td><td class="mbox-text"><div class="mbox-text-span">This article <b>may be <a href="/wiki/Wikipedia:Neutral_point_of_view#Undue_weight" title="Wikipedia:Neutral point of view">unbalanced</a> toward certain viewpoints</b>.<span class="hide-when-compact"> Please <a class="external text" href="https://en.wikipedia.org/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit">improve the article</a> by adding information on neglected viewpoints, or discuss the issue on the <a href="/wiki/Talk:Comparison_of_Java_and_C%2B%2B" title="Talk:Comparison of Java and C++">talk page</a>.</span> <span class="date-container"><i>(<span class="date">May 2016</span>)</i></span></div></td></tr></tbody></table> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1251242444"><table class="box-Self-published plainlinks metadata ambox ambox-content ambox-self-published" role="presentation"><tbody><tr><td class="mbox-image"><div class="mbox-image-div"><span typeof="mw:File"><span><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/b/b4/Ambox_important.svg/40px-Ambox_important.svg.png" decoding="async" width="40" height="40" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/b/b4/Ambox_important.svg/60px-Ambox_important.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/b/b4/Ambox_important.svg/80px-Ambox_important.svg.png 2x" data-file-width="40" data-file-height="40" /></span></span></div></td><td class="mbox-text"><div class="mbox-text-span">This article <b>may contain excessive or inappropriate references to <a href="/wiki/Wikipedia:Verifiability#Self-published_sources" title="Wikipedia:Verifiability">self-published sources</a></b>.<span class="hide-when-compact"> Please help <a class="external text" href="https://en.wikipedia.org/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit">improve it</a> by removing references to unreliable <a href="/wiki/Wikipedia:Reliable_sources" title="Wikipedia:Reliable sources">sources</a> where they are used inappropriately.</span> <span class="date-container"><i>(<span class="date">September 2010</span>)</i></span><span class="hide-when-compact"><i> (<small><a href="/wiki/Help:Maintenance_template_removal" title="Help:Maintenance template removal">Learn how and when to remove this message</a></small>)</i></span></div></td></tr></tbody></table> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1251242444"><table class="box-Original_research plainlinks metadata ambox ambox-content ambox-Original_research" role="presentation"><tbody><tr><td class="mbox-image"><div class="mbox-image-div"><span typeof="mw:File"><span><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/b/b4/Ambox_important.svg/40px-Ambox_important.svg.png" decoding="async" width="40" height="40" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/b/b4/Ambox_important.svg/60px-Ambox_important.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/b/b4/Ambox_important.svg/80px-Ambox_important.svg.png 2x" data-file-width="40" data-file-height="40" /></span></span></div></td><td class="mbox-text"><div class="mbox-text-span">This article <b>possibly contains <a href="/wiki/Wikipedia:No_original_research" title="Wikipedia:No original research">original research</a></b>.<span class="hide-when-compact"> Please <a class="external text" href="https://en.wikipedia.org/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit">improve it</a> by <a href="/wiki/Wikipedia:Verifiability" title="Wikipedia:Verifiability">verifying</a> the claims made and adding <a href="/wiki/Wikipedia:Citing_sources#Inline_citations" title="Wikipedia:Citing sources">inline citations</a>. Statements consisting only of original research should be removed.</span> <span class="date-container"><i>(<span class="date">August 2012</span>)</i></span><span class="hide-when-compact"><i> (<small><a href="/wiki/Help:Maintenance_template_removal" title="Help:Maintenance template removal">Learn how and when to remove this message</a></small>)</i></span></div></td></tr></tbody></table> </div> </div><span class="hide-when-compact"><i> (<small><a href="/wiki/Help:Maintenance_template_removal" title="Help:Maintenance template removal">Learn how and when to remove this message</a></small>)</i></span></div></td></tr></tbody></table> <p class="mw-empty-elt"> </p> <style data-mw-deduplicate="TemplateStyles:r1129693374">.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}</style><style data-mw-deduplicate="TemplateStyles:r1246091330">.mw-parser-output .sidebar{width:22em;float:right;clear:right;margin:0.5em 0 1em 1em;background:var(--background-color-neutral-subtle,#f8f9fa);border:1px solid var(--border-color-base,#a2a9b1);padding:0.2em;text-align:center;line-height:1.4em;font-size:88%;border-collapse:collapse;display:table}body.skin-minerva .mw-parser-output .sidebar{display:table!important;float:right!important;margin:0.5em 0 1em 1em!important}.mw-parser-output .sidebar-subgroup{width:100%;margin:0;border-spacing:0}.mw-parser-output .sidebar-left{float:left;clear:left;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-none{float:none;clear:both;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-outer-title{padding:0 0.4em 0.2em;font-size:125%;line-height:1.2em;font-weight:bold}.mw-parser-output .sidebar-top-image{padding:0.4em}.mw-parser-output .sidebar-top-caption,.mw-parser-output .sidebar-pretitle-with-top-image,.mw-parser-output .sidebar-caption{padding:0.2em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-pretitle{padding:0.4em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-title,.mw-parser-output .sidebar-title-with-pretitle{padding:0.2em 0.8em;font-size:145%;line-height:1.2em}.mw-parser-output .sidebar-title-with-pretitle{padding:0.1em 0.4em}.mw-parser-output .sidebar-image{padding:0.2em 0.4em 0.4em}.mw-parser-output .sidebar-heading{padding:0.1em 0.4em}.mw-parser-output .sidebar-content{padding:0 0.5em 0.4em}.mw-parser-output .sidebar-content-with-subgroup{padding:0.1em 0.4em 0.2em}.mw-parser-output .sidebar-above,.mw-parser-output .sidebar-below{padding:0.3em 0.8em;font-weight:bold}.mw-parser-output .sidebar-collapse .sidebar-above,.mw-parser-output .sidebar-collapse .sidebar-below{border-top:1px solid #aaa;border-bottom:1px solid #aaa}.mw-parser-output .sidebar-navbar{text-align:right;font-size:115%;padding:0 0.4em 0.4em}.mw-parser-output .sidebar-list-title{padding:0 0.4em;text-align:left;font-weight:bold;line-height:1.6em;font-size:105%}.mw-parser-output .sidebar-list-title-c{padding:0 0.4em;text-align:center;margin:0 3.3em}@media(max-width:640px){body.mediawiki .mw-parser-output .sidebar{width:100%!important;clear:both;float:none!important;margin-left:0!important;margin-right:0!important}}body.skin--responsive .mw-parser-output .sidebar a>img{max-width:none!important}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media print{body.ns-0 .mw-parser-output .sidebar{display:none!important}}</style><table class="sidebar nomobile nowraplinks" style="width:115px"><tbody><tr><th class="sidebar-title"><a href="/wiki/Comparison_of_programming_languages" title="Comparison of programming languages">Comparison of<br />programming languages</a></th></tr><tr><td class="sidebar-content" style="text-align: left"> <ul><li><a href="/wiki/Comparison_of_programming_languages" title="Comparison of programming languages">General comparison</a></li> <li><a href="/wiki/Assignment_(computer_science)#Notation" title="Assignment (computer science)">Assignment</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(syntax)" title="Comparison of programming languages (syntax)">Basic syntax</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(basic_instructions)" title="Comparison of programming languages (basic instructions)">Basic instructions</a></li> <li><a href="/wiki/Comment_(computer_programming)#Comparison" title="Comment (computer programming)">Comments</a></li> <li>Control flow <ul><li><a href="/wiki/Foreach_loop#Language_support" title="Foreach loop">Foreach loops</a></li> <li><a href="/wiki/While_loop#Demonstrating_while_loops" title="While loop">While loops</a></li> <li><a href="/wiki/For_loop#Timeline_of_the_for-loop_syntax_in_various_programming_languages" title="For loop">For loops</a></li> <li><a href="/wiki/Do_while_loop#Demonstrating_do_while_loops" title="Do while loop">Do-while</a></li></ul></li> <li><a href="/wiki/Exception_handling_syntax" title="Exception handling syntax">Exception handling</a></li> <li><a href="/wiki/Enumerated_type#Syntax_in_several_programming_languages" title="Enumerated type">Enumerated types</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(algebraic_data_type)" title="Comparison of programming languages (algebraic data type)">Algebraic data types</a></li> <li><a href="/wiki/Generator_(computer_programming)#Timeline" title="Generator (computer programming)">Generators</a></li> <li><a href="/wiki/Anonymous_function#Examples" title="Anonymous function">Anonymous functions</a></li> <li><a href="/wiki/Ternary_conditional_operator" title="Ternary conditional operator">Conditional expressions</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(functional_instructions)" class="mw-redirect" title="Comparison of programming languages (functional instructions)">Functional instructions</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(array)" title="Comparison of programming languages (array)">Arrays</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(associative_arrays)" class="mw-redirect" title="Comparison of programming languages (associative arrays)">Associative arrays</a></li> <li><a href="/wiki/Scope_(computer_science)#By_language" title="Scope (computer science)">Scope</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(strings)" title="Comparison of programming languages (strings)">String operations</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(string_functions)" title="Comparison of programming languages (string functions)">String functions</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(higher-order_functions)" class="mw-redirect" title="Comparison of programming languages (higher-order functions)">Higher-order functions</a> <ul><li><a href="/wiki/Filter_(higher-order_function)#Language_comparison" title="Filter (higher-order function)">Filter</a></li> <li><a href="/wiki/Fold_(higher-order_function)#In_various_languages" title="Fold (higher-order function)">Fold</a></li> <li><a href="/wiki/Map_(higher-order_function)#Language_comparison" title="Map (higher-order function)">Map</a></li></ul></li> <li><a href="/wiki/Comparison_of_programming_languages_by_type_system" title="Comparison of programming languages by type system">Type systems</a> <ul><li><a href="/wiki/Comparison_of_programming_languages_with_dependent_types" class="mw-redirect" title="Comparison of programming languages with dependent types">Dependent types</a></li></ul></li> <li><a href="/wiki/Comparison_of_programming_languages_(list_comprehension)" title="Comparison of programming languages (list comprehension)">List comprehension</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(object-oriented_programming)" title="Comparison of programming languages (object-oriented programming)">Object-oriented programming</a></li> <li><a href="/wiki/Constructor_(object-oriented_programming)" title="Constructor (object-oriented programming)">Object-oriented constructors</a></li> <li><a href="/wiki/Comparison_of_programming_languages_(operators)" class="mw-redirect" title="Comparison of programming languages (operators)">Operators</a> <ul><li><a href="/wiki/Ternary_conditional_operator#Usage" title="Ternary conditional operator">Ternary conditional operator</a></li> <li><a href="/wiki/Null_coalescing_operator#Examples_by_languages" title="Null coalescing operator">Null coalescing operators</a></li> <li><a href="/wiki/Safe_navigation_operator#Examples" title="Safe navigation operator">Safe navigation operators</a></li> <li><a href="/wiki/Modulo_operation#In_programming_languages" class="mw-redirect" title="Modulo operation">Modulo operators</a></li></ul></li></ul></td> </tr><tr><td class="sidebar-content" style="text-align: left"> <ul><li><a href="/wiki/Evaluation_strategy" title="Evaluation strategy">Evaluation strategy</a></li> <li><a href="https://en.wikibooks.org/wiki/Computer_Programming/Hello_world" class="extiw" title="b:Computer Programming/Hello world">List of "Hello World" programs</a></li></ul></td> </tr><tr><td class="sidebar-content" style="text-align: left"> <hr /> <div class="collapsible-list mw-collapsible mw-collapsed" style="text-align: left;"> <div style="line-height: 1.6em; font-weight: bold;"><div>Comparison of individual<br />languages</div></div> <ul class="mw-collapsible-content" style="margin-top: 0; margin-bottom: 0; line-height: inherit;"><li style="line-height: inherit; margin: 0">Comparison of Java and .NET platforms </li><li style="line-height: inherit; margin: 0"><a href="/wiki/ALGOL_58#ALGOL_58&#39;s_influence_on_ALGOL_60" title="ALGOL 58">ALGOL 58's influence on ALGOL 60</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/ALGOL_60#Comparisons_with_other_languages" title="ALGOL 60">ALGOL 60: Comparisons with other languages</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_ALGOL_68_and_C%2B%2B" title="Comparison of ALGOL 68 and C++">Comparison of ALGOL 68 and C++</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/ALGOL_68#Comparisons_with_other_languages" title="ALGOL 68">ALGOL 68: Comparisons with other languages</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Compatibility_of_C_and_C%2B%2B" title="Compatibility of C and C++">Compatibility of C and C++</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_Pascal_and_Delphi" title="Comparison of Pascal and Delphi">Comparison of Pascal and Borland Delphi</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_Object_Pascal_and_C" class="mw-redirect" title="Comparison of Object Pascal and C">Comparison of Object Pascal and C</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_Pascal_and_C" title="Comparison of Pascal and C">Comparison of Pascal and C</a> </li><li style="line-height: inherit; margin: 0"><a class="mw-selflink selflink">Comparison of Java and C++</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_C_Sharp_and_Java" title="Comparison of C Sharp and Java">Comparison of C# and Java</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_C_Sharp_and_Visual_Basic_.NET" title="Comparison of C Sharp and Visual Basic .NET">Comparison of C# and Visual Basic .NET</a> </li><li style="line-height: inherit; margin: 0"><a href="/wiki/Comparison_of_Visual_Basic_and_Visual_Basic_.NET" title="Comparison of Visual Basic and Visual Basic .NET">Comparison of Visual Basic and Visual Basic .NET</a> </li></ul> </div></td> </tr><tr><td class="sidebar-navbar"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><style data-mw-deduplicate="TemplateStyles:r1239400231">.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}</style><div class="navbar plainlinks hlist navbar-mini"><ul><li class="nv-view"><a href="/wiki/Template:Comparison_of_programming_languages" title="Template:Comparison of programming languages"><abbr title="View this template">v</abbr></a></li><li class="nv-talk"><a href="/wiki/Template_talk:Comparison_of_programming_languages" title="Template talk:Comparison of programming languages"><abbr title="Discuss this template">t</abbr></a></li><li class="nv-edit"><a href="/wiki/Special:EditPage/Template:Comparison_of_programming_languages" title="Special:EditPage/Template:Comparison of programming languages"><abbr title="Edit this template">e</abbr></a></li></ul></div></td></tr></tbody></table> <p><a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a> and <a href="/wiki/C%2B%2B" title="C++">C++</a> are two prominent <a href="/wiki/Object-oriented" class="mw-redirect" title="Object-oriented">object-oriented</a> <a href="/wiki/Programming_language" title="Programming language">programming languages</a>. By many language popularity metrics, the two languages have dominated object-oriented and high-performance software development for much of the 21st century, and are often directly compared and contrasted. Java's syntax <a href="/wiki/Java_(software_platform)#History" title="Java (software platform)">was based on C/C++</a>. </p> <meta property="mw:PageProp/toc" /> <div class="mw-heading mw-heading2"><h2 id="Design_aims">Design aims</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=1" title="Edit section: Design aims"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The differences between the programming languages C++ and Java can be traced to their <a href="/wiki/Virtual_heritage" title="Virtual heritage">heritage</a>, as they have different design goals. </p><p>C++ was designed for systems and applications programming (i.e., infrastructure programming), extending the <a href="/wiki/Procedural_programming" title="Procedural programming">procedural programming</a> language <a href="/wiki/C_(programming_language)" title="C (programming language)">C</a>, which was designed for efficient execution. To C, C++ added support for <a href="/wiki/Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a>, <a href="/wiki/Exception_handling" title="Exception handling">exception handling</a>, lifetime-based resource management (<a href="/wiki/Resource_Acquisition_Is_Initialization" class="mw-redirect" title="Resource Acquisition Is Initialization">Resource Acquisition Is Initialization</a> (RAII)), <a href="/wiki/Generic_programming" title="Generic programming">generic programming</a>, <a href="/wiki/Template_metaprogramming" title="Template metaprogramming">template metaprogramming</a>, and the <a href="/wiki/C%2B%2B_Standard_Library" title="C++ Standard Library">C++ Standard Library</a> which includes generic containers and algorithms (the <a href="/wiki/Standard_Template_Library" title="Standard Template Library">Standard Template Library</a> or STL), and many other general purpose facilities. </p><p>Java is a general-purpose, concurrent, class-based, object-oriented<sup id="cite_ref-FOOTNOTEBloch2018xi–xiiForeword_1-0" class="reference"><a href="#cite_note-FOOTNOTEBloch2018xi–xiiForeword-1"><span class="cite-bracket">&#91;</span>1<span class="cite-bracket">&#93;</span></a></sup> programming language that is designed to minimize implementation dependencies. It relies on a <a href="/wiki/Java_virtual_machine" title="Java virtual machine">Java virtual machine</a> to be <a href="/wiki/Computer_security" title="Computer security">secure</a> and highly <a href="/wiki/Porting" title="Porting">portable</a>. It is bundled with an extensive library designed to provide abstraction of the underlying platform. Java is a statically typed object-oriented language that uses a syntax similar to (but incompatible with) C++. It includes a documentation system called <a href="/wiki/Javadoc" title="Javadoc">Javadoc</a>. </p><p>The different goals in the development of C++ and Java resulted in different principles and design trade-offs between the languages. The differences are as follows: </p> <table class="wikitable"> <tbody><tr> <th style="width:50%;">C++ </th> <th style="width:50%;">Java </th></tr> <tr> <td>Extends <a href="/wiki/C_(programming_language)" title="C (programming language)">C</a> with <a href="/wiki/Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a> and <a href="/wiki/Generic_programming" title="Generic programming">generic programming</a>. C code can most properly be used. </td> <td>Strongly influenced by C++/C syntax. </td></tr> <tr> <td>Compatible with <a href="/wiki/C_(programming_language)" title="C (programming language)">C</a> source code, except for a few <a href="/wiki/Corner_case" title="Corner case">corner cases</a>. </td> <td>Provides the <a href="/wiki/Java_Native_Interface" title="Java Native Interface">Java Native Interface</a> and recently <a href="/wiki/Java_Native_Access" title="Java Native Access">Java Native Access</a> as a way to directly call C/C++ code. However, native languages are not safe and applications using native methods are susceptible to memory corruption.<sup id="cite_ref-FOOTNOTEBloch2018285Chapter_§11_Item_66:_Use_native_methods_judiciously_2-0" class="reference"><a href="#cite_note-FOOTNOTEBloch2018285Chapter_§11_Item_66:_Use_native_methods_judiciously-2"><span class="cite-bracket">&#91;</span>2<span class="cite-bracket">&#93;</span></a></sup> If the code is not carefully written, native methods can lower the performance of the system because the garbage collector is incapable of monitoring or maintaining native memory usage, and there is a cost context-switching between native and non-native code.<sup id="cite_ref-FOOTNOTEBloch2018285Chapter_§11_Item_66:_Use_native_methods_judiciously_2-1" class="reference"><a href="#cite_note-FOOTNOTEBloch2018285Chapter_§11_Item_66:_Use_native_methods_judiciously-2"><span class="cite-bracket">&#91;</span>2<span class="cite-bracket">&#93;</span></a></sup> </td></tr> <tr> <td><a href="/wiki/Write_once,_compile_anywhere" title="Write once, compile anywhere">Write once, compile anywhere</a> (WOCA). </td> <td><a href="/wiki/Write_once,_run_anywhere" title="Write once, run anywhere">Write once, run anywhere</a>/everywhere (WORA/WORE). </td></tr> <tr> <td>Allows <a href="/wiki/Procedural_programming" title="Procedural programming">procedural programming</a>, <a href="/wiki/Functional_programming" title="Functional programming">functional programming</a>, <a href="/wiki/Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a>, <a href="/wiki/Generic_programming" title="Generic programming">generic programming</a>, and <a href="/wiki/Template_metaprogramming" title="Template metaprogramming">template metaprogramming</a>. Favors a mix of paradigms. </td> <td>Allows <a href="/wiki/Procedural_programming" title="Procedural programming">procedural programming</a>, <a href="/wiki/Functional_programming" title="Functional programming">functional programming</a> (since Java 8) and <a href="/wiki/Generic_programming" title="Generic programming">generic programming</a> (since Java 5), but strongly encourages the <a href="/wiki/Object-oriented_programming" title="Object-oriented programming">object-oriented</a> <a href="/wiki/Programming_paradigm" title="Programming paradigm">programming paradigm</a>. Includes support for creating <a href="/wiki/Scripting_language" title="Scripting language">scripting languages</a>. </td></tr> <tr> <td>Runs as native executable machine code for the target <a href="/wiki/Instruction_set" class="mw-redirect" title="Instruction set">instruction set</a>(s). </td> <td>Runs on a <a href="/wiki/Java_virtual_machine" title="Java virtual machine">virtual machine</a>. </td></tr> <tr> <td>Provides object types and type names. Allows <a href="/wiki/Reflective_programming" title="Reflective programming">reflection</a> via <a href="/wiki/Run-time_type_information" title="Run-time type information">run-time type information</a> (RTTI). </td> <td>Is reflective, allowing <a href="/wiki/Metaprogramming" title="Metaprogramming">metaprogramming</a> and dynamic code generation at runtime. </td></tr> <tr> <td>Has multiple binary compatibility standards (commonly Microsoft (for MSVC compiler) and Itanium/GNU (for almost all other compilers)). </td> <td>Has one binary compatibility standard, <a href="/wiki/Cross-platform" class="mw-redirect" title="Cross-platform">cross-platform</a> for OS and compiler. </td></tr> <tr> <td>Optional automated <a href="/wiki/Bounds_checking" title="Bounds checking">bounds checking</a> (e.g., the <code>at()</code> method in <code>vector</code> and <code>string</code> containers). </td> <td>All operations are required to be bound-checked by all compliant distributions of Java. <a href="/wiki/HotSpot_(virtual_machine)" title="HotSpot (virtual machine)">HotSpot</a> can remove bounds checking. </td></tr> <tr> <td>Native <a href="/wiki/Unsigned_(arithmetic)" class="mw-redirect" title="Unsigned (arithmetic)">unsigned arithmetic</a> support. </td> <td>Native unsigned arithmetic unsupported. Java 8 changes some of this, but aspects are unclear.<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">&#91;</span>3<span class="cite-bracket">&#93;</span></a></sup> </td></tr> <tr> <td>Standardized minimum limits for all numerical types, but the actual sizes are implementation-defined. Standardized types are available via the standard library <code>&lt;cstdint&gt;</code>. </td> <td>Standardized limits and sizes of all primitive types on all platforms. </td></tr> <tr> <td>Pointers, references, and pass-by-value are supported for all types (primitive or user-defined). </td> <td>All types (primitive types and <a href="/wiki/Reference_type" class="mw-redirect" title="Reference type">reference types</a>) are always passed by value.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">&#91;</span>4<span class="cite-bracket">&#93;</span></a></sup> </td></tr> <tr> <td><a href="/wiki/Memory_management" title="Memory management">Memory management</a> can be done <a href="/wiki/Manual_memory_management" title="Manual memory management">manually</a> via <code>new / delete</code>, automatically by scope, or by smart pointers. Supports deterministic destruction of objects. <a href="/wiki/Garbage_collection_(computer_science)" title="Garbage collection (computer science)">Garbage collection</a> ABI standardized in C++11, though compilers are not required to implement garbage collection. </td> <td>Automatic <a href="/wiki/Garbage_collection_(computer_science)" title="Garbage collection (computer science)">garbage collection</a>.<sup id="cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-0" class="reference"><a href="#cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> Supports a non-deterministic finalize() method, use of which is not recommended.<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">&#91;</span>6<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-0" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> </td></tr> <tr> <td><a href="/wiki/Resource_management_(computing)" title="Resource management (computing)">Resource management</a> can be done manually or by automatic lifetime-based resource management (<a href="/wiki/Resource_Acquisition_Is_Initialization" class="mw-redirect" title="Resource Acquisition Is Initialization">RAII</a>). </td> <td>Resource management must generally be done manually, or automatically via finalizers, though this is generally discouraged. Has try-with-resources for automatic scope-based resource management (version 7 onwards). <p>It can also be done using the internal API <code>sun.misc.Unsafe</code> but that usage is highly discouraged and will be replaced by a public API in an upcoming Java version. </p> </td></tr> <tr> <td>Supports classes, structs (<a href="/wiki/Passive_data_structure" title="Passive data structure">passive data structure</a> (PDS) types), and unions, and can allocate them on the <a href="/wiki/Dynamic_memory_allocation" class="mw-redirect" title="Dynamic memory allocation">heap</a> or the <a href="/wiki/Stack-based_memory_allocation" title="Stack-based memory allocation">stack</a>. </td> <td>Classes are allocated on the <a href="/wiki/Dynamic_memory_allocation" class="mw-redirect" title="Dynamic memory allocation">heap</a>. <a href="/wiki/Java_version_history#Java_SE_6" title="Java version history">Java SE 6</a> optimizes with <a href="/wiki/Escape_analysis" title="Escape analysis">escape analysis</a> to allocate some objects on the <a href="/wiki/Stack-based_memory_allocation" title="Stack-based memory allocation">stack</a>. </td></tr> <tr> <td>Allows explicitly overriding types, and some implicit narrowing conversions (for compatibility with C). </td> <td>Rigid <a href="/wiki/Type_safety" title="Type safety">type safety</a> except for widening conversions. </td></tr> <tr> <td>The <a href="/wiki/C%2B%2B_Standard_Library" title="C++ Standard Library">C++ Standard Library</a> was designed to have a limited scope and functions, but includes language support, diagnostics, general utilities, strings, locales, containers, algorithms, <a href="/wiki/Iterator#C++" title="Iterator">iterators</a>, numerics, input/output, random number generators, regular expression parsing, threading facilities, type traits (for static type introspection) and Standard C Library. The <a href="/wiki/Boost_(C%2B%2B_libraries)" title="Boost (C++ libraries)">Boost library</a> offers more functions including network I/O. <p>A rich amount of third-party libraries exist for GUI and other functions like: <a href="/wiki/Adaptive_Communication_Environment" title="Adaptive Communication Environment">Adaptive Communication Environment</a> (ACE), <a href="/wiki/Crypto%2B%2B" title="Crypto++">Crypto++</a>, various <a href="/wiki/XMPP" title="XMPP">XMPP</a> <a href="/wiki/Instant_Messaging" class="mw-redirect" title="Instant Messaging">Instant Messaging</a> (IM) libraries,<sup id="cite_ref-XMPP_Software_»_Libraries_8-0" class="reference"><a href="#cite_note-XMPP_Software_»_Libraries-8"><span class="cite-bracket">&#91;</span>8<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/OpenLDAP" title="OpenLDAP">OpenLDAP</a>, <a href="/wiki/Qt_(software)" title="Qt (software)">Qt</a>, <a href="/wiki/Gtkmm" title="Gtkmm">gtkmm</a>. </p> </td> <td>The standard library has grown with each release. By version 1.6, the library included support for locales, logging, containers and iterators, algorithms, GUI programming (but not using the system GUI), graphics, multi-threading, networking, platform security, introspection, dynamic class loading, blocking and non-blocking I/O. It provided interfaces or support classes for <a href="/wiki/XML" title="XML">XML</a>, <a href="/wiki/XSLT" title="XSLT">XSLT</a>, <a href="/wiki/MIDI" title="MIDI">MIDI</a>, database connectivity, naming services (e.g. <a href="/wiki/LDAP" class="mw-redirect" title="LDAP">LDAP</a>), cryptography, security services (e.g. <a href="/wiki/Kerberos_(protocol)" title="Kerberos (protocol)">Kerberos</a>), print services, and web services. SWT offered an abstraction for platform-specific GUIs, but was superseded by <a href="/wiki/JavaFX" title="JavaFX">JavaFX</a> in the latest releases; allowing for graphics acceleration and CSS-themable UIs. Although it doesn't support any kind of "native platform look" support. </td></tr> <tr> <td><a href="/wiki/Operator_overloading" title="Operator overloading">Operator overloading</a> for most operators. Preserving meaning (semantics) is highly recommended. </td> <td>Operators are not overridable. The language overrides + and += for the String class. </td></tr> <tr> <td>Single and <a href="/wiki/Multiple_inheritance" title="Multiple inheritance">multiple inheritance</a> of classes, including virtual inheritance. </td> <td>Only supports single inheritance of classes.<sup id="cite_ref-FOOTNOTEBloch2018xi–xiiForeword_1-1" class="reference"><a href="#cite_note-FOOTNOTEBloch2018xi–xiiForeword-1"><span class="cite-bracket">&#91;</span>1<span class="cite-bracket">&#93;</span></a></sup> </td></tr> <tr> <td>Compile-time templates. Allows for <a href="/wiki/Turing_complete" class="mw-redirect" title="Turing complete">Turing complete</a> meta-programming. </td> <td><a href="/wiki/Generics_in_Java" title="Generics in Java">Generics</a> are used to achieve basic type-parametrization, but they do not translate from source code to byte code due to the use of <a href="/wiki/Type_erasure" title="Type erasure">type erasure</a> by the compiler. </td></tr> <tr> <td>Function pointers, function objects, lambdas (in <a href="/wiki/C%2B%2B11" title="C++11">C++11</a>), and interfaces (using abstract classes). </td> <td>Functions references, function objects and lambdas were added in <a href="/wiki/Java_8" class="mw-redirect" title="Java 8">Java 8</a>. Classes (and interfaces, which are classes) can be passed as references as well through <code>SomeClass.class</code> and <code>someObject.getClass()</code>. </td></tr> <tr> <td>No standard inline documentation mechanism. Third-party software (e.g. <a href="/wiki/Doxygen" title="Doxygen">Doxygen</a>) exists. </td> <td>Extensive <a href="/wiki/Javadoc" title="Javadoc">Javadoc</a> documentation standard on all system classes and methods. </td></tr> <tr> <td><code>const</code> keyword for defining immutable variables and member functions that do not change the object. Const-ness is propagated as a means to enforce, at compile-time, correctness of the code with respect to mutability of objects (see <a href="/wiki/Const-correctness" class="mw-redirect" title="Const-correctness">const-correctness</a>). </td> <td><code>final</code> provides a version of <code>const</code>,<sup id="cite_ref-FOOTNOTEGoetzPeierlsBlochBowbeer200648§3.4.1_Final_fields_9-0" class="reference"><a href="#cite_note-FOOTNOTEGoetzPeierlsBlochBowbeer200648§3.4.1_Final_fields-9"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup> equivalent to <code>type* const</code> pointers for objects and <code>const</code> for primitive types. Immutability of object members achieved via read-only interfaces and object encapsulation. </td></tr> <tr> <td>Supports the <code><a href="/wiki/Goto" title="Goto">goto</a></code> statement. </td> <td>Supports labels with loops and statement blocks. <code>goto</code> is a reserved keyword but is marked as "unused" in the <a rel="nofollow" class="external text" href="https://docs.oracle.com/javase/specs/">Java specification.</a> </td></tr> <tr> <td>Source code can be written to be <a href="/wiki/Cross-platform" class="mw-redirect" title="Cross-platform">cross-platform</a> (can be compiled for <a href="/wiki/BSD" class="mw-redirect" title="BSD">BSD</a>, <a href="/wiki/Linux" title="Linux">GNU/Linux</a>, <a href="/wiki/MacOS" title="MacOS">macOS</a>, <a href="/wiki/Solaris_(operating_system)" class="mw-redirect" title="Solaris (operating system)">Solaris</a>, <a href="/wiki/Microsoft_Windows" title="Microsoft Windows">Windows</a>, etc., without modification) and written to use platform-specific features. Typically compiled into native machine code, must be recompiled for each target platform. </td> <td>Compiled into <a href="/wiki/Java_bytecode" title="Java bytecode">Java bytecode</a> for the <a href="/wiki/JVM" class="mw-redirect" title="JVM">JVM</a>. Byte code is dependent on the Java platform, but is typically independent of <a href="/wiki/Operating_system" title="Operating system">operating system</a> specific features. </td></tr></tbody></table> <div class="mw-heading mw-heading2"><h2 id="Language_features">Language features</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=2" title="Edit section: Language features"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-heading mw-heading3"><h3 id="Syntax">Syntax</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=3" title="Edit section: Syntax"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1236090951">.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}</style><div role="note" class="hatnote navigation-not-searchable">See also: <a href="/wiki/Java_syntax" title="Java syntax">Java syntax</a> and <a href="/wiki/C%2B%2B_syntax" class="mw-redirect" title="C++ syntax">C++ syntax</a></div> <ul><li><a href="/wiki/Java_syntax" title="Java syntax">Java syntax</a> has a <a href="/wiki/Context-free_grammar" title="Context-free grammar">context-free grammar</a> that can be parsed by a simple <a href="/wiki/LALR_parser" title="LALR parser">LALR parser</a>. Parsing C++ is more complicated. For example, <code>Foo&lt;1&gt;(3);</code> is a sequence of comparisons if Foo is a variable, but creates an object if Foo is the name of a class template.</li> <li>C++ allows namespace-level constants, variables, and functions. In Java, such entities must belong to some given type, and therefore must be defined inside a type definition, either a class or an <a href="/wiki/Interface_(Java)" title="Interface (Java)">interface</a>.</li> <li>In C++, objects are values, while in Java they are not. C++ uses <i>value semantics</i> by default, while Java always uses <i>reference semantics</i>. To opt for reference semantics in C++, either a pointer or a reference can be used.</li></ul> <table class="wikitable"> <tbody><tr> <th style="width:600px;">C++ </th> <th style="width:600px;">Java </th></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// Declares class Foo</span> <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="c1">// Private Member variable. It will</span> <span class="w"> </span><span class="c1">// be initialized to 0, if the</span> <span class="w"> </span><span class="c1">// constructor would not set it.</span> <span class="w"> </span><span class="c1">// (from C++11)</span> <span class="w"> </span><span class="k">public</span><span class="o">:</span> <span class="w"> </span><span class="n">Foo</span><span class="p">()</span><span class="o">:</span><span class="w"> </span><span class="n">x</span><span class="p">{</span><span class="mi">0</span><span class="p">}</span><span class="w"> </span><span class="c1">// Constructor for Foo; initializes</span> <span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="c1">// x to 0. If the initializer were</span> <span class="w"> </span><span class="c1">// omitted, the variable would</span> <span class="w"> </span><span class="c1">// be initialized to the value that</span> <span class="w"> </span><span class="c1">// has been given at declaration of x.</span> <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">bar</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// Member function bar()</span> <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">x</span><span class="p">;</span> <span class="w"> </span><span class="p">}</span> <span class="p">};</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">class</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// Defines class Foo</span> <span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"> </span><span class="c1">// Member variable, normally declared</span> <span class="w"> </span><span class="c1">// as private to enforce encapsulation</span> <span class="w"> </span><span class="c1">// initialized to 0 by default</span> <span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">Foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// Constructor for Foo</span> <span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="c1">// no-arg constructor supplied by default</span> <span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">bar</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// Member method bar()</span> <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">x</span><span class="p">;</span> <span class="w"> </span><span class="p">}</span> <span class="p">}</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Foo</span><span class="w"> </span><span class="n">a</span><span class="p">;</span> <span class="c1">// declares a to be a Foo object value,</span> <span class="c1">// initialized using the default constructor.</span> <span class="c1">// Another constructor can be used as</span> <span class="n">Foo</span><span class="w"> </span><span class="nf">a</span><span class="p">(</span><span class="n">args</span><span class="p">);</span> <span class="c1">// or (C++11):</span> <span class="n">Foo</span><span class="w"> </span><span class="n">a</span><span class="p">{</span><span class="n">args</span><span class="p">};</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Foo</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">();</span> <span class="c1">// declares a to be a reference to a new Foo object</span> <span class="c1">// initialized using the default constructor</span> <span class="c1">// Another constructor can be used as</span> <span class="n">Foo</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">(</span><span class="n">args</span><span class="p">);</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Foo</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="p">;</span> <span class="c1">// copies the contents of a to a new Foo object b;</span> <span class="c1">// alternative syntax is &quot;Foo b(a)&quot;</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// Foo b = a;</span> <span class="c1">// would declare b to be reference to the object pointed to by a</span> <span class="n">Foo</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="p">.</span><span class="na">clone</span><span class="p">();</span> <span class="c1">// copies the contents of the object pointed to by a </span> <span class="c1">// to a new Foo object;</span> <span class="c1">// sets the reference b to point to this new object;</span> <span class="c1">// the Foo class must implement the Cloneable interface</span> <span class="c1">// for this code to compile</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">a</span><span class="p">.</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span><span class="w"> </span><span class="c1">// modifies the object a</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">a</span><span class="p">.</span><span class="na">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span><span class="w"> </span><span class="c1">// modifies the object referenced by a</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">x</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="c1">// outputs 0, because b is</span> <span class="c1">// some object other than a</span> <span class="c1">// or, since C++23:</span> <span class="n">std</span><span class="o">::</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">x</span><span class="p">);</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="na">x</span><span class="p">);</span> <span class="c1">// outputs 0, because b points to</span> <span class="c1">// some object other than a</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Foo</span><span class="o">*</span><span class="w"> </span><span class="n">c</span><span class="p">;</span> <span class="c1">// declares c to be a pointer to a</span> <span class="c1">// Foo object (initially</span> <span class="c1">// undefined; could point anywhere)</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Foo</span><span class="w"> </span><span class="n">c</span><span class="p">;</span> <span class="c1">// declares c to be a reference to a Foo</span> <span class="c1">// object (initially null if c is a class member;</span> <span class="c1">// it is necessary to initialize c before use</span> <span class="c1">// if it is a local variable)</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">;</span> <span class="c1">// c is set to the value of the address of the Foo object created by operator new</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">();</span> <span class="c1">// binds c to reference a new Foo object</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Foo</span><span class="o">&amp;</span><span class="w"> </span><span class="n">d</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">c</span><span class="p">;</span> <span class="c1">// binds d to reference the same object to which c points</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Foo</span><span class="w"> </span><span class="n">d</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">c</span><span class="p">;</span> <span class="c1">// binds d to reference the same object as c</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">c</span><span class="o">-&gt;</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span> <span class="c1">// modifies the object pointed to by c</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">c</span><span class="p">.</span><span class="na">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span> <span class="c1">// modifies the object referenced by c</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">d</span><span class="p">.</span><span class="n">bar</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span><span class="w"> </span><span class="c1">// invokes Foo::bar() for a</span> <span class="n">c</span><span class="o">-&gt;</span><span class="n">bar</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span><span class="w"> </span><span class="c1">// invokes Foo::bar() for *c</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">d</span><span class="p">.</span><span class="na">bar</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span><span class="w"> </span><span class="c1">// invokes Foo.bar() for a</span> <span class="n">c</span><span class="p">.</span><span class="na">bar</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span><span class="w"> </span><span class="c1">// invokes Foo.bar() for c</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">d</span><span class="p">.</span><span class="n">x</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="c1">// outputs 5, because d references the</span> <span class="c1">// same object to which c points</span> <span class="c1">// or, since C++23:</span> <span class="n">std</span><span class="o">::</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">d</span><span class="p">.</span><span class="n">x</span><span class="p">);</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">d</span><span class="p">.</span><span class="na">x</span><span class="p">);</span> <span class="c1">// outputs 5, because d references the</span> <span class="c1">// same object as c</span> </pre></div> </td></tr></tbody></table> <ul><li>In C++, it is possible to declare a pointer or reference to a <a href="/wiki/Const" class="mw-redirect" title="Const">const</a> object in order to prevent client code from modifying it. Functions and methods can also guarantee that they will not modify the object pointed to by a pointer by using the "const" keyword. This enforces <a href="/wiki/Const-correctness" class="mw-redirect" title="Const-correctness">const-correctness</a>.</li> <li>In Java, the <code>final</code> keyword is similar to the <code>const</code> keyword in C++, but its usage is more limited.<sup id="cite_ref-FOOTNOTEGoetzPeierlsBlochBowbeer200648§3.4.1_Final_fields_9-1" class="reference"><a href="#cite_note-FOOTNOTEGoetzPeierlsBlochBowbeer200648§3.4.1_Final_fields-9"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup> For the most part, const-correctness must rely on the semantics of the class' interface, i.e., it is not strongly enforced, except for public data members that are labeled <code>final</code>.</li></ul> <table class="wikitable"> <tbody><tr> <th style="width:400px;">C++ </th> <th style="width:400px;">Java </th></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">const</span><span class="w"> </span><span class="n">Foo</span><span class="o">*</span><span class="w"> </span><span class="n">a</span><span class="p">;</span><span class="w"> </span><span class="c1">// it is not possible to modify the object</span> <span class="w"> </span><span class="c1">// pointed to by a through a</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">final</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="n">a</span><span class="p">;</span><span class="w"> </span><span class="c1">// a declaration of a &quot;final&quot; reference:</span> <span class="w"> </span><span class="c1">// it is possible to modify the object, </span> <span class="w"> </span><span class="c1">// but the reference will constantly point </span> <span class="w"> </span><span class="c1">// to the first object assigned to it</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">();</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">();</span><span class="w"> </span><span class="c1">// Only in constructor</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">a</span><span class="o">-&gt;</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span> <span class="c1">// ILLEGAL</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">a</span><span class="p">.</span><span class="na">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span> <span class="c1">// LEGAL, the object&#39;s members can still be modified </span> <span class="c1">// unless explicitly declared final in the declaring class</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Foo</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">();</span> <span class="c1">// a declaration of a &quot;const&quot; pointer</span> <span class="c1">// it is possible to modify the object,</span> <span class="c1">// but the pointer will constantly point</span> <span class="c1">// to the object assigned to it here</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">final</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">();</span> <span class="c1">// a declaration of a &quot;final&quot; reference</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">();</span> <span class="c1">// ILLEGAL, it is not allowed to re-bind it</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Foo</span><span class="p">();</span> <span class="c1">// ILLEGAL, it is not allowed to re-bind it</span> </pre></div> </td></tr> <tr> <td><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">b</span><span class="o">-&gt;</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span> <span class="c1">// LEGAL, the object can still be modified</span> </pre></div> </td> <td><div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">b</span><span class="p">.</span><span class="na">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span> <span class="c1">// LEGAL, the object can still be modified</span> </pre></div> </td></tr></tbody></table> <ul><li>C++ supports <code><a href="/wiki/Goto" title="Goto">goto</a></code> statements, which may lead to <a href="/wiki/Spaghetti_code" title="Spaghetti code">spaghetti code</a> 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 <a href="/wiki/Control_flow" title="Control flow">control flow</a> structures, designed to enforce <a href="/wiki/Structured_programming#Low-level_structure_programming" title="Structured programming">structured control flow</a>, and relies on <a href="/wiki/Control_flow#Early_exit_from_loops" title="Control flow">break and continue</a> 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.<sup id="cite_ref-Martin_10-0" class="reference"><a href="#cite_note-Martin-10"><span class="cite-bracket">&#91;</span>10<span class="cite-bracket">&#93;</span></a></sup></li> <li>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 <a href="/wiki/Operating_system" title="Operating system">operating system</a> components. Similarly, many C++ compilers support an <a href="/wiki/Inline_assembler" title="Inline assembler">inline assembler</a>. 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 <a href="/wiki/Java_Native_Interface" title="Java Native Interface">Java Native Interface</a>, with a significant overhead for each call.</li></ul> <div class="mw-heading mw-heading3"><h3 id="Semantics">Semantics</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=4" title="Edit section: Semantics"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li>C++ allows default values for arguments of a function/method. Java does not. However, <a href="/wiki/Method_overloading" class="mw-redirect" title="Method overloading">method overloading</a> can be used to obtain similar results in Java but generate redundant stub code.</li> <li>The minimum of code needed to compile for C++ is a function, for Java is a class.</li> <li>C++ allows a range of implicit conversions between native types (including some narrowing conversions), and also allows defining implicit conversions involving user-defined types. In Java, only widening conversions between native types are implicit; other conversions require explicit cast syntax. <ul><li>A result of this is that although loop conditions (<code>if</code>, <code>while</code> and the exit condition in <code>for</code>) in Java and C++ both expect a boolean expression, code such as <code>if(a = 5)</code> will cause a compile error in Java because there is no implicit narrowing conversion from int to boolean, but will compile in C++. This is handy if the code was a typo and <code>if(a == 5)</code> was intended. However, current C++ compilers will usually generate a warning when such an assignment is performed within a conditional expression. Similarly, standalone comparison statements, e.g. <code>a==5;</code>, without a side effect usually lead to a warning.</li></ul></li> <li>For passing parameters to functions, C++ supports both <a href="/wiki/Pass-by-reference" class="mw-redirect" title="Pass-by-reference">pass-by-reference</a> and <a href="/wiki/Pass-by-value" class="mw-redirect" title="Pass-by-value">pass-by-value</a>. In Java, primitive parameters are always passed by value. Class types, interface types, and array types are collectively called reference types in Java and are also always passed by value.<sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">&#91;</span>11<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">&#91;</span>12<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">&#91;</span>13<span class="cite-bracket">&#93;</span></a></sup></li> <li>Java built-in types are of a specified size and range defined by the language specification. In C++, a minimal range of values is defined for built-in types, but the exact representation (number of bits) can be mapped to whatever native types are preferred on a given platform. <ul><li>For instance, Java characters are 16-bit <a href="/wiki/Unicode" title="Unicode">Unicode</a> characters, and strings are composed of a sequence of such characters. C++ offers both narrow and wide characters, but the actual size of each is platform dependent, as is the character set used. Strings can be formed from either type.</li> <li>This also implies that C++ compilers can automatically select the most efficient representation for the target platform (i.e., 64-bit integers for a 64-bit platform), while the representation is fixed in Java, meaning the values can either be stored in the less-efficient size, or must pad the remaining bits and add code to emulate the reduced-width behavior.</li></ul></li> <li>The rounding and precision of floating point values and operations in C++ is implementation-defined (although only very exotic or old platforms depart from the <a href="/wiki/IEEE_754" title="IEEE 754">IEEE 754</a> standard). Java provides an optional <i>strict floating-point model</i> (<a href="/wiki/Strictfp" title="Strictfp">strictfp</a>) that guarantees more consistent results across platforms, though at the cost of possibly slower run-time performance. However, Java does not comply strictly with the IEEE 754 standard. Most C++ compilers will, by default, comply partly with IEEE 754 (usually excluding strict rounding rules and raise exceptions on NaN results), but provide compliance options of varied strictness, to allow for some optimizing.<sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-15" class="reference"><a href="#cite_note-15"><span class="cite-bracket">&#91;</span>15<span class="cite-bracket">&#93;</span></a></sup> If we label those options from least compliant to most compliant as <i>fast</i>, <i>consistent</i> (Java's <i>strictfp</i>), <i>near-IEEE</i>, and <i>strict-IEEE</i>, we can say that most C++ implementations default to <i>near-IEEE</i>, with options to switch to <i>fast</i> or <i>strict-IEEE</i>, while Java defaults to <i>fast</i> with an option to switch to <i>consistent</i>.</li> <li>In C++, <a href="/wiki/Pointer_(computer_programming)" title="Pointer (computer programming)">pointers</a> can be manipulated directly as memory address values. Java references are pointers to objects.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">&#91;</span>16<span class="cite-bracket">&#93;</span></a></sup> Java references do not allow direct access to memory addresses or allow memory addresses to be manipulated with pointer arithmetic. In C++ one can construct pointers to pointers, pointers to ints and doubles, and pointers to arbitrary memory locations. Java references only access objects, never primitives, other references, or arbitrary memory locations. In Java, memory can be read and written by arbitrary values using the <code>sun.misc.Unsafe</code> API, however it is deprecated and not recommended.</li> <li>In C++, pointers can point to functions or member functions (<a href="/wiki/Function_pointer" title="Function pointer">function pointers</a>). The equivalent mechanism in Java uses object or interface references.</li> <li>Via stack-allocated objects, C++ supports <a href="/wiki/Resource_Acquisition_Is_Initialization" class="mw-redirect" title="Resource Acquisition Is Initialization">scoped resource management</a>, a technique used to automatically manage memory and other system resources that supports deterministic object destruction. While scoped resource management in C++ cannot be guaranteed (even objects with proper destructors can be allocated using <code>new</code> and left undeleted) it provides an effective means of resource management. Shared resources can be managed using <code>shared_ptr</code>, along with <code>weak_ptr</code> to break cyclic references. Java supports automatic memory management using <a href="/wiki/Garbage_collection_(computer_science)" title="Garbage collection (computer science)">garbage collection</a><sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-1" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> which can free unreachable objects even in the presence of cyclic references, but other system resources (files,<sup id="cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-1" class="reference"><a href="#cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> streams, windows, communication ports, threads, etc.) must be explicitly released because garbage collection is not guaranteed to occur immediately after the last object reference is abandoned.</li> <li>C++ features user-defined <a href="/wiki/Operator_overloading" title="Operator overloading">operator overloading</a>. Operator overloading allows for user-defined types to support operators (arithmetic, comparisons, etc.) like primitive types via user-defined implementations for these operators. It is generally recommended to preserve the semantics of the operators. Java supports no form of operator overloading (although its library uses the addition operator for string concatenation).</li> <li>Java features standard <a href="/wiki/Application_programming_interface" class="mw-redirect" title="Application programming interface">application programming interface</a> (API) support for <a href="/wiki/Reflective_programming" title="Reflective programming">reflective programming</a> (reflection) and <a href="/wiki/Dynamic_loading" title="Dynamic loading">dynamic loading</a> of arbitrary new code.</li> <li>C++ supports static and dynamic linking of binaries.</li> <li>Java has <a href="/wiki/Generic_programming#Generics_in_Java" title="Generic programming">generics</a>, which main purpose is to provide type-safe containers. C++ has compile-time <a href="/wiki/Generic_programming#Templates_in_C++" title="Generic programming">templates</a>, which provide more extensive support for generic programming and metaprogramming. Java has <a href="/wiki/Java_annotation" title="Java annotation">annotations</a>, which allow adding arbitrary custom metadata to classes and metaprogramming via an <a href="/wiki/Annotation_processing_tool#Java" class="mw-redirect" title="Annotation processing tool">annotation processing tool</a>.</li> <li>Both Java and C++ distinguish between native types (also termed <i>fundamental</i> or <i>built-in</i> types) and user-defined types (also termed <i>compound</i> types). In Java, native types have value semantics only, and compound types have reference semantics only. In C++ all types have value semantics, but a reference can be created to any type, which will allow the object to be manipulated via reference semantics.</li> <li>C++ supports <a href="/wiki/Multiple_inheritance" title="Multiple inheritance">multiple inheritance</a> of arbitrary classes. In Java a class can derive from only one class,<sup id="cite_ref-FOOTNOTEBloch2018xi–xiiForeword_1-2" class="reference"><a href="#cite_note-FOOTNOTEBloch2018xi–xiiForeword-1"><span class="cite-bracket">&#91;</span>1<span class="cite-bracket">&#93;</span></a></sup> but a class can implement multiple <a href="/wiki/Interface_(Java)" title="Interface (Java)">interfaces</a><sup id="cite_ref-FOOTNOTEBloch201887–92Chapter_§8_Item_8:_Favor_composition_over_inheritance_17-0" class="reference"><a href="#cite_note-FOOTNOTEBloch201887–92Chapter_§8_Item_8:_Favor_composition_over_inheritance-17"><span class="cite-bracket">&#91;</span>17<span class="cite-bracket">&#93;</span></a></sup> (in other words, it supports multiple inheritance of types, but only single inheritance of implementation).</li> <li>Java explicitly distinguishes between interfaces and classes. In C++, multiple inheritance and pure virtual functions make it possible to define classes that function almost like Java interfaces do, with a few small differences.</li> <li>Java has both language and standard library support for <a href="/wiki/Thread_(computer_science)" class="mw-redirect" title="Thread (computer science)">multi-threading</a>. The <code>synchronized</code> <a href="/wiki/Java_keywords" class="mw-redirect" title="Java keywords">keyword in Java</a> provides <a href="/wiki/Mutual_exclusion" title="Mutual exclusion">mutex locks</a> to support multi-threaded applications.<sup id="cite_ref-FOOTNOTEGoetzPeierlsBlochBowbeer200625–26§2.3.1_Intrinsic_locks_18-0" class="reference"><a href="#cite_note-FOOTNOTEGoetzPeierlsBlochBowbeer200625–26§2.3.1_Intrinsic_locks-18"><span class="cite-bracket">&#91;</span>18<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEBloch2018126–129Chapter_§11_Item_78:_Synchronize_access_to_shared_mutable_data_19-0" class="reference"><a href="#cite_note-FOOTNOTEBloch2018126–129Chapter_§11_Item_78:_Synchronize_access_to_shared_mutable_data-19"><span class="cite-bracket">&#91;</span>19<span class="cite-bracket">&#93;</span></a></sup> Java also provides libraries for more advanced multi-threading synchronizing. <a href="/wiki/C%2B%2B11" title="C++11">C++11</a> has a defined memory model for multi-threading in C++, and library support for creating threads and for many synchronizing primitives. There are also many third-party libraries for this.</li> <li>C++ member functions can be declared as <a href="/wiki/Virtual_function" title="Virtual function">virtual functions</a>, which means the method to be called is determined by the run-time type of the object (a.k.a. dynamic dispatching). By default, methods in C++ are not virtual (i.e., <i>opt-in virtual</i>). In Java, methods are virtual by default, but can be made non-virtual by using the <code><a href="/wiki/Final_(Java)" title="Final (Java)">final</a></code> keyword (i.e., <i>opt-out virtual</i>).</li> <li>C++ enumerations are primitive types and support implicit conversion to integer types (but not from integer types). Java enumerations can be <code>public static enum{enumName1,enumName2}</code> and are used like classes. Another way is to make another class that extends <code>java.lang.Enum&lt;E&gt;</code>) and may therefore define constructors, fields, and methods as any other class. As of <a href="/wiki/C%2B%2B11" title="C++11">C++11</a>, C++ supports <a href="/wiki/C%2B%2B11#Strongly_typed_enumerations" title="C++11">strongly-typed enumerations</a> which provide more type-safety and explicit specification of the storage type.</li> <li>Unary operators '++' and '--': in C++ "The operand shall be a modifiable <a href="/wiki/Value_(computer_science)" title="Value (computer science)">lvalue</a>. [skipped] The result is the updated operand; it is an lvalue...",<sup id="cite_ref-20" class="reference"><a href="#cite_note-20"><span class="cite-bracket">&#91;</span>20<span class="cite-bracket">&#93;</span></a></sup> but in Java "the binary numeric promotion mentioned above may include unboxing conversion and value set conversion. If necessary, value set conversion {and/or [...] boxing conversion} is applied to the sum prior to its being stored in the variable.",<sup id="cite_ref-21" class="reference"><a href="#cite_note-21"><span class="cite-bracket">&#91;</span>21<span class="cite-bracket">&#93;</span></a></sup> i.e. in Java, after the initialization "Integer i=2;", "++i;" changes the reference i by assigning new object, while in C++ the object is still the same.</li></ul> <div class="mw-heading mw-heading3"><h3 id="Resource_management">Resource management</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=5" title="Edit section: Resource management"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li>Java offers automatic <a href="/wiki/Garbage_collection_(computer_science)" title="Garbage collection (computer science)">garbage collection</a>, which may be bypassed in specific circumstances via the <a href="/wiki/Real_time_Java" class="mw-redirect" title="Real time Java">Real time Java</a> specification. Memory management in C++ is usually done via constructors, destructors, and <a href="/wiki/Smart_pointer" title="Smart pointer">smart pointers</a>. The C++ standard permits garbage collection, but does not require it. Garbage collection is rarely used in practice.</li> <li>C++ can allocate arbitrary blocks of memory. Java only allocates memory via object instantiation. Arbitrary memory blocks may be allocated in Java as an array of bytes.</li> <li>Java and C++ use different idioms for resource management. Java relies mainly on garbage collection, which can reclaim memory,<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-2" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> while C++ relies mainly on the <a href="/wiki/Resource_Acquisition_Is_Initialization" class="mw-redirect" title="Resource Acquisition Is Initialization">Resource Acquisition Is Initialization</a> (RAII) idiom. This is reflected in several differences between the two languages: <ul><li>In C++ it is common to allocate objects of compound types as local stack-bound variables which are destroyed when they go out of scope. In Java compound types are always allocated on the heap and collected by the garbage collector (except in virtual machines that use <a href="/wiki/Escape_analysis" title="Escape analysis">escape analysis</a> to convert heap allocations to stack allocations).</li> <li>C++ has destructors,<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-3" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> while Java has <a href="/wiki/Finalizer" title="Finalizer">finalizers</a>.<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-4" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> Both are invoked before an object's deallocation, but they differ significantly. A C++ object's destructor must be invoked implicitly (in the case of stack-bound variables) or explicitly to deallocate an object. The destructor executes <a href="/wiki/Synchronization" title="Synchronization">synchronously</a> just before the point in a program at which an object is deallocated. Synchronous, coordinated uninitializing and deallocating in C++ thus satisfy the RAII idiom. Destructors in C++ is the normal way of getting back the resources associated with an object, and is a needed counterpart to constructors.<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-5" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> In Java, object deallocation is implicitly handled by the garbage collector. A Java object's finalizer is invoked <a href="/wiki/Asynchrony_(computer_programming)" title="Asynchrony (computer programming)">asynchronously</a> some time after it has been accessed for the last time and before it is deallocated. Very few objects need finalizers. A finalizer is needed by only objects that must guarantee some cleanup of the object state before deallocating, typically releasing resources external to the JVM.<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-6" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> Direct usages of finalizers are usually not advised, as they are unpredictable, usually dangerous, and most of the time unneeded.<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-7" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> One has to be cautious not to think of finalizers as C++ destructors.<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-8" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> Rather, the try-with-resources or try-finally block achieves a more similar purpose as the destructor.<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-9" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> One problem with finalizers or cleaners is that it is not guaranteed that they will run immediately.<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-10" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> Hence, a finalizer should never be used for tasks that are time-critical.<sup id="cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-11" class="reference"><a href="#cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> Additionally, finalizers come with severe performance penalties and significantly increase the time it takes for objects to be deallocated, so their use is discouraged and deprecated in Java 9.</li> <li>With RAII in C++, one type of resource is typically wrapped inside a small class that allocates the resource upon construction and releases the resource upon destruction, and provide access to the resource in between those points. Any class that contain only such RAII objects do not need to define a destructor since the destructors of the RAII objects are called automatically as an object of this class is destroyed. In Java, safe synchronous deallocation of resources can be performed deterministically using the try/catch/finally construct. Alternatively, the try-with-resources construct, which was introduced in Java 7, should be used in preference to try-finally construct. <sup id="cite_ref-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally_22-0" class="reference"><a href="#cite_note-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally-22"><span class="cite-bracket">&#91;</span>22<span class="cite-bracket">&#93;</span></a></sup> The try-with-resources construct is more concise and readable.<sup id="cite_ref-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally_22-1" class="reference"><a href="#cite_note-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally-22"><span class="cite-bracket">&#91;</span>22<span class="cite-bracket">&#93;</span></a></sup> It also provide more helpful diagnostic information, since suppressed exception are not discarded, and will be printed in the stack trace with information saying that they were suppressed.<sup id="cite_ref-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally_22-2" class="reference"><a href="#cite_note-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally-22"><span class="cite-bracket">&#91;</span>22<span class="cite-bracket">&#93;</span></a></sup></li> <li>In C++, it is possible to have a <a href="/wiki/Dangling_pointer" title="Dangling pointer">dangling pointer</a>, a stale <a href="/wiki/Reference_(computer_science)" title="Reference (computer science)">reference</a> to an object that has already been deallocated. Attempting to use a dangling pointer typically results in program failure. In Java, the garbage collector will not destroy a referenced object.</li> <li>In C++, it is possible to have uninitialized primitive objects. Java enforces default initialization.</li> <li>In C++, it is possible to have an allocated object to which there is no valid reference. Such an <a href="/wiki/Unreachable_object" class="mw-redirect" title="Unreachable object">unreachable object</a> cannot be destroyed (deallocated), and results in a <a href="/wiki/Memory_leak" title="Memory leak">memory leak</a>. In contrast, in Java an object will not be deallocated by the garbage collector <i>until</i> it becomes unreachable (by the user program). (<i><a href="/wiki/Weak_reference" title="Weak reference">Weak references</a></i> are supported, which work with the Java garbage collector to allow for different <i>strengths</i> of reachability.) Garbage collection in Java prevents many memory leaks, but leaks are still possible under some circumstances.<sup id="cite_ref-23" class="reference"><a href="#cite_note-23"><span class="cite-bracket">&#91;</span>23<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-24" class="reference"><a href="#cite_note-24"><span class="cite-bracket">&#91;</span>24<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-25" class="reference"><a href="#cite_note-25"><span class="cite-bracket">&#91;</span>25<span class="cite-bracket">&#93;</span></a></sup> The automatic garbage collector may give the false impression that in Java one does not need to think about memory management.<sup id="cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-2" class="reference"><a href="#cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> However this is not quite true.<sup id="cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-3" class="reference"><a href="#cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> Loosely speaking, this is because a program can have "memory leaks", more formally known as "unintentional object retentions".<sup id="cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-4" class="reference"><a href="#cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> An example of a memory leak that may occur is for a program that has been written without any logical errors, except that it did not eliminate obsolete references.<sup id="cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-5" class="reference"><a href="#cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> This results in higher use of garbage collector activity, higher <a href="/wiki/Memory_footprint" title="Memory footprint">memory footprint</a>.<sup id="cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-6" class="reference"><a href="#cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> In extreme circumstances, this problem can lead to an OutOfMemoryError, but this rarely happens.</li></ul></li></ul> <p><sup id="cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-7" class="reference"><a href="#cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> The solution to this is to null out object references. <sup id="cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-8" class="reference"><a href="#cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> A second common reason for memory leak is the use of cache that has become no longer relevant. The solution to memory leaks due to using old cache is to represent the cache using a <code>WeakHashMap</code>. </p> <div class="mw-heading mw-heading3"><h3 id="Libraries">Libraries</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=6" title="Edit section: Libraries"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li>C++ provides <a href="/wiki/Cross-platform" class="mw-redirect" title="Cross-platform">cross-platform</a> access to many features typically available in platform-specific libraries. Direct access from Java to native operating system and hardware functions requires the use of the <a href="/wiki/Java_Native_Interface" title="Java Native Interface">Java Native Interface</a>.</li></ul> <div class="mw-heading mw-heading3"><h3 id="Runtime">Runtime</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=7" title="Edit section: Runtime"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <table class="wikitable"> <tbody><tr> <th style="width:50%;">C++ </th> <th style="width:50%;">Java </th></tr> <tr> <td>C++ is compiled directly to <a href="/wiki/Machine_code" title="Machine code">machine code</a> which is then executed directly by the <a href="/wiki/Central_processing_unit" title="Central processing unit">central processing unit</a>. </td> <td>Java is compiled to <a href="/wiki/Byte-code" class="mw-redirect" title="Byte-code">byte-code</a> which the <a href="/wiki/Java_virtual_machine" title="Java virtual machine">Java virtual machine</a> (JVM) then <a href="/wiki/Interpreter_(computing)" title="Interpreter (computing)">interprets</a> at runtime. Actual Java implementations do <a href="/wiki/Just-in-time_compilation" title="Just-in-time compilation">just-in-time compilation</a> to native machine code. </td></tr> </tbody></table> <ul><li>Due to its unconstrained expressiveness, low level C++ language features (e.g. unchecked array access, raw pointers, <a href="/wiki/Type_punning" title="Type punning">type punning</a>) cannot be reliably checked at compile-time or without overhead at run-time. Related programming errors can lead to low-level <a href="/wiki/Buffer_overflow" title="Buffer overflow">buffer overflows</a> and <a href="/wiki/Segmentation_fault" title="Segmentation fault">segmentation faults</a>. The <a href="/wiki/Standard_Template_Library" title="Standard Template Library">Standard Template Library</a> 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 <a href="/wiki/Java_virtual_machine" title="Java virtual machine">Java virtual machine</a> (JVM) and reported to the application in the form of an <a href="/wiki/Exception_handling" title="Exception handling">exception</a>.</li> <li>The Java language requires specific behavior in the case of an out-of-bounds array access, which generally requires <a href="/wiki/Bounds_checking" title="Bounds checking">bounds checking</a> 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, <a href="/wiki/Compiler_analysis" class="mw-redirect" title="Compiler analysis">compiler analysis</a> 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."</li></ul> <div class="mw-heading mw-heading3"><h3 id="Templates_vs._generics">Templates vs. generics</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=8" title="Edit section: Templates vs. generics"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Both C++ and Java provide facilities for <a href="/wiki/Generic_programming" title="Generic programming">generic programming</a>, <a href="/wiki/Template_(programming)" class="mw-redirect" title="Template (programming)">templates</a> and <a href="/wiki/Generics_in_Java" title="Generics in Java">generics</a>, respectively. Although they were created to solve similar kinds of problems, and have similar syntax, they are quite different. </p> <dl><dd><table class="wikitable"> <tbody><tr> <th>C++ Templates </th> <th>Java Generics </th></tr> <tr> <td>Classes, functions, aliases<sup id="cite_ref-26" class="reference"><a href="#cite_note-26"><span class="cite-bracket">&#91;</span>26<span class="cite-bracket">&#93;</span></a></sup> and variables<sup id="cite_ref-27" class="reference"><a href="#cite_note-27"><span class="cite-bracket">&#91;</span>27<span class="cite-bracket">&#93;</span></a></sup> can be templated. </td> <td>Classes and methods can be genericized. </td></tr> <tr> <td>Parameters can be variadic, of any type, integral value, character literal, or a class template. </td> <td>Parameters can be any reference type, including boxed primitive types (i.e. Integer, Boolean...). </td></tr> <tr> <td>Separate instantiations of the class or function will be generated for each parameter-set when compiled. For class templates, only the member functions that are used will be instantiated. </td> <td>One version of the class or function is compiled, works for all type parameters (via type-erasure). </td></tr> <tr> <td>Objects of a class template instantiated with different parameters will have different types at run time (i.e., distinct template instantiations are distinct classes). </td> <td>Type parameters are erased when compiled; objects of a class with different type parameters are the same type at run time. It causes a different constructor. Because of this type erasure, it is not possible to overload methods using different instantiations of the generic class. </td></tr> <tr> <td>Implementation of the class or function template must be visible within a translation unit in order to use it. This usually implies having the definitions in the header files or included in the header file. As of <a href="/wiki/C%2B%2B11" title="C++11">C++11</a>, it is possible to use <a href="/wiki/C%2B%2B11#Extern_template" title="C++11">extern templates</a> to separate compiling of some instantiations. </td> <td>Signature of the class or function from a compiled class file is sufficient to use it. </td></tr> <tr> <td>Templates can be <a href="/wiki/Template_(programming)#Explicit_template_specialization" class="mw-redirect" title="Template (programming)">specialized</a>—a separate implementation could be provided for a particular template parameter. </td> <td>Generics cannot be specialized. </td></tr> <tr> <td>Template parameters can have <a href="/wiki/Default_argument" title="Default argument">default arguments</a>. Pre-<a href="/wiki/C%2B%2B11" title="C++11">C++11</a>, this was allowed only for template classes, not functions. </td> <td>Generic type parameters cannot have default arguments. </td></tr> <tr> <td>Wildcards unsupported. Instead, return types are often available as nested <a href="/wiki/Typedef" title="Typedef">typedefs</a>. (Also, <a href="/wiki/C%2B%2B11" title="C++11">C++11</a> added keyword <code>auto</code>, which acts as a wildcard for any type that can be determined at compile time.) </td> <td>Wildcards supported as type parameter. </td></tr> <tr> <td>Bounding of type parameters and enforcement of relationships between type parameters effectively possible through metaprogramming,<sup id="cite_ref-28" class="reference"><a href="#cite_note-28"><span class="cite-bracket">&#91;</span>28<span class="cite-bracket">&#93;</span></a></sup> or since C++20, directly via <code>std::derived_from</code> and other <a href="/wiki/Concepts_(C%2B%2B)" title="Concepts (C++)">concepts</a> </td> <td>Supports bounding of type parameters with "extends" and "super" for upper and lower bounds, respectively; allows enforcement of relationships between type parameters. </td></tr> <tr> <td>Allows instantiation of an object with the type of the parameter type. </td> <td>Precludes instantiation of an object with the type of the parameter type (except via reflection). </td></tr> <tr> <td>Type parameter of class template can be used for static methods and variables. </td> <td>Type parameter of generic class cannot be used for static methods and variables. </td></tr> <tr> <td><a href="/wiki/Static_variable" title="Static variable">Static variables</a> unshared between classes and functions of different type parameters. </td> <td>Static variables shared between instances of classes of different type parameters. </td></tr> <tr> <td>Class and function templates do not necessarily enforce type relations for type parameters in their declaration. Use of an incorrect type parameter results in compiling failure, often generating an error message within the template code rather than in the user's code that invokes it. Proper use of templated classes and functions is dependent on proper documentation. Metaprogramming provides these features at the cost of added effort. Since C++20, <a href="/wiki/Concepts_(C%2B%2B)" title="Concepts (C++)">concepts</a> can be used to provide these features. </td> <td>Generic classes and functions can enforce type relationships for type parameters in their declaration. Use of an incorrect type parameter results in a type error within the code that uses it. Operations on parametrized types in generic code are only allowed in ways that can be guaranteed to be safe by the declaration. This results in greater type safety at the cost of flexibility. </td></tr> <tr> <td>Templates are <a href="/wiki/Turing-complete" class="mw-redirect" title="Turing-complete">Turing-complete</a> (see <a href="/wiki/Template_metaprogramming" title="Template metaprogramming">template metaprogramming</a>). </td> <td>Generics are also Turing-complete<sup id="cite_ref-29" class="reference"><a href="#cite_note-29"><span class="cite-bracket">&#91;</span>29<span class="cite-bracket">&#93;</span></a></sup> </td></tr></tbody></table></dd></dl> <div class="mw-heading mw-heading3"><h3 id="Miscellaneous">Miscellaneous</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=9" title="Edit section: Miscellaneous"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li>Java and C++ use different means to divide code into multiple source files. <ul><li>Java uses a package system that dictates the file name and path for all program definitions. Its compiler imports the executable <a href="/wiki/Class_(file_format)" class="mw-redirect" title="Class (file format)">class files</a>.</li> <li>Prior to C++20, C++ used a <a href="/wiki/Header_file" class="mw-redirect" title="Header file">header file</a> <a href="/wiki/Source_code" title="Source code">source code</a> inclusion system to share declarations between source files. Since C++20, however, modules were introduced offering similar functionality to Java packages, however C++ modules do not have the same hierarchical structure of Java packages and do not have the same granularity, allowing for importing individual functions or classes - rather, all symbols marked <code>export</code> are accessible after importing a module.</li> <li>Since C++23, the C++ standard library can now be imported as a module, but must be imported in its entirety rather than importing specific packages of the library like in Java.</li></ul></li> <li>Compiled Java code files are generally smaller than code files in C++ as <a href="/wiki/Java_bytecode" title="Java bytecode">Java bytecode</a> is usually more compact than native <a href="/wiki/Machine_code" title="Machine code">machine code</a> and Java programs are never statically linked.</li> <li>C++ compiling features an added textual <a href="/wiki/Preprocessor" title="Preprocessor">preprocessing</a> phase, while Java does not. Thus some users add a preprocessing phase to their build process for better support of conditional compiling.</li> <li>Java's division and modulus operators are well defined to truncate to zero. C++ (pre-<a href="/wiki/C%2B%2B11" title="C++11">C++11</a>) does not specify whether or not these operators truncate to zero or "truncate to -infinity". -3/2 will always be -1 in Java and C++11, but a <a href="/wiki/C%2B%2B03" title="C++03">C++03</a> compiler may return either -1 or -2, depending on the platform. <a href="/wiki/C99" title="C99">C99</a> defines division in the same fashion as Java and C++11. Both languages guarantee (where a and b are integer types) that <code>(a/b)*b + (a%b) == a</code> for all a and b (b&#160;!= 0). The <a href="/wiki/C%2B%2B03" title="C++03">C++03</a> version will sometimes be faster, as it is allowed to pick whichever truncation mode is native to the processor.</li> <li>The sizes of integer types are defined in Java (int is 32-bit, long is 64-bit), while in C++ the size of integers and pointers is compiler and <a href="/wiki/Application_binary_interface" title="Application binary interface">application binary interface</a> (ABI) dependent within given constraints. Thus a Java program will have consistent behavior across platforms, whereas a C++ program may require adapting for some platforms, but may run faster with more natural integer sizes for the local platform.</li></ul> <p>An example comparing <a href="https://en.wikibooks.org/wiki/C%2B%2B_Programming/Code/IO#.E2.80.8ERounding_number_example" class="extiw" title="wikibooks:C++ Programming/Code/IO">C++</a> and <a href="https://en.wikibooks.org/wiki/Java_Programming/Mathematical_functions#Rounding_number_example" class="extiw" title="wikibooks:Java Programming/Mathematical functions">Java</a> exists in <a href="/wiki/Wikibooks" title="Wikibooks">Wikibooks</a>. </p> <div class="mw-heading mw-heading2"><h2 id="Performance">Performance</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=10" title="Edit section: Performance"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1251242444"><table class="box-More_citations_needed_section plainlinks metadata ambox ambox-content ambox-Refimprove" role="presentation"><tbody><tr><td class="mbox-image"><div class="mbox-image-div"><span typeof="mw:File"><a href="/wiki/File:Question_book-new.svg" class="mw-file-description"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/50px-Question_book-new.svg.png" decoding="async" width="50" height="39" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/75px-Question_book-new.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/100px-Question_book-new.svg.png 2x" data-file-width="512" data-file-height="399" /></a></span></div></td><td class="mbox-text"><div class="mbox-text-span">This section <b>needs additional citations for <a href="/wiki/Wikipedia:Verifiability" title="Wikipedia:Verifiability">verification</a></b>.<span class="hide-when-compact"> Please help <a href="/wiki/Special:EditPage/Comparison_of_Java_and_C%2B%2B" title="Special:EditPage/Comparison of Java and C++">improve this article</a> by <a href="/wiki/Help:Referencing_for_beginners" title="Help:Referencing for beginners">adding citations to reliable sources</a>&#32;in this section. Unsourced material may be challenged and removed.</span> <span class="date-container"><i>(<span class="date">September 2010</span>)</i></span><span class="hide-when-compact"><i> (<small><a href="/wiki/Help:Maintenance_template_removal" title="Help:Maintenance template removal">Learn how and when to remove this message</a></small>)</i></span></div></td></tr></tbody></table> <p>In addition to running a compiled Java program, computers running Java applications generally must also run the <a href="/wiki/Java_virtual_machine" title="Java virtual machine">Java virtual machine</a> (JVM), while compiled C++ programs can be run without external applications. Early versions of Java were significantly outperformed by statically compiled languages such as C++. This is because the program statements of these two closely related languages may compile to a few machine instructions with C++, while compiling into several byte codes involving several machine instructions each when interpreted by a JVM. For example: </p> <table class="wikitable"> <tbody><tr> <th>Java/C++ statement </th> <th>C++ generated code (x86) </th> <th>Java generated byte code </th></tr> <tr> <td><code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">a[i]++;</code> </td> <td><div class="mw-highlight mw-highlight-lang-nasm mw-content-ltr" dir="ltr"><pre><span></span><span class="nf">mov</span><span class="w"> </span><span class="nb">edx</span><span class="p">,[</span><span class="nb">ebp</span><span class="o">+</span><span class="mh">4h</span><span class="p">]</span> <span class="nf">mov</span><span class="w"> </span><span class="nb">eax</span><span class="p">,[</span><span class="nb">ebp</span><span class="o">+</span><span class="mh">1Ch</span><span class="p">]</span> <span class="nf">inc</span><span class="w"> </span><span class="kt">dword</span><span class="w"> </span><span class="nv">ptr</span><span class="w"> </span><span class="p">[</span><span class="nb">edx</span><span class="o">+</span><span class="nb">eax</span><span class="o">*</span><span class="mi">4</span><span class="p">]</span> </pre></div> </td> <td><style data-mw-deduplicate="TemplateStyles:r1195917819">.mw-parser-output .pre-borderless{border:none}</style><pre class="pre">aload_1 iload_2 dup2 iaload iconst_1 iadd iastore</pre> </td></tr></tbody></table> <p>Since performance optimization is a very complex issue, it is very difficult to quantify the performance difference between C++ and Java in general terms, and most benchmarks are unreliable and biased. Given the very different natures of the languages, definitive qualitative differences are also difficult to draw. In a nutshell, there are inherent inefficiencies and hard limits on optimizing in Java, given that it heavily relies on flexible high-level abstractions, however, the use of a powerful JIT compiler (as in modern JVM implementations) can mitigate some issues. In any case, if the inefficiencies of Java are too great, compiled C or C++ code can be called from Java via the JNI. </p><p>Some inefficiencies that are inherent to the Java language include, mainly: </p> <ul><li>All objects are allocated on the heap. Though allocation is extremely fast in modern JVMs using 'bump allocation', which performs similarly to stack allocation, performance can still be negatively impacted due to the invocation of the garbage collector. Modern JIT compilers mitigate this problem to some extent with escape analysis or escape detection to allocate some objects on the stack, since Oracle JDK 6.</li> <li>Performance-critical projects like efficient database systems and messaging libraries have had to use internal unofficial APIs like <code>sun.misc.Unsafe</code> to gain access to manual resource management and be able to do stack allocation; effectively manipulating pseudo-pointers.</li> <li>A lot of run-time casting required even using standard containers induces a performance penalty. However, most of these casts are statically eliminated by the JIT compiler.</li> <li>Safety guarantees come at a run-time cost. For example, the compiler is required to put appropriate range checks in the code. Guarding each array access with a range check is not efficient, so most JIT compilers will try to eliminate them statically or by moving them out of inner loops (although most native compilers for C++ will do the same when range-checks are optionally used).</li> <li>Lack of access to low-level details prevents the developer from improving the program where the compiler is unable to do so.<sup id="cite_ref-30" class="reference"><a href="#cite_note-30"><span class="cite-bracket">&#91;</span>30<span class="cite-bracket">&#93;</span></a></sup></li> <li>The mandatory use of reference-semantics for all user-defined types in Java can introduce large amounts of superfluous memory indirections (or jumps) (unless elided by the JIT compiler) which can lead to frequent cache misses (a.k.a. <a href="/wiki/Thrashing_(computer_science)" title="Thrashing (computer science)">cache thrashing</a>). Furthermore, cache-optimization, usually via cache-aware or <a href="/wiki/Cache-oblivious_algorithm" title="Cache-oblivious algorithm">cache-oblivious</a> data structures and algorithms, can often lead to orders of magnitude improvements in performance as well as avoiding time-complexity degeneracy that is characteristic of many cache-pessimizing algorithms, and is therefore one of the most important forms of optimization; reference-semantics, as mandated in Java, makes such optimizations impossible to realize in practice (by neither the programmer nor the JIT compiler).</li> <li><a href="/wiki/Garbage_collection_(computer_science)" title="Garbage collection (computer science)">Garbage collection</a>,<sup id="cite_ref-hundt2011_31-0" class="reference"><a href="#cite_note-hundt2011-31"><span class="cite-bracket">&#91;</span>31<span class="cite-bracket">&#93;</span></a></sup> as this form of automatic memory management introduces memory overhead.<sup id="cite_ref-HertzBerger2005_32-0" class="reference"><a href="#cite_note-HertzBerger2005-32"><span class="cite-bracket">&#91;</span>32<span class="cite-bracket">&#93;</span></a></sup></li></ul> <p>However, there are a number of benefits to Java's design, some realized, some only theorized: </p> <ul><li>Java <a href="/wiki/Garbage_collection_(computer_science)" title="Garbage collection (computer science)">garbage collection</a> may have better cache coherence than the usual use of <i><a href="/wiki/Malloc" class="mw-redirect" title="Malloc">malloc</a></i>/<i><a href="/wiki/New_(C%2B%2B)" class="mw-redirect" title="New (C++)">new</a></i> for memory allocation. Nevertheless, arguments exist<sup class="noprint Inline-Template" style="margin-left:0.1em; white-space:nowrap;">&#91;<i><a href="/wiki/Wikipedia:Avoid_weasel_words" class="mw-redirect" title="Wikipedia:Avoid weasel words"><span title="Who says this? (March 2012)">weasel&#160;words</span></a></i>&#93;</sup> that both allocators equally fragment the heap and neither exhibits better cache locality. However, in C++, allocation of single objects on the heap is rare, and large quantities of single objects are usually allocated in blocks via an STL container and/or with a small object allocator.<sup id="cite_ref-33" class="reference"><a href="#cite_note-33"><span class="cite-bracket">&#91;</span>33<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-34" class="reference"><a href="#cite_note-34"><span class="cite-bracket">&#91;</span>34<span class="cite-bracket">&#93;</span></a></sup></li> <li>Run-time compiling can potentially use information about the platform on which the code is being executed to improve code more effectively. However, most state-of-the-art native (C, C++, etc.) compilers generate multiple code paths to employ the full computational abilities of the given system.<sup id="cite_ref-35" class="reference"><a href="#cite_note-35"><span class="cite-bracket">&#91;</span>35<span class="cite-bracket">&#93;</span></a></sup> Also, the inverse argument can be made that native compilers can better exploit architecture-specific optimizing and instruction sets than multi-platform JVM distributions.</li> <li>Run-time compiling allows for more aggressive virtual function inlining than is possible for a static compiler, because the JIT compiler has more information about all possible targets of virtual calls, even if they are in different dynamically loaded modules. Currently available JVM implementations have no problem in inlining most of the monomorphic, mostly monomorphic and dimorphic calls, and research is in progress to inline also megamorphic calls, thanks to the recent invoke dynamic enhancements added in Java 7.<sup id="cite_ref-36" class="reference"><a href="#cite_note-36"><span class="cite-bracket">&#91;</span>36<span class="cite-bracket">&#93;</span></a></sup> Inlining can allow for further optimisations like loop vectorisation or <a href="/wiki/Loop_unwinding" class="mw-redirect" title="Loop unwinding">loop unrolling</a>, resulting in a huge overall performance increase.</li> <li>In Java, thread synchronizing is built into the language,<sup id="cite_ref-FOOTNOTEBloch2018126–129Chapter_§11_Item_78:_Synchronize_access_to_shared_mutable_data_19-1" class="reference"><a href="#cite_note-FOOTNOTEBloch2018126–129Chapter_§11_Item_78:_Synchronize_access_to_shared_mutable_data-19"><span class="cite-bracket">&#91;</span>19<span class="cite-bracket">&#93;</span></a></sup> so the JIT compiler can potentially, via escape analysis, elide locks,<sup id="cite_ref-37" class="reference"><a href="#cite_note-37"><span class="cite-bracket">&#91;</span>37<span class="cite-bracket">&#93;</span></a></sup> significantly improve the performance of naive multi-threaded code.</li></ul> <p>Also, some performance problems occur in C++: </p> <ul><li>Allowing pointers to point to any address can make optimizing difficult due to the possibility of <a href="/wiki/Pointer_aliasing" class="mw-redirect" title="Pointer aliasing">pointer aliasing</a>.</li> <li>Since the code generated from various instantiations of the same class template in C++ is not shared (as with type-erased generics in Java), excessive use of templates may lead to significant increase of the executable code size (<a href="/wiki/Code_bloat" title="Code bloat">code bloat</a>). However, because function templates are aggressively inlined, they can sometimes reduce code size, but more importantly allow for more aggressive static analysis and code optimizing by the compiler, more often making them more efficient than non-templated code. In contrast, Java generics are necessarily less efficient than non-genericized code.</li> <li>Because in a traditional C++ compiler, dynamic linking is performed after code generating and optimizing in C++, function calls spanning different dynamic modules cannot be inlined. However modern C++ compilers like MSVC and Clang+LLVM offer link-time-code-generation options that allow modules to be compiled to intermediate formats which allows inlining at the final link stage.</li></ul> <div class="mw-heading mw-heading2"><h2 id="Official_standard_and_reference_of_the_language">Official standard and reference of the language</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=11" title="Edit section: Official standard and reference of the language"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-heading mw-heading3"><h3 id="Language_specification">Language specification</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=12" title="Edit section: Language specification"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The C++ language is defined by <i>ISO/IEC 14882</i>, an <a href="/wiki/International_Organization_for_Standardization" title="International Organization for Standardization">ISO</a> standard, which is published by the <i>ISO/IEC JTC1/SC22/WG21</i> committee. The latest, post-standardization draft of <a href="/wiki/C%2B%2B17" title="C++17">C++17</a> is available as well.<sup id="cite_ref-38" class="reference"><a href="#cite_note-38"><span class="cite-bracket">&#91;</span>38<span class="cite-bracket">&#93;</span></a></sup> </p><p>The C++ language evolves via an open steering committee called the C++ Standards Committee. The committee is composed of the creator of C++ <a href="/wiki/Bjarne_Stroustrup" title="Bjarne Stroustrup">Bjarne Stroustrup</a>, the convener <a href="/wiki/Herb_Sutter" title="Herb Sutter">Herb Sutter</a>, and other prominent figures, including many representatives of industries and user-groups (i.e., the stake-holders). Being an open committee, anyone is free to join, participate, and contribute proposals for upcoming releases of the standard and technical specifications. The committee now aims to release a new standard every few years, although in the past strict review processes and discussions have meant longer delays between publication of new standards (1998, 2003, and 2011). </p><p>The Java language is defined by the <i>Java Language Specification</i>,<sup id="cite_ref-39" class="reference"><a href="#cite_note-39"><span class="cite-bracket">&#91;</span>39<span class="cite-bracket">&#93;</span></a></sup> a book which is published by Oracle. </p><p>The Java language continuously evolves via a process called the <a href="/wiki/Java_Community_Process" title="Java Community Process">Java Community Process</a>, and the world's programming community is represented by a group of people and organizations - the Java Community members<sup id="cite_ref-40" class="reference"><a href="#cite_note-40"><span class="cite-bracket">&#91;</span>40<span class="cite-bracket">&#93;</span></a></sup>—which is actively engaged into the enhancement of the language, by sending public requests - the Java Specification Requests - which must pass formal and public reviews before they get integrated into the language. </p><p>The lack of a firm standard for Java and the somewhat more volatile nature of its specifications have been a constant source of criticism by stake-holders wanting more stability and conservatism in the addition of new language and library features. In contrast, the C++ committee also receives constant criticism, for the opposite reason, i.e., being too strict and conservative, and taking too long to release new versions. </p> <div class="mw-heading mw-heading3"><h3 id="Trademarks">Trademarks</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=13" title="Edit section: Trademarks"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>"C++" is not a trademark of any company or organization and is not owned by any individual.<sup id="cite_ref-41" class="reference"><a href="#cite_note-41"><span class="cite-bracket">&#91;</span>41<span class="cite-bracket">&#93;</span></a></sup> "Java" is a trademark of <a href="/wiki/Oracle_Corporation" title="Oracle Corporation">Oracle Corporation</a>.<sup id="cite_ref-42" class="reference"><a href="#cite_note-42"><span class="cite-bracket">&#91;</span>42<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="References">References</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=14" title="Edit section: References"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-heading mw-heading3"><h3 id="Citations">Citations</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=15" title="Edit section: Citations"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1239543626">.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}</style><div class="reflist"> <div class="mw-references-wrap mw-references-columns"><ol class="references"> <li id="cite_note-FOOTNOTEBloch2018xi–xiiForeword-1"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEBloch2018xi–xiiForeword_1-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018xi–xiiForeword_1-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018xi–xiiForeword_1-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFBloch2018">Bloch 2018</a>, pp.&#160;xi–xii, Foreword.</span> </li> <li id="cite_note-FOOTNOTEBloch2018285Chapter_§11_Item_66:_Use_native_methods_judiciously-2"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEBloch2018285Chapter_§11_Item_66:_Use_native_methods_judiciously_2-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018285Chapter_§11_Item_66:_Use_native_methods_judiciously_2-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFBloch2018">Bloch 2018</a>, p.&#160;285, Chapter §11 Item 66: Use native methods judiciously.</span> </li> <li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/d/d6/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/a/aa/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/4/4c/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20170225213350/https://blogs.oracle.com/darcy/entry/unsigned_api">"Unsigned Integer Arithmetic API now in JDK 8"</a>. Archived from <a rel="nofollow" class="external text" href="https://blogs.oracle.com/darcy/entry/unsigned_api">the original</a> on 25 February 2017<span class="reference-accessdate">. Retrieved <span class="nowrap">17 March</span> 2014</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Unsigned+Integer+Arithmetic+API+now+in+JDK+8&amp;rft_id=https%3A%2F%2Fblogs.oracle.com%2Fdarcy%2Fentry%2Funsigned_api&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://download.oracle.com/javase/tutorial/java/javaOO/arguments.html">"The Java Tutorials: Passing Information to a Method or a Constructor"</a>. Oracle<span class="reference-accessdate">. Retrieved <span class="nowrap">17 February</span> 2013</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=The+Java+Tutorials%3A+Passing+Information+to+a+Method+or+a+Constructor&amp;rft.pub=Oracle&amp;rft_id=http%3A%2F%2Fdownload.oracle.com%2Fjavase%2Ftutorial%2Fjava%2FjavaOO%2Farguments.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references-5"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018123–125Chapter_§2_Item_7:_Eliminate_obsolete_references_5-8"><sup><i><b>i</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFBloch2018">Bloch 2018</a>, pp.&#160;123–125, Chapter §2 Item 7: Eliminate obsolete references.</span> </li> <li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html">"The Java Tutorials: Object as a Superclass"</a>. Oracle<span class="reference-accessdate">. Retrieved <span class="nowrap">17 February</span> 2013</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=The+Java+Tutorials%3A+Object+as+a+Superclass&amp;rft.pub=Oracle&amp;rft_id=http%3A%2F%2Fdocs.oracle.com%2Fjavase%2Ftutorial%2Fjava%2FIandI%2Fobjectclass.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span>.</span> </li> <li id="cite_note-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners-7"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-8"><sup><i><b>i</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-9"><sup><i><b>j</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-10"><sup><i><b>k</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201829–33Chapter_§2_Item_8:_Avoid_finalizers_and_cleaners_7-11"><sup><i><b>l</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFBloch2018">Bloch 2018</a>, pp.&#160;29–33, Chapter §2 Item 8: Avoid finalizers and cleaners.</span> </li> <li id="cite_note-XMPP_Software_»_Libraries-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-XMPP_Software_»_Libraries_8-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://xmpp.org/xmpp-software/libraries/">"XMPP Software&#160;» Libraries"</a>. xmpp.org<span class="reference-accessdate">. Retrieved <span class="nowrap">13 June</span> 2013</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=XMPP+Software+%C2%BB+Libraries&amp;rft.pub=xmpp.org&amp;rft_id=http%3A%2F%2Fxmpp.org%2Fxmpp-software%2Flibraries%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEGoetzPeierlsBlochBowbeer200648§3.4.1_Final_fields-9"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEGoetzPeierlsBlochBowbeer200648§3.4.1_Final_fields_9-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEGoetzPeierlsBlochBowbeer200648§3.4.1_Final_fields_9-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFGoetzPeierlsBlochBowbeer2006">Goetz et al. 2006</a>, p.&#160;48, §3.4.1 Final fields.</span> </li> <li id="cite_note-Martin-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-Martin_10-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFRobert_C._Martin1997" class="citation web cs1">Robert C. Martin (January 1997). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20080511205821/http://www.objectmentor.com/resources/articles/javacpp.pdf">"Java vs. C++: A Critical Comparison"</a> <span class="cs1-format">(PDF)</span>. Archived from <a rel="nofollow" class="external text" href="http://www.objectmentor.com/resources/articles/javacpp.pdf">the original</a> <span class="cs1-format">(PDF)</span> on 11 May 2008<span class="reference-accessdate">. Retrieved <span class="nowrap">15 December</span> 2007</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Java+vs.+C%2B%2B%3A+A+Critical+Comparison&amp;rft.date=1997-01&amp;rft.au=Robert+C.+Martin&amp;rft_id=http%3A%2F%2Fwww.objectmentor.com%2Fresources%2Farticles%2Fjavacpp.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-11">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3">"Reference Types and Values"</a>. <i>The Java Language Specification, Third Edition</i><span class="reference-accessdate">. Retrieved <span class="nowrap">9 December</span> 2010</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=The+Java+Language+Specification%2C+Third+Edition&amp;rft.atitle=Reference+Types+and+Values&amp;rft_id=http%3A%2F%2Fjava.sun.com%2Fdocs%2Fbooks%2Fjls%2Fthird_edition%2Fhtml%2FtypesValues.html%234.3&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-12">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFHorstmannCornell2008" class="citation book cs1">Horstmann, Cay; Cornell, Gary (2008). <i>Core Java</i>. Vol.&#160;I (Eighth&#160;ed.). Sun Microsystems. pp.&#160;140–141. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-13-235476-9" title="Special:BookSources/978-0-13-235476-9"><bdi>978-0-13-235476-9</bdi></a>. <q>Some programmers (and unfortunately even some book authors) claim that the Java programming language uses call by reference for objects. However, that is false. Because this is such a common misunderstanding, it is worth examining a counterexample in some detail... This discussion demonstrates that the Java programming language does not use call by reference for objects. Instead <i>object references are passed by value</i>.</q></cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Core+Java&amp;rft.pages=140-141&amp;rft.edition=Eighth&amp;rft.pub=Sun+Microsystems&amp;rft.date=2008&amp;rft.isbn=978-0-13-235476-9&amp;rft.aulast=Horstmann&amp;rft.aufirst=Cay&amp;rft.au=Cornell%2C+Gary&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFDeitelDeitel2009" class="citation book cs1">Deitel, Paul; Deitel, Harvey (2009). <i>Java for Programmers</i>. Prentice Hall. p.&#160;223. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-13-700129-3" title="Special:BookSources/978-0-13-700129-3"><bdi>978-0-13-700129-3</bdi></a>. <q>Unlike some other languages, Java does not allow programmers to choose pass-by-value or pass-by-reference—all arguments are passed by value. A method call can pass two types of values to a method—copies of primitive values (e.g., values of type int and double) and copies of references to objects (including references to arrays). Objects themselves cannot be passed to methods.</q></cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Java+for+Programmers&amp;rft.pages=223&amp;rft.pub=Prentice+Hall&amp;rft.date=2009&amp;rft.isbn=978-0-13-700129-3&amp;rft.aulast=Deitel&amp;rft.aufirst=Paul&amp;rft.au=Deitel%2C+Harvey&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://gcc.gnu.org/wiki/FloatingPointMath">"Semantics of Floating Point Math in GCC"</a>. GNU Foundation<span class="reference-accessdate">. Retrieved <span class="nowrap">20 April</span> 2013</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Semantics+of+Floating+Point+Math+in+GCC&amp;rft.pub=GNU+Foundation&amp;rft_id=https%3A%2F%2Fgcc.gnu.org%2Fwiki%2FFloatingPointMath&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-15">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://msdn.microsoft.com/en-us/library/e7s85ffb.aspx">"Microsoft c++ compiler, /fp (Specify Floating-Point Behavior)"</a>. Microsoft Corporation<span class="reference-accessdate">. Retrieved <span class="nowrap">19 March</span> 2013</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Microsoft+c%2B%2B+compiler%2C+%2Ffp+%28Specify+Floating-Point+Behavior%29&amp;rft.pub=Microsoft+Corporation&amp;rft_id=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fe7s85ffb.aspx&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3.1">"Java Language Specification 4.3.1: Objects"</a>. Sun Microsystems<span class="reference-accessdate">. Retrieved <span class="nowrap">9 December</span> 2010</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Java+Language+Specification+4.3.1%3A+Objects&amp;rft.pub=Sun+Microsystems&amp;rft_id=http%3A%2F%2Fjava.sun.com%2Fdocs%2Fbooks%2Fjls%2Fthird_edition%2Fhtml%2FtypesValues.html%234.3.1&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEBloch201887–92Chapter_§8_Item_8:_Favor_composition_over_inheritance-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEBloch201887–92Chapter_§8_Item_8:_Favor_composition_over_inheritance_17-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFBloch2018">Bloch 2018</a>, pp.&#160;87–92, Chapter §8 Item 8: Favor composition over inheritance.</span> </li> <li id="cite_note-FOOTNOTEGoetzPeierlsBlochBowbeer200625–26§2.3.1_Intrinsic_locks-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEGoetzPeierlsBlochBowbeer200625–26§2.3.1_Intrinsic_locks_18-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFGoetzPeierlsBlochBowbeer2006">Goetz et al. 2006</a>, pp.&#160;25–26, §2.3.1 Intrinsic locks.</span> </li> <li id="cite_note-FOOTNOTEBloch2018126–129Chapter_§11_Item_78:_Synchronize_access_to_shared_mutable_data-19"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEBloch2018126–129Chapter_§11_Item_78:_Synchronize_access_to_shared_mutable_data_19-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch2018126–129Chapter_§11_Item_78:_Synchronize_access_to_shared_mutable_data_19-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFBloch2018">Bloch 2018</a>, pp.&#160;126–129, Chapter §11 Item 78: Synchronize access to shared mutable data.</span> </li> <li id="cite_note-20"><span class="mw-cite-backlink"><b><a href="#cite_ref-20">^</a></b></span> <span class="reference-text">Standard for Programming Language C++ '11, 5.3.2 Increment and decrement [expr.pre.incr].</span> </li> <li id="cite_note-21"><span class="mw-cite-backlink"><b><a href="#cite_ref-21">^</a></b></span> <span class="reference-text">The Java™ Language Specification, Java SE 7 Edition, Chapters 15.14.2, 15.14.3, 15.15.1, 15.15.2, <a rel="nofollow" class="external free" href="http://docs.oracle.com/javase/specs/">http://docs.oracle.com/javase/specs/</a></span> </li> <li id="cite_note-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally-22"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally_22-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally_22-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201834–36Chapter_§2_Item_9:_Prefer_try-with-resources_to_try-finally_22-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFBloch2018">Bloch 2018</a>, pp.&#160;34–36, Chapter §2 Item 9: Prefer try-with-resources to try-finally.</span> </li> <li id="cite_note-23"><span class="mw-cite-backlink"><b><a href="#cite_ref-23">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFSatish_Chandra_GuptaRajeev_Palanki2005" class="citation web cs1">Satish Chandra Gupta; Rajeev Palanki (16 August 2005). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20120722095536/http://www.ibm.com/developerworks/rational/library/05/0816_GuptaPalanki/">"Java memory leaks – Catch me if you can"</a>. IBM DeveloperWorks. Archived from <a rel="nofollow" class="external text" href="http://www-128.ibm.com/developerworks/rational/library/05/0816_GuptaPalanki/">the original</a> on 22 July 2012<span class="reference-accessdate">. Retrieved <span class="nowrap">2 April</span> 2015</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Java+memory+leaks+%E2%80%93+Catch+me+if+you+can&amp;rft.pub=IBM+DeveloperWorks&amp;rft.date=2005-08-16&amp;rft.au=Satish+Chandra+Gupta&amp;rft.au=Rajeev+Palanki&amp;rft_id=http%3A%2F%2Fwww-128.ibm.com%2Fdeveloperworks%2Frational%2Flibrary%2F05%2F0816_GuptaPalanki%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-24"><span class="mw-cite-backlink"><b><a href="#cite_ref-24">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20140205030750/http://www.openlogic.com/wazi/bid/188158">How to Fix Memory Leaks in Java</a> by Veljko Krunic (10 Mar 2009)</span> </li> <li id="cite_note-25"><span class="mw-cite-backlink"><b><a href="#cite_ref-25">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java">Creating a memory leak with Java</a> on <a href="/wiki/Stackoverflow" class="mw-redirect" title="Stackoverflow">stackoverflow</a>.com</span> </li> <li id="cite_note-26"><span class="mw-cite-backlink"><b><a href="#cite_ref-26">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://en.cppreference.com/w/cpp/language/type_alias">"Type alias, alias template"</a>. <i>cppreference.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">4 October</span> 2022</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=cppreference.com&amp;rft.atitle=Type+alias%2C+alias+template&amp;rft_id=http%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Flanguage%2Ftype_alias&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-27"><span class="mw-cite-backlink"><b><a href="#cite_ref-27">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://en.cppreference.com/w/cpp/language/variable_template">"Variable template"</a>. <i>cppreference.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">4 October</span> 2022</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=cppreference.com&amp;rft.atitle=Variable+template&amp;rft_id=http%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Flanguage%2Fvariable_template&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-28"><span class="mw-cite-backlink"><b><a href="#cite_ref-28">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.boost.org/libs/type_traits/doc/html/boost_typetraits/reference.html">Boost type traits library</a></span> </li> <li id="cite_note-29"><span class="mw-cite-backlink"><b><a href="#cite_ref-29">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://arxiv.org/abs/1605.05274">Java Generics Are Turing Complete</a></span> </li> <li id="cite_note-30"><span class="mw-cite-backlink"><b><a href="#cite_ref-30">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFClarkAmir_HormatiSami_YehiaScott_Mahlke2007" class="citation journal cs1">Clark, Nathan; Amir Hormati; Sami Yehia; Scott Mahlke (2007). "Liquid SIMD: Abstracting SIMD hardware using lightweight dynamic mapping". <i>Hpca'07</i>: 216–227.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Hpca%2707&amp;rft.atitle=Liquid+SIMD%3A+Abstracting+SIMD+hardware+using+lightweight+dynamic+mapping&amp;rft.pages=216-227&amp;rft.date=2007&amp;rft.aulast=Clark&amp;rft.aufirst=Nathan&amp;rft.au=Amir+Hormati&amp;rft.au=Sami+Yehia&amp;rft.au=Scott+Mahlke&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-hundt2011-31"><span class="mw-cite-backlink"><b><a href="#cite_ref-hundt2011_31-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFHundt2011" class="citation web cs1">Hundt, Robert (27 April 2011). <a rel="nofollow" class="external text" href="https://days2011.scala-lang.org/sites/days2011/files/ws3-1-Hundt.pdf">"Loop Recognition in C++/Java/Go/Scala"</a> <span class="cs1-format">(PDF)</span>. Stanford, California: <a href="/w/index.php?title=Scala_Days&amp;action=edit&amp;redlink=1" class="new" title="Scala Days (page does not exist)">Scala Days</a> 2011. <a rel="nofollow" class="external text" href="https://ghostarchive.org/archive/20221009/https://days2011.scala-lang.org/sites/days2011/files/ws3-1-Hundt.pdf">Archived</a> <span class="cs1-format">(PDF)</span> from the original on 9 October 2022<span class="reference-accessdate">. Retrieved <span class="nowrap">17 November</span> 2012</span>. <q>Java shows a large GC component, but a good code performance. [...] We find that in regards to performance, C++ wins out by a large margin. [...] The Java version was probably the simplest to implement, but the hardest to analyze for performance. Specifically the effects around garbage collection were complicated and very hard to tune; 318&#160;kB</q></cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Loop+Recognition+in+C%2B%2B%2FJava%2FGo%2FScala&amp;rft.place=Stanford%2C+California&amp;rft.pub=Scala+Days+2011&amp;rft.date=2011-04-27&amp;rft.aulast=Hundt&amp;rft.aufirst=Robert&amp;rft_id=https%3A%2F%2Fdays2011.scala-lang.org%2Fsites%2Fdays2011%2Ffiles%2Fws3-1-Hundt.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-HertzBerger2005-32"><span class="mw-cite-backlink"><b><a href="#cite_ref-HertzBerger2005_32-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFMatthew_Hertz,_Emery_D._Berger2005" class="citation web cs1">Matthew Hertz, Emery D. Berger (2005). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20170706100244/https://people.cs.umass.edu/~emery/pubs/gcvsmalloc.pdf">"Quantifying the Performance of Garbage Collection vs. Explicit Memory Management"</a> <span class="cs1-format">(PDF)</span>. OOPSLA 2005. Archived from <a rel="nofollow" class="external text" href="http://people.cs.umass.edu/~emery/pubs/gcvsmalloc.pdf">the original</a> <span class="cs1-format">(PDF)</span> on 6 July 2017<span class="reference-accessdate">. Retrieved <span class="nowrap">15 March</span> 2015</span>. <q>In particular, when garbage collection has five times as much memory as required, its runtime performance matches or slightly exceeds that of explicit memory management. However, garbage collection's performance degrades substantially when it must use smaller heaps. With three times as much memory, it runs 17% slower on average, and with twice as much memory, it runs 70% slower.</q></cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Quantifying+the+Performance+of+Garbage+Collection+vs.+Explicit+Memory+Management&amp;rft.pub=OOPSLA+2005&amp;rft.date=2005&amp;rft.au=Matthew+Hertz%2C+Emery+D.+Berger&amp;rft_id=http%3A%2F%2Fpeople.cs.umass.edu%2F~emery%2Fpubs%2Fgcvsmalloc.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-33"><span class="mw-cite-backlink"><b><a href="#cite_ref-33">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFAlexandrescu2001" class="citation book cs1">Alexandrescu, Andrei (2001). Addison-Wesley (ed.). <i>Modern C++ Design: Generic Programming and Design Patterns Applied. Chapter 4</i>. pp.&#160;77–96. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-201-70431-0" title="Special:BookSources/978-0-201-70431-0"><bdi>978-0-201-70431-0</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Modern+C%2B%2B+Design%3A+Generic+Programming+and+Design+Patterns+Applied.+Chapter+4&amp;rft.pages=77-96&amp;rft.date=2001&amp;rft.isbn=978-0-201-70431-0&amp;rft.aulast=Alexandrescu&amp;rft.aufirst=Andrei&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-34"><span class="mw-cite-backlink"><b><a href="#cite_ref-34">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.boost.org/doc/libs/release/libs/pool/">"Boost Pool library"</a>. Boost<span class="reference-accessdate">. Retrieved <span class="nowrap">19 April</span> 2013</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Boost+Pool+library&amp;rft.pub=Boost&amp;rft_id=http%3A%2F%2Fwww.boost.org%2Fdoc%2Flibs%2Frelease%2Flibs%2Fpool%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-35"><span class="mw-cite-backlink"><b><a href="#cite_ref-35">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20200929080449/https://www.slac.stanford.edu/comp/unix/.../icc/.../optaps_dsp_qax.htm">Targeting IA-32 Architecture Processors for Run-time Performance Checking</a></span> </li> <li id="cite_note-36"><span class="mw-cite-backlink"><b><a href="#cite_ref-36">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20110907092432/http://www.azulsystems.com/blog/cliff/2011-04-04-fixing-the-inlining-problem">"Fixing The Inlining "Problem" by Dr. Cliff Click |Azul Systems: Blogs"</a>. Archived from <a rel="nofollow" class="external text" href="http://www.azulsystems.com/blog/cliff/2011-04-04-fixing-the-inlining-problem">the original</a> on 7 September 2011<span class="reference-accessdate">. Retrieved <span class="nowrap">23 September</span> 2011</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Fixing+The+Inlining+%22Problem%22+by+Dr.+Cliff+Click+%7CAzul+Systems%3A+Blogs&amp;rft_id=http%3A%2F%2Fwww.azulsystems.com%2Fblog%2Fcliff%2F2011-04-04-fixing-the-inlining-problem&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-37"><span class="mw-cite-backlink"><b><a href="#cite_ref-37">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://java.sun.com/performance/reference/whitepapers/6_performance.html#2.1.2">Oracle Technology Network for Java Developers</a></span> </li> <li id="cite_note-38"><span class="mw-cite-backlink"><b><a href="#cite_ref-38">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf">"Working Draft, Standard for Programming Language C++"</a> <span class="cs1-format">(PDF)</span>. <a rel="nofollow" class="external text" href="https://ghostarchive.org/archive/20221009/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf">Archived</a> <span class="cs1-format">(PDF)</span> from the original on 9 October 2022.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Working+Draft%2C+Standard+for+Programming+Language+C%2B%2B&amp;rft_id=http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2012%2Fn3337.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></span> </li> <li id="cite_note-39"><span class="mw-cite-backlink"><b><a href="#cite_ref-39">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://java.sun.com/docs/books/jls/">The Java Language Specification</a></span> </li> <li id="cite_note-40"><span class="mw-cite-backlink"><b><a href="#cite_ref-40">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.jcp.org/en/participation/members">The Java Community Process(SM) Program - Participation - JCP Members</a></span> </li> <li id="cite_note-41"><span class="mw-cite-backlink"><b><a href="#cite_ref-41">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.stroustrup.com/bs_faq.html#revenues">Bjarne Stroustrup's FAQ: Do you own C++?</a></span> </li> <li id="cite_note-42"><span class="mw-cite-backlink"><b><a href="#cite_ref-42">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://blogs.zdnet.com/BTL/?p=16598">ZDNet: Oracle buys Sun; Now owns Java</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20100410145901/http://blogs.zdnet.com/BTL/?p=16598">Archived</a> 10 April 2010 at the <a href="/wiki/Wayback_Machine" title="Wayback Machine">Wayback Machine</a>.</span> </li> </ol></div></div> <div class="mw-heading mw-heading3"><h3 id="Sources">Sources</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=16" title="Edit section: Sources"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFBloch2018" class="citation book cs1">Bloch, Joshua (2018). <i>"Effective Java: Programming Language Guide"</i> (third&#160;ed.). Addison-Wesley. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0134685991" title="Special:BookSources/978-0134685991"><bdi>978-0134685991</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=%22Effective+Java%3A+Programming+Language+Guide%22&amp;rft.edition=third&amp;rft.pub=Addison-Wesley&amp;rft.date=2018&amp;rft.isbn=978-0134685991&amp;rft.aulast=Bloch&amp;rft.aufirst=Joshua&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFGoetzPeierlsBlochBowbeer2006" class="citation book cs1">Goetz, Brian; Peierls, Tim; Bloch, Joshua; Bowbeer, Joseph; Holmes, David; Lea, Doug (2006). <a rel="nofollow" class="external text" href="https://archive.org/details/javaconcurrencyi00goet"><i>Java Concurrency in Practice</i></a>. Addison Wesley. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/0-321-34960-1" title="Special:BookSources/0-321-34960-1"><bdi>0-321-34960-1</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Java+Concurrency+in+Practice&amp;rft.pub=Addison+Wesley&amp;rft.date=2006&amp;rft.isbn=0-321-34960-1&amp;rft.aulast=Goetz&amp;rft.aufirst=Brian&amp;rft.au=Peierls%2C+Tim&amp;rft.au=Bloch%2C+Joshua&amp;rft.au=Bowbeer%2C+Joseph&amp;rft.au=Holmes%2C+David&amp;rft.au=Lea%2C+Doug&amp;rft_id=https%3A%2F%2Farchive.org%2Fdetails%2Fjavaconcurrencyi00goet&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AComparison+of+Java+and+C%2B%2B" class="Z3988"></span></li></ul> <p><br /> </p><p><br /> </p> <div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;action=edit&amp;section=17" title="Edit section: External links"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1235681985">.mw-parser-output .side-box{margin:4px 0;box-sizing:border-box;border:1px solid #aaa;font-size:88%;line-height:1.25em;background-color:var(--background-color-interactive-subtle,#f8f9fa);display:flow-root}.mw-parser-output .side-box-abovebelow,.mw-parser-output .side-box-text{padding:0.25em 0.9em}.mw-parser-output .side-box-image{padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .side-box-imageright{padding:2px 0.9em 2px 0;text-align:center}@media(min-width:500px){.mw-parser-output .side-box-flex{display:flex;align-items:center}.mw-parser-output .side-box-text{flex:1;min-width:0}}@media(min-width:720px){.mw-parser-output .side-box{width:238px}.mw-parser-output .side-box-right{clear:right;float:right;margin-left:1em}.mw-parser-output .side-box-left{margin-right:1em}}</style><style data-mw-deduplicate="TemplateStyles:r1237033735">@media print{body.ns-0 .mw-parser-output .sistersitebox{display:none!important}}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}</style><div class="side-box side-box-right plainlinks sistersitebox"><style data-mw-deduplicate="TemplateStyles:r1126788409">.mw-parser-output .plainlist ol,.mw-parser-output .plainlist ul{line-height:inherit;list-style:none;margin:0;padding:0}.mw-parser-output .plainlist ol li,.mw-parser-output .plainlist ul li{margin-bottom:0}</style> <div class="side-box-flex"> <div class="side-box-image"><span class="noviewer" typeof="mw:File"><span><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/40px-Wikibooks-logo-en-noslogan.svg.png" decoding="async" width="40" height="40" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/60px-Wikibooks-logo-en-noslogan.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/80px-Wikibooks-logo-en-noslogan.svg.png 2x" data-file-width="400" data-file-height="400" /></span></span></div> <div class="side-box-text plainlist">The Wikibook <i><a href="https://en.wikibooks.org/wiki/C%2B%2B_Programming" class="extiw" title="wikibooks:C++ Programming">C++ Programming</a></i> has a page on the topic of: <i><b><a href="https://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/Comparisons/Java" class="extiw" title="wikibooks:C++ Programming/Programming Languages/Comparisons/Java">Programming Languages/Comparisons/Java</a></b></i></div></div> </div> <ul><li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20180921225953/https://decodediary.com/2018/09/20/difference-between-c-and-java/">Difference Between C++ and Java</a></li> <li><a rel="nofollow" class="external text" href="http://ineed.coffee/98/object-oriented-memory-management">Object Oriented Memory Management: Java vs. C++</a></li> <li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20020402093228/http://www.ora.com/catalog/javanut/excerpt/index.html">Chapter 2:How Java Differs from C</a>, chapter from Java in a Nutshell by David Flanagan</li> <li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20070523171523/http://www.fatalmind.com/papers/java_vs_cplusplus/resource.html">Java vs. C++ resource management comparison</a> - Comprehensive paper with examples</li> <li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20100630201919/http://www.azulsystems.com/blog/cliff-click/2009-09-06-java-vs-c-performanceagain">Java vs C performance... again...</a> - In-depth discussion of performance differences between Java and C/C++</li> <li><a rel="nofollow" class="external text" href="http://christianrubiales.com/hyperpoly/?q=java,cpp">Hyperpoly - Java and C++ Comparison</a></li></ul> <div class="navbox-styles"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><style data-mw-deduplicate="TemplateStyles:r1236075235">.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}</style></div><div role="navigation" class="navbox" aria-labelledby="C++" style="padding:3px"><table class="nowraplinks hlist mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1239400231"><div class="navbar plainlinks hlist navbar-mini"><ul><li class="nv-view"><a href="/wiki/Template:C%2B%2B_programming_language" title="Template:C++ programming language"><abbr title="View this template">v</abbr></a></li><li class="nv-talk"><a href="/wiki/Template_talk:C%2B%2B_programming_language" title="Template talk:C++ programming language"><abbr title="Discuss this template">t</abbr></a></li><li class="nv-edit"><a href="/wiki/Special:EditPage/Template:C%2B%2B_programming_language" title="Special:EditPage/Template:C++ programming language"><abbr title="Edit this template">e</abbr></a></li></ul></div><div id="C++" style="font-size:114%;margin:0 4em"><a href="/wiki/C%2B%2B" title="C++">C++</a></div></th></tr><tr><td class="navbox-abovebelow" colspan="2"><div> <ul><li><a href="/wiki/C%2B%2B" title="C++">C++</a></li> <li><a href="/wiki/Outline_of_C%2B%2B" title="Outline of C++">Outline</a></li> <li><a href="/wiki/C%2B%2B#Standardization" title="C++">C++98</a></li> <li><a href="/wiki/C%2B%2B03" title="C++03">C++03</a></li> <li><a href="/wiki/C%2B%2B11" title="C++11">C++11</a></li> <li><a href="/wiki/C%2B%2B14" title="C++14">C++14</a></li> <li><a href="/wiki/C%2B%2B17" title="C++17">C++17</a></li> <li><a href="/wiki/C%2B%2B20" title="C++20">C++20</a></li> <li><a href="/wiki/C%2B%2B23" title="C++23">C++23</a></li> <li><a href="/wiki/C%2B%2B26" title="C++26">C++26</a></li> <li><a href="/wiki/Category:C%2B%2B_libraries" title="Category:C++ libraries">Libraries</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Features</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/C%2B%2B_classes" title="C++ classes">Classes</a></li> <li><a href="/wiki/Concepts_(C%2B%2B)" title="Concepts (C++)">Concepts</a></li> <li><a href="/wiki/Copy_constructor_(C%2B%2B)" title="Copy constructor (C++)">Copy constructor</a></li> <li><a href="/wiki/C%2B%2B#Exception_handling" title="C++">Exception handling</a> (<a href="/wiki/Exception_safety" title="Exception safety">Exception safety</a>)</li> <li><a href="/wiki/Function_overloading" title="Function overloading">Function overloading</a></li> <li><a href="/wiki/C%2B%2B11#Rvalue_references_and_move_constructors" title="C++11">Move semantics</a></li> <li><a href="/wiki/New_and_delete_(C%2B%2B)" title="New and delete (C++)">new and delete</a></li> <li><a href="/wiki/Operator_overloading" title="Operator overloading">Operator overloading</a></li> <li><a href="/wiki/Operators_in_C_and_C%2B%2B" title="Operators in C and C++">Operators</a></li> <li><a href="/wiki/Reference_(C%2B%2B)" title="Reference (C++)">References</a></li> <li><a href="/wiki/Template_(C%2B%2B)" title="Template (C++)">Templates</a></li> <li><a href="/wiki/Virtual_function" title="Virtual function">Virtual functions</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/C%2B%2B_Standard_Library" title="C++ Standard Library">Standard Library</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Input/output_(C%2B%2B)" title="Input/output (C++)">I/O Streams</a></li> <li><a href="/wiki/Smart_pointer" title="Smart pointer">Smart pointers</a></li> <li><a href="/wiki/Standard_Template_Library" title="Standard Template Library">STL</a></li> <li><a href="/wiki/C%2B%2B_string_handling" title="C++ string handling">Strings</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Ideas</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/As-if_rule" title="As-if rule">As-if rule</a></li> <li><a href="/wiki/Barton%E2%80%93Nackman_trick" title="Barton–Nackman trick">Barton–Nackman trick</a></li> <li><a href="/wiki/Curiously_recurring_template_pattern" title="Curiously recurring template pattern">Curiously recurring template pattern</a></li> <li><a href="/wiki/Most_vexing_parse" title="Most vexing parse">Most vexing parse</a></li> <li><a href="/wiki/One_Definition_Rule" title="One Definition Rule">One Definition Rule</a></li> <li><a href="/wiki/Resource_acquisition_is_initialization" title="Resource acquisition is initialization">Resource acquisition is initialization</a></li> <li><a href="/wiki/Rule_of_three_(C%2B%2B_programming)" title="Rule of three (C++ programming)">Rule of three</a></li> <li><a href="/wiki/Object_slicing" title="Object slicing">Slicing</a></li> <li><a href="/wiki/Special_member_functions" title="Special member functions">Special member functions</a></li> <li><a href="/wiki/Substitution_failure_is_not_an_error" title="Substitution failure is not an error">Substitution failure is not an error</a></li> <li><a href="/wiki/Template_metaprogramming" title="Template metaprogramming">Template metaprogramming</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Category:C%2B%2B_compilers" title="Category:C++ compilers">Compilers</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/List_of_compilers#C++_compilers" title="List of compilers">Comparison of C++ compilers</a></li> <li><a href="/wiki/Borland_C%2B%2B" title="Borland C++">Borland C++</a></li> <li><a href="/wiki/Borland_C%2B%2B" title="Borland C++">Borland Turbo C++</a></li> <li><a href="/wiki/C%2B%2BBuilder" title="C++Builder">C++Builder</a></li> <li><a href="/wiki/Clang" title="Clang">Clang</a></li> <li><a href="/wiki/GNU_Compiler_Collection" title="GNU Compiler Collection">GCC</a></li> <li><a href="/wiki/Intel_C%2B%2B_Compiler" title="Intel C++ Compiler">Intel C++ Compiler</a></li> <li><a href="/wiki/Oracle_Developer_Studio" title="Oracle Developer Studio">Oracle Solaris Studio</a></li> <li><a href="/wiki/Visual_C%2B%2B" class="mw-redirect" title="Visual C++">Visual C++</a></li> <li><a href="/wiki/Watcom_C/C%2B%2B" title="Watcom C/C++">Watcom C/C++</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Category:Integrated_development_environments" title="Category:Integrated development environments">IDEs</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Comparison_of_integrated_development_environments#C/C++" title="Comparison of integrated development environments">Comparison of C IDEs</a></li> <li><a href="/wiki/Anjuta" title="Anjuta">Anjuta</a></li> <li><a href="/wiki/CLion" class="mw-redirect" title="CLion">CLion</a></li> <li><a href="/wiki/Code::Blocks" title="Code::Blocks">Code::Blocks</a></li> <li><a href="/wiki/CodeLite" title="CodeLite">CodeLite</a></li> <li><a href="/wiki/Dev-C%2B%2B" title="Dev-C++">Dev-C++</a></li> <li><a href="/wiki/Eclipse_(software)" title="Eclipse (software)">Eclipse</a></li> <li><a href="/wiki/Geany" title="Geany">Geany</a></li> <li><a href="/wiki/NetBeans" title="NetBeans">NetBeans</a></li> <li><a href="/wiki/KDevelop" title="KDevelop">KDevelop</a></li> <li><a href="/wiki/Qt_Creator" title="Qt Creator">Qt Creator</a></li> <li><a href="/wiki/Visual_Studio" title="Visual Studio">Visual Studio</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Superset languages</th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Objective-C%2B%2B" class="mw-redirect" title="Objective-C++">Objective-C++</a></li> <li><a href="/wiki/C%2B%2B/CLI" title="C++/CLI">C++/CLI</a></li> <li><a href="/wiki/C%2B%2B/CX" title="C++/CX">C++/CX</a></li> <li><a href="/wiki/C%2B%2B/WinRT" title="C++/WinRT">C++/WinRT</a></li> <li><a href="/wiki/Ch_(computer_programming)" title="Ch (computer programming)">Ch</a></li> <li><a href="/wiki/SYCL" title="SYCL">SYCL</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Dialects</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Embedded_C%2B%2B" title="Embedded C++">Embedded C++</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Relative to<br />other languages</th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Comparison_of_programming_languages" title="Comparison of programming languages">Comparison of programming languages</a></li> <li><a class="mw-selflink selflink">Comparison of Java and C++</a></li> <li><a href="/wiki/Comparison_of_ALGOL_68_and_C%2B%2B" title="Comparison of ALGOL 68 and C++">Comparison of ALGOL 68 and C++</a></li> <li><a href="/wiki/Compatibility_of_C_and_C%2B%2B" title="Compatibility of C and C++">Compatibility of C and C++</a></li> <li><a href="/wiki/Criticism_of_C%2B%2B" title="Criticism of C++">Criticism of C++</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Software_development" title="Software development">Designer</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Bjarne_Stroustrup" title="Bjarne Stroustrup">Bjarne Stroustrup</a></li></ul> </div></td></tr><tr><td class="navbox-abovebelow" colspan="2"><div><span class="noviewer" typeof="mw:File"><span title="Category"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/16px-Symbol_category_class.svg.png" decoding="async" width="16" height="16" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/23px-Symbol_category_class.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/31px-Symbol_category_class.svg.png 2x" data-file-width="180" data-file-height="185" /></span></span> <b><a href="/wiki/Category:C%2B%2B_programming_language_family" title="Category:C++ programming language family">Category</a></b></div></td></tr></tbody></table></div> <!-- NewPP limit report Parsed by mw‐api‐ext.codfw.main‐6f5cb46759‐gwsbt Cached time: 20241125222450 Cache expiry: 2592000 Reduced expiry: false Complications: [vary‐revision‐sha1, show‐toc] CPU time usage: 0.780 seconds Real time usage: 0.964 seconds Preprocessor visited node count: 4898/1000000 Post‐expand include size: 128643/2097152 bytes Template argument size: 14729/2097152 bytes Highest expansion depth: 13/100 Expensive parser function count: 45/500 Unstrip recursion depth: 1/20 Unstrip post‐expand size: 152636/5000000 bytes Lua time usage: 0.477/10.000 seconds Lua memory usage: 7588085/52428800 bytes Number of Wikibase entities loaded: 0/400 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 808.915 1 -total 26.37% 213.351 1 Template:Reflist 17.86% 144.486 17 Template:Cite_web 16.11% 130.343 35 Template:Sfn 12.45% 100.733 1 Template:ProgLangCompare 12.11% 97.936 1 Template:Sidebar 10.75% 86.938 1 Template:Short_description 9.94% 80.399 1 Template:Multiple_issues 7.30% 59.060 2 Template:Pagetype 6.39% 51.686 4 Template:Ambox --> <!-- Saved in parser cache with key enwiki:pcache:idhash:42922-0!canonical and timestamp 20241125222451 and revision id 1259576150. Rendering was triggered because: edit-page --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://en.wikipedia.org/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;oldid=1259576150">https://en.wikipedia.org/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;oldid=1259576150</a>"</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Help:Category" title="Help:Category">Categories</a>: <ul><li><a href="/wiki/Category:Comparison_of_individual_programming_languages" title="Category:Comparison of individual programming languages">Comparison of individual programming languages</a></li><li><a href="/wiki/Category:Java_(programming_language)" title="Category:Java (programming language)">Java (programming language)</a></li><li><a href="/wiki/Category:C%2B%2B" title="Category:C++">C++</a></li></ul></div><div id="mw-hidden-catlinks" class="mw-hidden-catlinks mw-hidden-cats-hidden">Hidden categories: <ul><li><a href="/wiki/Category:Webarchive_template_wayback_links" title="Category:Webarchive template wayback links">Webarchive template wayback links</a></li><li><a href="/wiki/Category:Articles_with_short_description" title="Category:Articles with short description">Articles with short description</a></li><li><a href="/wiki/Category:Short_description_is_different_from_Wikidata" title="Category:Short description is different from Wikidata">Short description is different from Wikidata</a></li><li><a href="/wiki/Category:Articles_needing_more_viewpoints_from_May_2016" title="Category:Articles needing more viewpoints from May 2016">Articles needing more viewpoints from May 2016</a></li><li><a href="/wiki/Category:Articles_with_self-published_sources_from_September_2010" title="Category:Articles with self-published sources from September 2010">Articles with self-published sources from September 2010</a></li><li><a href="/wiki/Category:All_articles_with_self-published_sources" title="Category:All articles with self-published sources">All articles with self-published sources</a></li><li><a href="/wiki/Category:Articles_that_may_contain_original_research_from_August_2012" title="Category:Articles that may contain original research from August 2012">Articles that may contain original research from August 2012</a></li><li><a href="/wiki/Category:All_articles_that_may_contain_original_research" title="Category:All articles that may contain original research">All articles that may contain original research</a></li><li><a href="/wiki/Category:Articles_with_multiple_maintenance_issues" title="Category:Articles with multiple maintenance issues">Articles with multiple maintenance issues</a></li><li><a href="/wiki/Category:Use_dmy_dates_from_January_2021" title="Category:Use dmy dates from January 2021">Use dmy dates from January 2021</a></li><li><a href="/wiki/Category:Articles_needing_additional_references_from_September_2010" title="Category:Articles needing additional references from September 2010">Articles needing additional references from September 2010</a></li><li><a href="/wiki/Category:All_articles_needing_additional_references" title="Category:All articles needing additional references">All articles needing additional references</a></li><li><a href="/wiki/Category:All_articles_with_specifically_marked_weasel-worded_phrases" title="Category:All articles with specifically marked weasel-worded phrases">All articles with specifically marked weasel-worded phrases</a></li><li><a href="/wiki/Category:Articles_with_specifically_marked_weasel-worded_phrases_from_March_2012" title="Category:Articles with specifically marked weasel-worded phrases from March 2012">Articles with specifically marked weasel-worded phrases from March 2012</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> This page was last edited on 25 November 2024, at 22:24<span class="anonymous-show">&#160;(UTC)</span>.</li> <li id="footer-info-copyright">Text is available under the <a href="/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License" title="Wikipedia:Text of the Creative Commons Attribution-ShareAlike 4.0 International License">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use" class="extiw" title="foundation:Special:MyLanguage/Policy:Terms of Use">Terms of Use</a> and <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy" class="extiw" title="foundation:Special:MyLanguage/Policy:Privacy policy">Privacy Policy</a>. Wikipedia® is a registered trademark of the <a rel="nofollow" class="external text" href="https://wikimediafoundation.org/">Wikimedia Foundation, Inc.</a>, a non-profit organization.</li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li> <li id="footer-places-about"><a href="/wiki/Wikipedia:About">About Wikipedia</a></li> <li id="footer-places-disclaimers"><a href="/wiki/Wikipedia:General_disclaimer">Disclaimers</a></li> <li id="footer-places-contact"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us">Contact Wikipedia</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct">Code of Conduct</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/en.wikipedia.org">Statistics</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li> <li id="footer-places-mobileview"><a href="//en.m.wikipedia.org/w/index.php?title=Comparison_of_Java_and_C%2B%2B&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li> </ul> </footer> </div> </div> </div> <div class="vector-settings" id="p-dock-bottom"> <ul></ul> </div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.main-694cf4987f-t89nq","wgBackendResponseTime":187,"wgPageParseReport":{"limitreport":{"cputime":"0.780","walltime":"0.964","ppvisitednodes":{"value":4898,"limit":1000000},"postexpandincludesize":{"value":128643,"limit":2097152},"templateargumentsize":{"value":14729,"limit":2097152},"expansiondepth":{"value":13,"limit":100},"expensivefunctioncount":{"value":45,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":152636,"limit":5000000},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 808.915 1 -total"," 26.37% 213.351 1 Template:Reflist"," 17.86% 144.486 17 Template:Cite_web"," 16.11% 130.343 35 Template:Sfn"," 12.45% 100.733 1 Template:ProgLangCompare"," 12.11% 97.936 1 Template:Sidebar"," 10.75% 86.938 1 Template:Short_description"," 9.94% 80.399 1 Template:Multiple_issues"," 7.30% 59.060 2 Template:Pagetype"," 6.39% 51.686 4 Template:Ambox"]},"scribunto":{"limitreport-timeusage":{"value":"0.477","limit":"10.000"},"limitreport-memusage":{"value":7588085,"limit":52428800},"limitreport-logs":"anchor_id_list = table#1 {\n [\"CITEREFAlexandrescu2001\"] = 1,\n [\"CITEREFBloch2018\"] = 1,\n [\"CITEREFClarkAmir_HormatiSami_YehiaScott_Mahlke2007\"] = 1,\n [\"CITEREFDeitelDeitel2009\"] = 1,\n [\"CITEREFGoetzPeierlsBlochBowbeer2006\"] = 1,\n [\"CITEREFHorstmannCornell2008\"] = 1,\n [\"CITEREFHundt2011\"] = 1,\n [\"CITEREFMatthew_Hertz,_Emery_D._Berger2005\"] = 1,\n [\"CITEREFRobert_C._Martin1997\"] = 1,\n [\"CITEREFSatish_Chandra_GuptaRajeev_Palanki2005\"] = 1,\n}\ntemplate_list = table#1 {\n [\"!\"] = 1,\n [\"C++ programming language\"] = 1,\n [\"Cite book\"] = 5,\n [\"Cite journal\"] = 1,\n [\"Cite web\"] = 17,\n [\"Code\"] = 1,\n [\"DEFAULTSORT:Comparison Of Java And C Plus Plus\"] = 1,\n [\"More citations needed section\"] = 1,\n [\"Multiple issues\"] = 1,\n [\"Original research\"] = 1,\n [\"Pre\"] = 1,\n [\"ProgLangCompare\"] = 1,\n [\"Reflist\"] = 1,\n [\"See also\"] = 1,\n [\"Self-published\"] = 1,\n [\"Sfn\"] = 35,\n [\"Short description\"] = 1,\n [\"Sxhl\"] = 1,\n [\"Unbalanced\"] = 1,\n [\"Use dmy dates\"] = 1,\n [\"Weasel inline\"] = 1,\n [\"Webarchive\"] = 1,\n [\"Wikibooks\"] = 1,\n}\narticle_whitelist = table#1 {\n}\n"},"cachereport":{"origin":"mw-api-ext.codfw.main-6f5cb46759-gwsbt","timestamp":"20241125222450","ttl":2592000,"transientcontent":false}}});});</script> <script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"Comparison of Java and C++","url":"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_Java_and_C%2B%2B","sameAs":"http:\/\/www.wikidata.org\/entity\/Q907151","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q907151","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2002-03-05T09:12:26Z","dateModified":"2024-11-25T22:24:49Z","headline":"comparison between two coding languages"}</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10