Difference between revisions of "Java/C2/Introduction-to-Array/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 13: Line 13:
 
|-
 
|-
 
|  00:07
 
|  00:07
|  In this tutorial, you will learn how  to '''create arrays''' and  access elements in '''arrays'''.
+
|  In this tutorial, you will learn how  to create '''arrays''' and  access elements in '''array'''s.
 
+
 
+
  
 
|-
 
|-
 
|  00:14
 
|  00:14
|  For this tutorial we are using
+
|  For this tutorial, we are using:
 
+
 
* '''Ubuntu 11.10'''
 
* '''Ubuntu 11.10'''
 
* '''JDK 1.6''' and  
 
* '''JDK 1.6''' and  
 
* '''Eclipse 3.7.0'''
 
* '''Eclipse 3.7.0'''
 
 
  
 
|-
 
|-
 
| 00:25
 
| 00:25
| | For this tutorial, you should have knowledge of '''data types''' and '''for loop in Java.'''
+
| | For this tutorial, you should have knowledge of '''data types''' and '''for loop''' in Java.
 
+
  
 
|-
 
|-
 
| 00:32
 
| 00:32
| If not, for relevant tutorial please visit our website which as shown.
+
| If not, for relevant tutorials, please visit our website which is as shown.
  
 
|-
 
|-
 
| 00:38
 
| 00:38
Arrays are a collection of data.  
+
'''Array'''s are a collection of data.  
 
+
  
 
|-
 
|-
 
| 00:40
 
| 00:40
| For example, a list of marks, a list of names, a list of temperatures, a list of rainfall,
+
| For example, a list of marks, a list of names, a list of temperatures, a list of rainfall.
 
+
  
 
|-
 
|-
 
| 00:47
 
| 00:47
| Each item has an index based on its position.  
+
| Each item has an index, based on its position.  
 
+
  
 
|-
 
|-
 
| 00:52
 
| 00:52
| The index of the first element is 0.
+
| The index of the first element is '''0'''.
 
+
  
 
|-
 
|-
 
| 00:55
 
| 00:55
 
| The index of the  second element is  1 and so on.
 
| The index of the  second element is  1 and so on.
 
  
 
|-
 
|-
 
| 00:59
 
| 00:59
 
| Let us now see how to store this data.
 
| Let us now see how to store this data.
 
  
 
|-
 
|-
Line 72: Line 60:
 
|-
 
|-
 
|  01:06
 
|  01:06
|  A '''class''' named '''ArraysDemo '''has already been created.
+
|  A '''class''' named '''ArraysDemo''' has already been created.
 
+
  
 
|-
 
|-
 
| 01:11
 
| 01:11
| Within the main method, let us add the rainfall data.
+
| Within the '''main method''', let us add the rainfall data.
  
 
|-
 
|-
 
|  01:16
 
|  01:16
|  So Inside main function, type
+
|  So, inside '''main function''', type:
 
+
  
 
|-
 
|-
 
| 01:18
 
| 01:18
| '''int rainfall '''''open  and close  brackets equal to''''' '''''within curly brackets type''''' 25, 31, 29, 13, 27, 35, 12 ''''' and finally a semicolon.''
+
| '''int rainfall''' open  and close  brackets equal to within curly brackets type '''25, 31, 29, 13, 27, 35, 12''' and finally a semicolon.  
 
+
  
 
|-
 
|-
 
| 01:53
 
| 01:53
| Note the square braces after the '''variable '''name''' rainfall'''.  
+
| Note the square braces after the '''variable''' name '''rainfall'''.  
 
+
  
 
|-
 
|-
 
| 01:58  
 
| 01:58  
| This declares '''rainfall''' as an '''array''' of '''integers'''.
+
| This declares '''rainfall''' as an '''array''' of integers.
 
+
  
 
|-
 
|-
 
| 02:03
 
| 02:03
| The braces are used to specify the elements of the array.
+
| The braces are used to specify the elements of the '''array'''.
  
 
|-
 
|-
 
| 02:09
 
