Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is what I have read about Byte in Java tutorial: 

“ The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation

I didn’t understand the lines in bold. Can anyone explain it to me? 

1 Answer

0 votes
by (19.7k points)

It says whenever you use byte or int data type, it has a default range of  -128 to 127(byte) and −2,147,483,648 to 2,147,483,647(int). So in place of int, you can use byte data type when the requirement lies between the range -128 to 127 which will help you to save the memory. So, implicitly variable’s range is acting as documentation to give clarification about which data type you should choose. 

Interested in Java? Check out this Java Certification by Intellipaat. 

Related questions

0 votes
1 answer
asked Mar 14, 2021 in Java by Jake (7k points)
0 votes
1 answer
asked Feb 15, 2021 in Java by sheela_singh (9.5k points)

Browse Categories

...