 Hello and welcome to the lecture on Introduction to Array in Java. In this lecture we will be discussing about array concept in Java and array and arrays classes in Java library. The learning outcome of this video lecture is that the student will be able to write a Java program using array and array and array classes in Java library. The student will be able to differentiate between raw array in Java and usage of array and array classes. Array is a collection of similar type of data elements. Java array is an object which contains elements of similar data type. Array can be accessed using single variable name and index is used to access individual element from a set of elements. Array is a data structure which is used to store fixed set of elements in a sequential order. Array elements accessed using index and index starts with zero. Now here is how to declare array variable in Java. There are two ways of declaration of array as shown here. First data type with square brackets space name of array variable. Second way is data type space name of array with square bracket. Here is an example that is integer array declared with array name nums. Next is how to instantiate array in Java. When an array is declared only a reference of array is created. So to actually allocate a memory to array we use new operator as shown here. Data type specifies the type of data being allocated. Size specifies the number of elements in the array and array ref var is the name of array variable that is linked to the array. To use new to allocate an array you must specify the type and number of elements to allocate. Here is an example given first array nums is declared here and then in next line using new operator to instantiate this array. We can write the declaration of array variable and instantiation of array in a single text statement as shown here. The elements in the array allocated by new operator will automatically be initialized to 0 for numeric types and false for Boolean type for 0.0 value for double data type and it will be initialized to null for reference type that is user defined data type. Now here we can pause the video for some time and answer the below question which of this is an incorrect array declaration. Here option A and B using new operation correctly that is before array data type and array size. But in option C operator new is not succeeded by array type and array size. Hence the correct answer is option C. Next is initialization of array in Java. Syntax is as shown here. While declaration of array we can initialize array by specifying element values separated by commas in curly brackets as shown here. Data type specifies which type of data is stored in var num in array. Var num specifies the name of array variable and values that is val 1 to val n indicates the values assigned to array at the time of initialization of array. Here is an example given here difference in the initialization is same as we discussed at the time of array declaration. Both line of code initialize the array nums with the values 12, 32, 56, 34 and 45. We are accessing these individual elements using index that is here in this example from 0 to 4 and array using array reference variable as shown here. Another way of initializing array in Java is shown here with example. First line declare array variable with name roll nums. Second line instantiate and initialize array roll nums with values. This statement is equivalent to the statement shown here that is at the time of declaration itself we are initializing array roll numbers. We can write in this way also. Now you can pause the video for some time and answer the below question which of these is an incorrect statement. So here the answer is option A because array can be initialized using both new operator and comma separated expression surrounded by curly braces. We have seen in previous slide that it is not necessary to use new operator always at the time of array initialization. Therefore the correct answer is option C. Now this is a simple Java program in which array nums is declared and instantiated as shown in line number 4. Then individual array elements with index 0 to 4 are initialized with the values that is from line number 5 to line number 9 in the code. Then for loop return on line number 11 is used to display array elements. In this for loop in test condition length property of array is used to get the size of array. Array nums is declared and initialized with the values 12, 32, 56, 34 and 45 and this is the output of this given program. Now what are arrays in Java? Arrays are objects which store multiple variables of the same type. It can hold primitive types as well as object references. Since arrays are objects they are created during runtime. The array length is fixed. Array class in java.lang.reflect package is a part of the Java reflection. This class provides static method to dynamically create and access Java arrays. The arrays class in java.util package is a part of the Java collection framework. This class provides various methods for manipulating arrays such as sorting and searching. Static methods to dynamically create and access Java arrays. This class provides a static factory which allows arrays to be viewed as a list. That's why it is a part of the Java collection framework. See array class in detail. Array class is available in java.lang.reflect package. This class provides static methods to dynamically create and access Java arrays. It is final class which means it can't be instantiated or changed. Only the methods of this class can be used by the class name itself. The array class is immutable in nature. It means that the class cannot be extended or inherited. The array class is declared as a final to achieve immatability. The methods of this class can be used by the class name itself as shown here. The example is given here. How the methods can be instantiated or called using the array class name. Now let us see arrays class in detail. The arrays class in java.util package is part of the Java collection framework. This is a utility class which provides more methods for array manipulation such as searching and sorting. This class provides static methods to dynamically create and access Java arrays. Array class is not immutable. It is not defined as final class. This class provides a bridge from raw arrays to collection-based arrays that is list. This class consists only static methods and the methods of object class which is a superclass of this class. The methods of this class can be used by the class name itself. This is a simple program to demonstrate array class usage in Java. Now in this program, first we have declared the array size with the variable name size of array. Then we have created integer array using the array class from the java.lang.reflect package and from this array class we have used the new instance method which will help you to create the new instance of this array class of type int. Then the parameters passed to this new instance method is the first parameter is the type and second one is the size of that array. Then we have type constate this into a particular type integer. Then after that to insert the elements in the array we have used the set int method with the array class name. The set int method will help you to add the elements to the particular array at a particular index. So parameter to this method is first parameter is the array name then the index and then the value. So this statement will add the element 11 at index 0. Similarly 12 will be inserted at index 1, 13 will be inserted at index 2 in the array int. Then to print the array content we have used the two string method from arrays class. Arrays class is a part of java.util.array package, util package. Then to this method we have passed our array name array int which will help you to print this array as a string. So this is the output of this print of statement in the square bracket. The value is separated by comma it will display two string method. Then if you want to retrieve a particular element at a particular index then here we have used the get int method from array class. So with the name of array class name dot get int the parameter passed is the name of the array comma the index value from which you want to get the value index. So it will get the value at index 0. So that is in this case it is 11. So output is that element at index 0 is 11. Now next one is the example program to demonstrate the array class. We already used a two string method from the array class in the previous example. Here we have first created again the array of type integer with the size 5 using the new operator. So we are instantiated array of type integer with the size 5. Then from the array class we call the set int method to insert the value 10 and from the arrays class we use the two string method just to simply display that particular array. So as we discussed the initial value default value of the integer array is 0 and in this example we have inserted only the value 10 at index 0. So the output is first element is 10 and remaining element is 0. Why the remaining elements are 0? Because the default initial value for the integer type data is 0. Thank you for watching this video.