| 02:09
| let us now access data.
+
| Let us now access data.
  
 
|-
 
|-
 
|  02:12
 
|  02:12
| So on the Next line, type  
+
| So on the next line, type:
 
+
  
 
|-
 
|-
 
| 02:14
 
| 02:14
| '''System '''''dot '''''out '''''dot'' '''println ''' ''' rainfall ''' in square brackets type 2  
+
| '''System ''' dot '''out ''' dot '''println''' '''rainfall''' in square brackets type '''2'''.
 
+
  
 
|-
 
|-
 
| 02:28
 
| 02:28
| We are printing the element with the index number 2.
+
| We are printing the element with the index number 2.
 
+
  
 
|-
 
|-
 
| 02:32
 
| 02:32
| In other words, the third element in the array i.e.29.
+
| In other words, the third element in the '''array''' i.e. 29.
 
+
  
 
|-
 
|-
 
| 02:38
 
| 02:38
| Let us save   run the program  
+
| Let us '''save''', '''run''' the program.
  
 
|-
 
|-
 
|  02:43
 
|  02:43
|As  we can see, the output is the third element,i.e '''29'''.  
+
|As  we can see, the output is the third element, i.e '''29'''.  
 
+
  
 
|-
 
|-
 
| 02:49
 
| 02:49
| Now let us type 0 in place of 2
+
| Now, let us type 0 in place of 2.
  
 
|-
 
|-
 
| 02:56  
 
| 02:56  
|   Save and run the program
+
| '''Save''' and '''run''' the program.
  
 
|-
 
|-
 
| 03:00
 
| 03:00
| As we can see, the output is the first value i.e 25
+
| As we can see, the output is the first value i.e 25.
 
+
  
 
|-
 
|-
 
| 03:07
 
| 03:07
| Now let us modify the value of the first item
+
| Now, let us modify the value of the first item.
  
 
|-
 
|-
 
| 03:13  
 
| 03:13  
|   So type '''rainfall [0] = 11; '''
+
| So, type: '''rainfall[0] = 11;'''
+
  
 
|-
 
|-
 
| 03:27
 
| 03:27
| Now let us see its value. So save and run the program
+
| Now, let us see its value. So '''save''' and '''run''' the program.
 
+
  
 
|-
 
|-
Line 169: Line 144:
 
|-
 
|-
 
|  03:40
 
|  03:40
|  Now what if we  know only the size of the array and do not know the values.
+
|  Now, what if we  know only the size of the '''array''' and do not know the values.
 
|-
 
|-
 
| 03:45
 
| 03:45
| Let us see how to create such array.
+
| Let us see how to create such '''array'''.
  
 
|-
 
|-
 
|  03:49
 
|  03:49
| Remove everything in main function and type
+
| Remove everything in '''main''' function and type:
 
|-
 
|-
 
| 03:57
 
| 03:57
| '''int squares [] = new int [10]; '''
+
| '''int squares[] = new int[10];'''
 
|-
 
|-
 
| 04:19
 
| 04:19
| This statement creates an array of integers having 10 elements. The name of the array is '''squares'''.
+
| This statement creates an '''array''' of integers having 10 elements. The name of the '''array''' is '''squares'''.
 
|-
 
|-
 
| 04:30
 
| 04:30
| Now let us add some values to it
+
| Now, let us add some values to it.
  
 
|-
 
|-
 
|  04:33
 
|  04:33
| So '''Type'''
+
| So, type:
 
+
  
 
|-
 
|-
Line 198: Line 172:
 
|-
 
|-
 
| 04:43
 
| 04:43
| Next line'''squares[1] = 4;'''
+
| Next line, '''squares[1] = 4;'''
  
 
|-
 
|-
 
| 04:53
 
| 04:53
| Next line'''squares[2] = 9;'''  
+
| Next line, '''squares[2] = 9;'''  
  
 
|-
 
|-
 
| 05:04
 
| 05:04
 
| '''squares[3] = 16;'''
 
| '''squares[3] = 16;'''
 
  
 
|-
 
|-
 
| 05:15
 
