Java - Does null variable require space in memory
Posted
by Yatendra Goel
on Stack Overflow
See other posts from Stack Overflow
or by Yatendra Goel
Published on 2010-03-12T05:19:49Z
Indexed on
2010/03/12
5:27 UTC
Read the original article
Hit count: 182
java
class CheckStore {
private String displayText;
private boolean state;
private String meaningfulText;
private URL url;
public CheckStore(String text, boolean state) {
this.displayText = text;
this.state = state;
}
:
:
}
As I am initializing only two variables (displayText
and state
) in the constructor, Will the rest two variables (meaningfulText
and url
which will have the value null
) will require space in memory to store null
value.
Q1. I think they will require space. If they will, then how much memory does a null
value takes in the memory (like int
takes 4 bytes).
Q2. How much space a string takes in memory. I guess it will depend on the length of the string. So how much space a string takes of how much length?
© Stack Overflow or respective owner