GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array declaration" Watch "array declaration" New topic
Author

array declaration

Yosi Hendarsjah
Ranch Hand

Joined: Oct 02, 2003
Posts: 164
What's the difference between these two methods of array declarations?
Victor Pan
Ranch Hand

Joined: May 01, 2002
Posts: 36
SAME


Java makes world work!!!
dhana rangu
Ranch Hand

Joined: Oct 01, 2003
Posts: 65
hi yoshi
the first stmt is anonymous array.We can use such array construction if we want to send an array as an argument to some method.


dhana
Harvinder Singh
Ranch Hand

Joined: Feb 14, 2003
Posts: 90
int[] a1 = new int[]{2,6,9};
int[] a2 = {2,6,9};
Hi,
{} is considered as array intiallizer.In the second way of initiallization when compilers finds the '{}' then it searches the data types.Since the left hand mention it an int. a2 is intiallized with the int types.
But in the first the data type is explicitly mentioned as int. I hope that it will help u a little.
Thanks.


Hard work beats talent<br />when talent doesn't work hard.<p> - Tim Notke
Yosi Hendarsjah
Ranch Hand

Joined: Oct 02, 2003
Posts: 164
Are the bytecodes the same or different?
Harvinder Singh
Ranch Hand

Joined: Feb 14, 2003
Posts: 90
Hi Yoshi,
The bytecode are converted to machine specific code by JVM which is one of the way by which java achieve platform independency.Urs suggestion are always invited.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array declaration