{"id":347,"date":"2021-01-04T15:16:14","date_gmt":"2021-01-04T15:16:14","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/?page_id=347"},"modified":"2021-01-04T15:23:37","modified_gmt":"2021-01-04T15:23:37","slug":"operators","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/operators\/","title":{"rendered":"Operators"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a06ee0b07758\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a06ee0b07758\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/operators\/#The_Java_Operators\" >The Java Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/operators\/#Differences_from_CC\" >Differences from C\/C++<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>The Java operators are based on those of C\/C++, with some additions and modifications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Java_Operators\"><\/span>The Java Operators<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here are the&nbsp;<em>operators<\/em>&nbsp;in Java.<\/p>\n\n\n\n<p>The&nbsp;<em>precedence<\/em>&nbsp;and&nbsp;<em>associativity<\/em>&nbsp;are essentially the same as in C\/C++.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Precedence<\/th><th>Operator<\/th><th>Operand<br>Types<\/th><th>Associativity<\/th><th>Operation<\/th><\/tr><\/thead><tbody><tr><td>1<br>(Highest)<\/td><td><strong>++<br>&#8212;<br>+<br>&#8211;<br>~<br>!<br>(type)<\/strong><\/td><td>arithmetic<br>arithmetic<br>arithmetic<br>arithmetic<br>integral<br>boolean<br>any<\/td><td>Right-to-Left<\/td><td>pre- or post- increment<br>pre- or post- decrement<br>unary plus<br>unary minus<br>bitwise complement (unary)<br>logical complement (unary)<br>cast<\/td><\/tr><tr><td>2<\/td><td><strong>*<br>\/<br>%<\/strong><\/td><td>arithmetic<br>arithmetic<br>arithmetic<\/td><td>Left-to-Right<\/td><td>multiplication<br>division<br>remainder (modulus)<\/td><\/tr><tr><td>3<\/td><td><strong>+<br>&#8211;<br>+<\/strong><\/td><td>arithmetic<br>arithmetic<br>string<\/td><td>Left-to-Right<\/td><td>addition<br>subtraction<br>string concatenation<\/td><\/tr><tr><td>4<\/td><td><strong>&lt;&lt;<br>&gt;&gt;<br>&gt;&gt;&gt;<\/strong><\/td><td>integral<br>integral<br>integral<\/td><td>Left-to-Right<\/td><td>left shift<br>right shift with sign extension<br>right shift with zero extension<\/td><\/tr><tr><td>5<\/td><td><strong>&lt;<br>&lt;=<br>&gt;<br>&gt;=<br><br>instanceof<\/strong><\/td><td>arithmetic<br>arithmetic<br>arithmetic<br>arithmetic<br><br>object, type<\/td><td>Left-to-Right<\/td><td>less than<br>less then or equal<br>greater than<br>greater than or equal<br><br>type comparison<\/td><\/tr><tr><td>6<\/td><td><strong>==<br>!=<br><br>==<br>!=<\/strong><\/td><td>primitive<br>primitive<br><br>object<br>object<\/td><td>Left-to-Right<\/td><td>equal (have identical values)<br>not equal (have different values)<br><br>equal (refer to same obect)<br>not equal (refer to different objects)<\/td><\/tr><tr><td>7<\/td><td><strong>&amp;<br>&amp;<\/strong><\/td><td>integral<br>boolean<\/td><td>Left-to-Right<\/td><td>bitwise AND<br>boolean AND<\/td><\/tr><tr><td>8<\/td><td><strong>^<br>^<\/strong><\/td><td>integral<br>boolean<\/td><td>Left-to-Right<\/td><td>bitwise XOR<br>boolean XOR<\/td><\/tr><tr><td>9<\/td><td><strong>|<br>|<\/strong><\/td><td>integral<br>boolean<\/td><td>Left-to-Right<\/td><td>bitwise OR<br>boolean OR<\/td><\/tr><tr><td>10<\/td><td><strong>&amp;&amp;<\/strong><\/td><td>boolean<\/td><td>Left-to-Right<\/td><td>conditional AND<\/td><\/tr><tr><td>11<\/td><td><strong>||<\/strong><\/td><td>boolean<\/td><td>Left-to-Right<\/td><td>conditional OR<\/td><\/tr><tr><td>12<\/td><td><strong>?:<\/strong><\/td><td>boolean, any, any<\/td><td>Right-to-Left<\/td><td>conditional (ternary) operator<\/td><\/tr><tr><td>13<br>(Lowest)<\/td><td><strong>=<br>*=<br>\/=<br>%=<br>+=<br>-=<br>&lt;&lt;=<br>&gt;&gt;=<br>&gt;&gt;&gt;=<br>&amp;=<br>^=<br>|=<\/strong><\/td><td>variable, any<\/td><td>Right-to-Left<\/td><td>assignment<br><br>assignment with operation<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Differences_from_CC\"><\/span>Differences from C\/C++<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here are some ways in which Java operators differ from those of C and C++:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Java<\/th><th>C &amp; C++<\/th><th>Comments<\/th><\/tr><\/thead><tbody><tr><td>No comma operator<\/td><td>Support comma operator<\/td><td>Java&#8217;s&nbsp;<strong><code>for<\/code><\/strong>&nbsp;statement supports a useful syntax, as in C\/C++<\/td><\/tr><tr><td>No reference or dereference operators (<strong>*<\/strong>,<strong>&nbsp;-&gt;&nbsp;<\/strong>and<strong>&nbsp;&amp;<\/strong>)<\/td><td>Support reference and dereference operators.<\/td><td>Java has no pointers.<\/td><\/tr><tr><td>No&nbsp;<strong>sizeof&nbsp;<\/strong>operator<\/td><td>Support&nbsp;<strong>sizeof&nbsp;<\/strong>operator<\/td><td>Java doesn&#8217;t need it for portability<\/td><\/tr><tr><td>Doesn&#8217;t consider&nbsp;<strong>[]<\/strong>&nbsp;and&nbsp;<strong>.&nbsp;<\/strong>to be operators<\/td><td>Consider&nbsp;<strong>[]&nbsp;<\/strong>and&nbsp;<strong>.&nbsp;<\/strong>to be operators<\/td><td>&nbsp;<\/td><\/tr><tr><td>The&nbsp;<strong>+&nbsp;<\/strong>operator applied to Strings concatenates them.<\/td><td>&nbsp;<\/td><td>In Java, conversion is performed automatically for primitive types, and by calling the&nbsp;<strong>toString()<\/strong>&nbsp;method for non-primitive types.<\/td><\/tr><tr><td>Supports&nbsp;<strong>instanceof&nbsp;<\/strong>operator<\/td><td>C++ has&nbsp;<strong>typeid&nbsp;<\/strong>operator<\/td><td>Tests whether an object is an instance of a class or whether it implements an interface.<\/td><\/tr><tr><td>Supports&nbsp;<strong>&gt;&gt;&gt;&nbsp;<\/strong>operator<\/td><td>&nbsp;<\/td><td>Right-shifts with zero extension.<\/td><\/tr><tr><td>Supports variety of &amp;, | and ^ operators, depending on operand type.<\/td><td>&nbsp;<\/td><td>Operators perform bitwise operations on integral values, but boolean operations on boolean values.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>The Java operators are based on those of C\/C++, with some additions and modifications. The Java Operators Here are the&nbsp;operators&nbsp;in Java. The&nbsp;precedence&nbsp;and&nbsp;associativity&nbsp;are essentially the same as in C\/C++. PrecedenceOperatorOperandTypesAssociativityOperation1(Highest)++&#8212;+&#8211;~!(type)arithmeticarithmeticarithmeticarithmeticintegralbooleananyRight-to-Leftpre- or post- incrementpre- or post- decrementunary plusunary minusbitwise complement (unary)logical complement (unary)cast2*\/%arithmeticarithmeticarithmeticLeft-to-Rightmultiplicationdivisionremainder (modulus)3+&#8211;+arithmeticarithmeticstringLeft-to-Rightadditionsubtractionstring concatenation4&lt;&lt;&gt;&gt;&gt;&gt;&gt;integralintegralintegralLeft-to-Rightleft shiftright shift with sign extensionright shift with zero extension5&lt;&lt;=&gt;&gt;=instanceofarithmeticarithmeticarithmeticarithmeticobject, typeLeft-to-Rightless thanless then [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":34,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","_uag_custom_page_level_css":"","ocean_post_layout":"left-sidebar","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"ocs-course-topics-sidebar","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","footnotes":""},"class_list":["post-347","page","type-page","status-publish","hentry","entry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"ocean-thumb-m":false,"ocean-thumb-ml":false,"ocean-thumb-l":false},"uagb_author_info":{"display_name":"Bryan Higgs","author_link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/author\/bryan\/"},"uagb_comment_info":0,"uagb_excerpt":"The Java operators are based on those of C\/C++, with some additions and modifications. The Java Operators Here are the&nbsp;operators&nbsp;in Java. The&nbsp;precedence&nbsp;and&nbsp;associativity&nbsp;are essentially the same as in C\/C++. Precedence Operator OperandTypes Associativity Operation 1(Highest) ++&#8212;+&#8211;~!(type) arithmeticarithmeticarithmeticarithmeticintegralbooleanany Right-to-Left pre- or post- incrementpre- or post- decrementunary plusunary minusbitwise complement (unary)logical complement (unary)cast 2 *\/% arithmeticarithmeticarithmetic Left-to-Right multiplicationdivisionremainder&hellip;","_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/comments?post=347"}],"version-history":[{"count":4,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/347\/revisions"}],"predecessor-version":[{"id":352,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/347\/revisions\/352"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/34"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/media?parent=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}