| 05:15
| So We have entered the squares of first four numbers.
+
| So, we have entered the squares of first four numbers.
 
|-
 
|-
 
| 05:20
 
| 05:20
|  Now what about the other elements of the array. Let us see what they contain.
+
|  Now what about the other elements of the '''array'''. Let us see what they contain.
  
 
|-
 
|-
 
|  05:26
 
|  05:26
| So We shall print the sixth value in the array.   
+
| So, we shall print the sixth value in the '''array'''.   
 
+
  
 
|-
 
|-
 
| 05:30
 
| 05:30
|  Type '''System S capital.out.println(squares [5]); '''
+
|  Type: '''System''' S capital '''.out.println(squares [5]);'''
 
+
 
+
 
+
  
 
|-
 
|-
 
|  05:56
 
|  05:56
|  Save and run the program.We see that the value is zero.  
+
'''Save''' and '''run''' the program. We see that the value is zero.  
  
 
|-
 
|-
 
| 06:05
 
| 06:05
   | This is because when we create an array of integers, all the values are initialized to 0.  
+
   | This is because when we create an '''array''' of integers, all the values are initialized to 0.  
  
 
|-
 
|-
 
| 06:11  
 
| 06:11  
| Similarly an array of floats will have all its values initialized to 0.0.
+
| Similarly, an '''array''' of floats will have all its values initialized to 0.0.
 
+
  
 
|-
 
|-
 
| 06:18
 
| 06:18
| It would be a long process if we have to type each value into the array. Instead, let us use a for loop.
+
| It would be a long process if we have to type each value into the '''array'''. Instead, let us use a for loop.
  
 
|-
 
|-
 
| 06:28
 
| 06:28
|  So '''Type'''
+
|  So, type:
 
+
'''int n, x ;'''  
 
+
'''int n, x ; '''  
+
 
+
 
'''for(x = 4; x  < 10; x = x + 1){'''
 
'''for(x = 4; x  < 10; x = x + 1){'''
 
 
'''n = x + 1;'''
 
'''n = x + 1;'''
 
+
'''squares[x] = n * n;'''
'''squares [x] = n * n;'''
+
'''}'''
 
+
'''} '''
+
 
+
  
 
|-
 
|-
 
| 07:25
 
| 07:25
|So We iterate over numbers from 4 to 9 and set the corresponding element in the array.
+
|So, we iterate over numbers from 4 to 9 and set the corresponding element in the '''array'''.
 
+
  
 
|-
 
|-
 
| 07:36
 
| 07:36
| Now let us see the output.
+
| Now, let us see the output.
  
 
|-
 
|-
 
| 07:38
 
| 07:38
|  | As we can see, we are printing the  value of sixth element in  array SoSave and run.  
+
|  | As we can see, we are printing the  value of sixth element in  '''array'''. So, '''Save''' and '''run'''.  
 
|-
 
|-
 
| 07:52
 
| 07:52
| We   see the sixth element is now square of 6, which is 36.
+
| We see the sixth element is now square of 6 which is 36.
 
+
  
 
|-
 
|-
 
| 07:57
 
| 07:57
| In fact now we can set all the values inside the for loop.
+
| In fact, now we can set all the values inside the '''for loop'''.
  
 
|-
 
|-
 
|  08:03
 
|  08:03
| Remove the lines that set the values manually and change '''4''' to '''0'''
+
| Remove the lines that set the values manually and change '''4''' to '''0'''
 
+
  
 
|-
 
|-
 
| 08:14
 
| 08:14
| This way all the elements from index 0 to   9 are set to the corresponding squares.
+
| This way, all the elements from index 0 to 9 are set to the corresponding squares.
 
+
  
 
|-
 
|-
 
| 08:21
 
| 08:21
 
| We shall now see the value of the third element.
 
| We shall now see the value of the third element.
 
  
 
|-
 
|-
 
| 08:25
 
| 08:25
| So change '''5 '''to '''2'''
+
| So, change '''5''' to '''2'''.
 
+
  
 
|-
 
