• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is primitive type int in java?  RSS feed

 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

Can someone explain me what is primitive type int in java?
How it is used by computer?

The most important is why this :

outputs

Thank you!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The type int is a 32-bit signed integer. It stores integer numbers in two's complement format. This means it can hold numbers between Integer.MIN_VALUE = -2^31 = -2147483648 and Integer.MAX_VALUE = 2^31 - 1 = 2147483647.

If you have an int that contains 2147483647 and you add 1, then it overflows (rolls around) to -2147483648. This is a consequence of how integers are stored and how the CPU in your computer handles them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!