Tuesday, October 5, 2010

Array in Java

Important POints :

1)Uninitialized locations of Array in java Is Initialized with Zero.
2) Length is Non Static Variable.
Syso(arr.length);
3) Length is not a Function/Method it is Non Static Variable of a Array Object.
4) Small Program
int a[] = new int[40];
int b[] = null;
System.out.println(" >> a "+a);/*Prints Address*/
System.out.println(" >>> b "+b);/*Prints Null */

5) Array Of Objects
ClassName arrayName[] = new ClassName[5];
ArrayName is An Array which can hold Five ClassName Objects.
Where Objects are Not at Iniitliized .

Syso(arrayName[0]) /* Prints Null */
arrayName[0] = new ClassName();
Syso(arrayName[0]) /* Prints Address */

6) array OF String Objects
String s1[] = new String[3];
s1[0] = "Java";
s2[1] = "Sekhar";
s3[3] = "Ravi ";
Syso(s1[0]) /* Prints Java Not Address of the Object 'java' */
7) An Array With Zero Elements are Permitted.
Example :
int j[] = new int[0];
Syso(j[0]) /* Returns Error Bcz Array Doesn't contain any Elements */

No comments:

AWS certification question

AWS AWS Hi! this is for questions related to AWS questions. EC2 instances EC2 storage types cold HDD : 1. Defines performance in terms...