|-
 
| 08:30
 
| 08:30
| Save and run
+
| '''Save''' and '''run'''.
 
+
  
 
|-
 
|-
 
| 08:35
 
| 08:35
| As we can see, the value of the third element has been set in the loop and it is 9.
+
| As we can see, the value of the third element has been set in the '''loop''' and it is 9.
  
 
|-
 
|-
 
|  08:42
 
|  08:42
|  This way, arrays can be created and used.
+
|  This way, '''array'''s can be created and used.
  
 
|-
 
|-
Line 321: Line 275:
 
|-
 
|-
 
| 08:53
 
| 08:53
| In this tutorial we have learnt  
+
| In this tutorial we have learnt:
 
|-
 
|-
 
| 08:55
 
| 08:55
| TO declare and initialize the array ,
+
|* TO declare and initialize the '''array'''.
 
|-
 
|-
 
| 08:58
 
| 08:58
| And access element in an array
+
|* And access an element in an '''array'''.
 
|-
 
|-
 
|  09:01
 
|  09:01
| The assignment for this tutorial is,
+
| The assignment for this tutorial is:
 
+
  
 
|-
 
|-
 
| 09:04
 
| 09:04
| Given an array of integers, find the sum of all the elements in the array.
+
| Given an '''array''' of integers, find the sum of all the elements in the '''array'''.
  
 
|-
 
|-
 
|  09:10
 
|  09:10
| To know more about the '''Spoken Tutorial''' project,
+
| To know more about the Spoken Tutorial project,
 
|-
 
|-
 
| 09:13  
 
| 09:13  
Line 345: Line 298:
 
|-
 
|-
 
| 09:19
 
| 09:19
| It summarises the project.If you do not have good bandwidth, you can download and watch it.
+
| It summarizes the project. If you do not have good bandwidth, you can download and watch it.
  
 
|-
 
|-
 
|  09:26
 
|  09:26
|  The Spoken Tutorial Project Team. Conducts workshops using '''spoken tutorials''' and gives certificates for those who pass an online test.  
+
|  The Spoken Tutorial project team: Conducts workshops using spoken tutorials and gives certificates for those who pass an online test.  
 
|-
 
|-
 
| 09:34
 
| 09:34
Line 356: Line 309:
 
|-
 
|-
 
|  09:40
 
|  09:40
|   '''Spoken Tutorial '''Project is a part of the '''Talk to a Teacher''' project.
+
| Spoken Tutorial project is a part of the Talk to a Teacher project.
 
|-
 
|-
 
| 09:44
 
| 09:44
| It is supported by the '''National Mission on Education through ICT, MHRD, Government of India.  
+
| It is supported by the National Mission on Education through ICT, MHRD, Government of India.  
 
|-  
 
|-  
 
| 09:50
 
| 09:50
| '''More information on this Mission is available at '''spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro'''
+
| More information on this mission is available at '''spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro'''.
  
 
|-
 
|-
 
|  09:57
 
|  09:57
 
|  This script has been contributed by '''TalentSprint'''.  
 
|  This script has been contributed by '''TalentSprint'''.  
 
+
This is Prathamesh Salunke, signing off. Thanks for joining.
This is Prathamesh Salunke signing off. Thanks for joining.
+
 
+
 
+
 
+
  
 
|}
 
|}

Revision as of 22:36, 28 March 2015


Time Narration
00:02 Welcome to the spoken tutorial on Introduction to Arrays.
00:07 In this tutorial, you will learn how to create arrays and access elements in arrays.
00:14 For this tutorial, we are using:
  • Ubuntu 11.10
  • JDK 1.6 and
  • Eclipse 3.7.0
