Java - Does null variable require space in memory
- by Yatendra Goel
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?