Array

ARRAY:

An array is a data structure which holds similar types of elements.
An array is an object that stores a list of items. Each slot in an array holds individual elements. Each element should be a single datatype element, such that integer, strings, char etc.

DECLARING ARRAY ELEMENTS:

It indicates the name of the array followed by empty brackets.
Int arr[ ] ;

CREATING ARRAY OBJECTS:

After declaration of array, object is created and assigned to it.

There are two methods to create the array-

  1. Initialization
int initializeArray[ ] = {  1, 2, 3, 4, 5 };

  1. Use of new keyboard.
int newArray [ ] = new int [ 5 ];

The ‘new’ keyword creates an instance of the array. The number of elements array will hold must be specify inside ‘ [ ] ‘.


Program to show creation and definition of an array.

public class Array {
int arr[] = {1,2,3,4,5,6,7};
int i;
void display(){
        System.out.println("Displayin array elements");
           for(i=0;ii++){
                    System.out.println(arr[i]);
        }
}
public static void main(String args[]){
        Array d = new Array();
        d.display();
}
}

OUTPUT:
Displaying array elements
1
2
3
4
5
6
7


ACCESSING ARRAY ELEMENTS:

The array subscript expressions are used to change and use the values of the array. Knowledge of array subscripts are necessary for accessing an array element.

Array subscript always with ‘0’. Array subscript also known as index number.

For example,

int arr[] = {1,2,3,4,5,6,7};

In above example array subscript (index number) is as follows:

Array subscript
Array element
0
1
1
2
2
3
3
4
4
5
5
6
6
7

All subscripts must be within the body of the array. Such that in above example number of elements are 7, so max subscript will be 6 only.

The length of an array can be tested using ‘length’ instance variable.
For example,

int totalElement = arr.length;



MULTIDIMENSIONAL ARRAY:

Java doesn’t support multidimensional array. But array of array can be created.

For example,
public class arraOfArray{
int i=0;
int j=0;
int arr[][]=new int[3][3]; // array of array created
void set(){
           arr[0][0]=1;
           arr[0][1]=0;
           arr[0][2]=0;
           arr[1][0]=0;
           arr[1][1]=1;
           arr[1][2]=0;
           arr[2][0]=0;
           arr[2][1]=0;
           arr[2][2]=1;
}
void show(){
           for(i=0;i<3 i="" span="">++){
                       for(j=0;j<3 j="" span="">++){
                    System.out.print(arr[i][j] +"");
                   }
        System.out.println(" ");
        }
}
public static void main(String args[])
{
arrayOfArray aoa = new arrayOfArray ();
aoa.set();
aoa.show();
}
}

OUTPUT:
100
010
001

Python Programming ↓ 👆
Java Programming ↓ 👆
JAVA EasyExamNotes.com covered following topics in these notes.
JAVA Programs
Principles of Programming Languages ↓ 👆
Principles of Programming Languages
EasyExamNotes.com covered following topics in these notes.

Practicals:
Previous years solved papers:
A list of Video lectures References:
  1. Sebesta,”Concept of programming Language”, Pearson Edu 
  2. Louden, “Programming Languages: Principles & Practices” , Cengage Learning 
  3. Tucker, “Programming Languages: Principles and paradigms “, Tata McGraw –Hill. 
  4. E Horowitz, "Programming Languages", 2nd Edition, Addison Wesley

    Computer Organization and Architecture ↓ 👆

    Computer Organization and Architecture 

    EasyExamNotes.com covered following topics in these notes.

    1. Structure of desktop computers
    2. Logic gates
    3. Register organization
    4. Bus structure
    5. Addressing modes
    6. Register transfer language
    7. Direct mapping numericals
    8. Register in Assembly Language Programming
    9. Arrays in Assembly Language Programming

    References:

    1. William stalling ,“Computer Architecture and Organization” PHI
    2. Morris Mano , “Computer System Organization ”PHI

    Computer Network ↓ 👆
    Computer Network

    EasyExamNotes.com covered following topics in these notes.
    1. Data Link Layer
    2. Framing
    3. Byte count framing method
    4. Flag bytes with byte stuffing framing method
    5. Flag bits with bit stuffing framing method
    6. Physical layer coding violations framing method
    7. Error control in data link layer
    8. Stop and Wait scheme
    9. Sliding Window Protocol
    10. One bit sliding window protocol
    11. A protocol Using Go-Back-N
    12. Selective repeat protocol
    13. Application layer
    References:
    1. Andrew S. Tanenbaum, David J. Wetherall, “Computer Networks” Pearson Education.
    2. Douglas E Comer, “Internetworking with TCP/IP Principles, Protocols, And Architecture",Pearson Education
    3. KavehPahlavan, Prashant Krishnamurthy, “Networking Fundamentals”, Wiley Publication.
    4. Ying-Dar Lin, Ren-Hung Hwang, Fred Baker, “Computer Networks: An Open Source Approach”, McGraw Hill.