new
is how you ask the computer “I need memory space.”
int a = 2
: The computer knows an int is 4 bytes. So it can assume you just need 4 bytes and new
isn’t needed.
Technically you can be like: int a = new Integer(2);
but that’s not needed.
int[] array = int[23]
: The computer knows you’re making an array, but it doesn’t know what int[23]
means. It doesn’t know what to do with the 23.
int[] array = new int[23]
: The computer now knows from the new keyword that you want to allocate space for an integer array of 23 elements.
So whenever you use new, you’re asking the computer to give you space for whatever comes after the keyword.
If you got to the part about contructors, then you know that new will also call the contructor function.
Hope that makes sense!