Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why are the data types byte, char and short needed

Tags:

java

jvm

I read in the JVM specification that the data types byte,short and char are internally treated as int. So why having these data types if we don't have a benefit from their small size?

like image 822
David Michael Gang Avatar asked Jun 05 '13 15:06

David Michael Gang


1 Answers

In part it's for compatibility with C/C++, and in part it's to conserve memory - internally, a short is stored as a short, but it's processed as an integer. A new short[10] takes up half as much memory as a new int[10]

like image 85
Zim-Zam O'Pootertoot Avatar answered Sep 18 '22 18:09

Zim-Zam O'Pootertoot