00:25 For this tutorial, you should have knowledge of data types and for loop in Java.
00:32 If not, for relevant tutorials, please visit our website which is as shown.
00:38 Arrays are a collection of data.
00:40 For example, a list of marks, a list of names, a list of temperatures, a list of rainfall.
00:47 Each item has an index, based on its position.
00:52 The index of the first element is 0.
00:55 The index of the second element is 1 and so on.
00:59 Let us now see how to store this data.
01:03 So switch to Eclipse.
01:06 A class named ArraysDemo has already been created.
01:11 Within the main method, let us add the rainfall data.
01:16 So, inside main function, type:
01:18 int rainfall open and close brackets equal to within curly brackets type 25, 31, 29, 13, 27, 35, 12 and finally a semicolon.
01:53 Note the square braces after the variable name rainfall.
01:58 This declares rainfall as an array of integers.
02:03 The braces are used to specify the elements of the array.
02:09 Let us now access data.
02:12 So on the next line, type:
02:14 System dot out dot println rainfall in square brackets type 2.
02:28 We are printing the element with the index number 2.
02:32 In other words, the third element in the array i.e. 29.
02:38 Let us save, run the program.
02:43 As we can see, the output is the third element, i.e 29.
02:49 Now, let us type 0 in place of 2.
02:56 Save and run the program.
03:00 As we can see, the output is the first value i.e 25.
03:07 Now, let us modify the value of the first item.
03:13 So, type: rainfall[0] = 11;
03:27 Now, let us see its value. So save and run the program.
03:34 As we can see, the value has been changed to 11.
03:40 Now, what if we know only the size of the array and do not know the values.
03:45 Let us see how to create such array.
03:49 Remove everything in main function and type:
03:57 int squares[] = new int[10];
04:19 This statement creates an array of integers having 10 elements. The name of the array is squares.
04:30 Now, let us add some values to it.
04:33 So, type:
04:35 squares[0] = 1;
04:43 Next line, squares[1] = 4;
04:53 Next line, squares[2] = 9;
05:04 squares[3] = 16;
05:15 So, we have entered the squares of first four numbers.
05:20 Now what about the other elements of the array. Let us see what they contain.
05:26 So, we shall print the sixth value in the array.
05:30 Type: System S capital .out.println(squares [5]);
05:56 Save and run the program. We see that the value is zero.
06:05 This is because when we create an array of integers, all the values are initialized to 0.
06:11 Similarly, an array of floats will have all its values initialized to 0.0.
06:18 It would be a long process if we have to type each value into the array. Instead, let us use a for loop.
06:28 So, type:

int n, x ; for(x = 4; x < 10; x = x + 1){ n = x + 1; squares[x] = n * n; }

07:25 So, we iterate over numbers from 4 to 9 and set the corresponding element in the array.
07:36 Now, let us see the output.
07:38 As we can see, we are printing the value of sixth element in array. So, Save and run.
07:52 We see the sixth element is now square of 6 which is 36.
07:57 In fact, now we can set all the values inside the for loop.
08:03 Remove the lines that set the values manually and change 4 to 0
08:14 This way, all the elements from index 0 to 9 are set to the corresponding squares.
08:21 We shall now see the value of the third element.
08:25 So, change 5 to 2.
08:30 Save and run.
08:35 As we can see, the value of the third element has been set in the loop and it is 9.
08:42 This way, arrays can be created and used.
08:50 We have come to the end of this tutorial.
08:53 In this tutorial we have learnt:
08:55 * TO declare and initialize the array.
08:58 * And access an element in an array.
09:01 The assignment for this tutorial is:
09:04 Given an array of integers, find the sum of all the elements in the array.
09:10 To know more about the Spoken Tutorial project,
09:13 watch the video available at the following link.
09:19 It summarizes the project. If you do not have good bandwidth, you can download and watch it.
09:26 The Spoken Tutorial project team: Conducts workshops using spoken tutorials and gives certificates for those who pass an online test.
09:34 For more details, please write to contact AT spoken HYPHEN tutorial DOT org.
09:40 Spoken Tutorial project is a part of the Talk to a Teacher project.
09:44 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
09:50 More information on this mission is available at spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro.
09:57 This script has been contributed by TalentSprint.

This is Prathamesh Salunke, signing off. Thanks for joining.

Contributors and Content Editors

Jyotisolanki, PoojaMoolya, Sandhya.np14, Sneha