<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yousuf Ibrahim Gani</title>
    <description>The latest articles on DEV Community by Yousuf Ibrahim Gani (@yousufibrahim28).</description>
    <link>https://dev.to/yousufibrahim28</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1098617%2Fa38310cf-ab0d-469a-8e5b-1955836279ec.png</url>
      <title>DEV Community: Yousuf Ibrahim Gani</title>
      <link>https://dev.to/yousufibrahim28</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yousufibrahim28"/>
    <language>en</language>
    <item>
      <title>What happens when you add 1 to Integer.MAX_VALUE in Java?</title>
      <dc:creator>Yousuf Ibrahim Gani</dc:creator>
      <pubDate>Fri, 09 Jun 2023 21:28:12 +0000</pubDate>
      <link>https://dev.to/yousufibrahim28/what-happens-when-you-add-1-to-integermaxvalue-in-java-3e40</link>
      <guid>https://dev.to/yousufibrahim28/what-happens-when-you-add-1-to-integermaxvalue-in-java-3e40</guid>
      <description>&lt;p&gt;Integer.MAX_VALUE + 1;&lt;/p&gt;

&lt;p&gt;Does it throw an exception? Like a Numeric overflow exception &lt;/p&gt;

&lt;p&gt;This is pretty interesting when I first got to know about it.&lt;/p&gt;

&lt;p&gt;The answer is it doesn’t throw any exception, compile time or runtime.&lt;/p&gt;

&lt;p&gt;It gives you an answer and that will be Integer.MIN_VALUE&lt;/p&gt;

&lt;p&gt;Integer.MAX_VALUE + 1 = Integer.MIN_VALUE;&lt;/p&gt;

&lt;p&gt;Yes, you read it right. This happens because of the reason that Java represents the numbers in binary format and uses a Two’s complement representation while doing any operations on the number like addition, subtraction etc. &lt;/p&gt;

&lt;p&gt;In Two’s complement form, the leftmost digit in binary indicates the sign, 0 is positive and 1 is Negative&lt;/p&gt;

&lt;p&gt;Integer.MAX_VALUE = 2147483647 = 01111111111111111111111111111111&lt;/p&gt;

&lt;p&gt; Integer.MIN_VALUE = -2147483648 = 10000000000000000000000000000000&lt;/p&gt;

&lt;p&gt;So when you add &lt;/p&gt;

&lt;p&gt;01111111111111111111111111111111 + 00000000000000000000000000000001 = 10000000000000000000000000000000&lt;/p&gt;

&lt;p&gt;Learn more about it here: &lt;a href="https://lnkd.in/ga8Q29u9"&gt;https://lnkd.in/ga8Q29u9&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is school mathematics that we usually never give any importance to, but this is one of the concepts that is responsible for thousands of software running successfully, which are the engines for many successful organizations.&lt;/p&gt;

&lt;p&gt;Next time when you use Integers in Java and perform any operation, you will know what happens under the hood. &lt;/p&gt;

&lt;h1&gt;
  
  
  java #software #mathematics #concepts #learnings
&lt;/h1&gt;

</description>
    </item>
  </channel>
</rss>
