Why does Java strictly specify the range and behavior of its primitive types? Java strictly specifies the ranges for primitive values. The selection of values in integer or floating point types differs based on the requirement of an application. Developers need not always use int type to handle any integer values. By having the ranges, Java allows developers to utilize the facilities on primitive types in wise manner. For example to use the integer constant 39, it is not wise to represent long or int or even short as it is available in byte type and occupies 8 bits of memory space. By using it as int type, 32 bits of memory space need to be used. Hence there will be a performance issue. Thus the range of primitive types plays a vital role in a Java application performance.
|