Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:00:49+00:00 2026-05-30T09:00:49+00:00

I know this question has been partly answered here on S.O. , but there

  • 0

I know this question has been partly answered here on S.O., but there they explain what happens during an arithmetic overflow. And elsewhere on S.O. they explain how to check for overflow in java code, i.e. to prevent it as a programmer.

Here I am asking why there are no exceptions at run-time, and no compiler warnings?

AFAIK, this has not been answered before.

In Bruce Eckel’s book Thinking in Java, 1st ed. (2000), Chapter 3, there is this little java program:

//: Overflow.java
// Surprise! Java lets you overflow.
public class Overflow {
      public static void main(String[] args) {
        int big = 0x7fffffff; // max int value
        prt("big = " + big);
        int bigger = big * 4;
        prt("bigger = " + bigger);
      }
      static void prt(String s) {
        System.out.println(s);
      }
} ///:~

The output of this is:

big = 2147483647
bigger = -4

and you get no errors or warnings from the compiler, and no exceptions
at run-time.

No change when Integer.MAX_VALUE is used instead of “0x7fffffff”

I have tried this on some java compilers from 1.2 to 1.6, and it still shows this behaviour. I now wonder why this is so?

  • Is this a bug or feature?
  • Is this impossible to detect, or a low-priority issue for compiler designers?
  • Is this not fixed because of backward compatibility?
  • Maybe in newer releases of the JDK, can this be controlled at compile time by enabling some rarely used compiler switch/-D:property, or some java VM argument (-XX:…)?

Just now I used these VMs, Windows x86 32 bit

Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

and

Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)

By the way, C# (Microsoft.CSharp\v4.0_4.0.0.0) shows the same behaviour

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OverflowCheck
{
    class Overflow
    {
        static void Main(string[] args)
        {
            int big = 0x7fffffff; // same behaviour vor Int32.MaxValue
            prt("big = " + big);
            int bigger = big * 4;
            prt("bigger = " + bigger);
            prt("done");
        }
          static void prt(String s) {
            System.Console.WriteLine(s);

        }
    }
}

Output:

big = 2147483647
bigger = -4
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:00:50+00:00Added an answer on May 30, 2026 at 9:00 am

    The language specification mandates wrap-around behaviour for overflowing computations, so it’s a feature. Since most overflows cannot be detected at compile time, it’s of dubious value to check for those that can be detected, in particular because they may have been intentional.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked here before, but I don't think those
I know this question has been asked here a few times before. But i
I know this question has been asked and answered many times. But almost all
I know this question has been asked many times here, but no answer has
I know this question has been rised quite a lot of times, but then
I know this question has been asked before, but non of the solutions solve
I know this question has been asked a zillion times, but I still feel
I know this question has been done but I have a slightly different twist
I know this question has been posted before... but I haven't found any answer
I know this question has been asked before, but I haven't been able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.