/**
 * {@link <a href=
 * "https://[Log in to view URL]"
 * target="_blank">Overflow generato da un calcolo</a>}
 * 
 * @author itammb ( Italia Massimiliano Buscati )
 * @version JDK 1.15
 *
 */
class Main {

    /**
	 * @see Math#addExact(int x, int y)
	 *
	 */
	public static void overflow() {
		int num = 2147483647;
		try {
			System.out.println("massimo valore di tipo int -> " + num);
			// JVM non rileva un errore di overflow
			num++;
			// la variabile viene alterata
			System.out.println("minimo valore di tipo int -> " + num);

			num = 2147483647;
			// JVM rileva un errore di overflow
			num = Math.addExact(num, 1);
		} catch (Exception ex) {
			System.out.println("JVM segnala un errore di overflow");
		}

		System.out.println("la variabile non è alterata -> " + num);
	}
    public static void main(String[] args) {
		// Unit test - overflow generato da un calcolo
		overflow();        
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: