In your second program, the { ... }
are not array delimiters, they are block delimetes; in this case they are used to give a so-called initializer block, which is executed when a new instance of your class is instantiated.
The "correct" way to create an initialized array is:
new byte[] { 1, 2, 3 };
This can be used always, both when the reference is initialized and when an existing reference is used or when the array is passed to a method:
byte[] myArray = new byte[] { 1, 2, 3 }; // OK
myArray = new byte[] { 4, 5, 6 }; // OK
anObject.someMethod(new byte[] { 7, 8, 9}); // OK
However, the first variant is very common and therefore Java allows you to leave the new byte[]
part out in that particular case:
byte[] myArray = { 1, 2, 3 }; // OK
myArray = { 4, 5, 6 }; // Does not compile
anObject.someMethod({ 7, 8, 9}); // Does not compile