Q:

Why long value is negative although it's smaller than Long.MAX_VALUE

The value of Long.MAX_VALUE is 9223372036854775807
However, when I print the following:
System.out.println(1000 * 60 * 60 * 24 * 30);

I get -1702967296
Although the value should be 2592000000 which is smaller than Long.MAX_VALUE

A:

The values you are using are int not long. Use long value otherwise the result wraps round and becomes negative.

