开发者

what int,float variables after the program is executed

In开发者_JAVA技巧 general, as for as objects, java reclaims the memory occupied by the object whenever it is no longer needed. But at the same time we are using int, float and double data types, which are defined internally by the java language itself. What about the memory of that data type whenever it is no longer needed?

Please give me a reply...

Saravanan.P


Java removes any variables from memory as soon as those variables are no longer accessible. In other words, the built-in primitive datatypes consume no memory as soon as you leave the block they were declared in.

The memory usage of the different primitive datatypes are:

byte: 8 bit
short: 16 bit
int: 32 bit
long: 64 bit
float: 32 bit
double: 64 bit
boolean: 1 bit (it represents one bit, but can consume up to a byte)
char: 16 bit


Primitives (like int, float etc) are allocated in the stack, if they are local method variables and in the heap if they are member variables (i.e. fields of a class). Only the heap is garbage collected.


Fields and static variables are initialized to 0. Local variables must be explicitly initialized, otherwise the compiler will report an error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