but will it still be an object as Im not creating an instance like we do with the new keyword
There is no way to prevent creating a new Object unless you explicitly initialise an existing array.
int[] array = {1234,234,43,15234,433}; // creates a new array object every time
is shorthand for
int[] array = new int[] {1234,234,43,15234,433}; // creates a new array object every time
The only way to prevent using a new object is either
int[] array = null; // no new object
or
int[] array = reusedArray; // no new array
array[0] = 1234;
array[1] = 234;
array[2] = 43;
array[3] = 15234;
array[4] = 433;
when we use the "new" keyword what are we exactly telling the compiler
Create a new object on the heap (unless escape analysis can eliminate the object creation) While the Oracle/OpenJDK version 6 to 11 can place some objects on the stack instead of the heap to reduce heap usage, this doesn't apply to arrays AFAIK.
[Added] Is an array an object?
Variables in Java are only primitives or references. If it's not a scalar primitive, it's an object. e.g. Boolean
, int[]
, String
, Enum
variables are all references to Objects. i.e. String s
is not an object.