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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(4 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
|-
 
|-
 
|  00:02
 
|  00:02
| Welcome to the spoken tutorial on '''Array Operations '''in java.
+
| Welcome to the spoken tutorial on '''Array Operations''' in java.
  
 
|-
 
|-
 
|  00:07
 
|  00:07
| In this tutorial, you will learn how to  
+
| In this tutorial, you will learn how to:
  
 
|-
 
|-
 
|  00:09
 
|  00:09
| '''import the class Arrays '''and,
+
| '''import''' the '''class''' '''Arrays ''' and  
  
 
|-
 
|-
 
|  00:12
 
|  00:12
| '''perform basic operations on arrays'''.
+
| perform basic operations on '''arrays'''.
  
 
|-
 
|-
 
|  00:15
 
|  00:15
|  For this tutorial we are using  
+
|  For this tutorial, we are using '''Ubuntu 11.10''', '''JDK 1.6''' and '''Eclipse 3.7.0'''
 
+
'''Ubuntu 11.10''',  
+
 
+
'''JDK 1.6''' and  
+
 
+
'''Eclipse 3.7.0'''
+
  
 
|-
 
|-
 
|  00:25
 
|  00:25
| | For this tutorial, you should have knowledge on''' arrays in Java.'''
+
| For this tutorial, you should have knowledge of '''arrays''' in Java.
 
+
  
 
|-
 
|-
 
|  00:30
 
|  00:30
| If not, for relevant tutorial please visit our website which is as shown [http://spoken-tutorial.org/ http][http://spoken-tutorial.org/ ://][http://spoken-tutorial.org/ spoken][http://spoken-tutorial.org/ -][http://spoken-tutorial.org/ tutorial][http://spoken-tutorial.org/ .][http://spoken-tutorial.org/ org]
+
| If not, for relevant tutorials, please visit our website which is as shown. [http://spoken-tutorial.org]
  
 
|-
 
|-
 
| 00:35
 
| 00:35
|  The methods for array operations are available in a '''class '''called '''Arrays'''.  
+
|  The methods for array operations are available in a '''class''' called '''Arrays'''.  
 
+
  
 
|-
 
|-
 
|  00:40
 
|  00:40
| To access them, we need to import that '''class'''.
+
| To access them, we need to '''import''' that '''class'''.
 
+
  
 
|-
 
|-
 
|  00:43
 
|  00:43
| It is done by the statement '''import java.util.Arrays semicolon'''
+
| It is done by the statement '''import java.util.Arrays''' semicolon.
 
+
  
 
|-
 
|-
 
|  00:50
 
|  00:50
| We can access a '''method '''from the '''class'''.
+
| We can access a '''method''' from the '''class'''.
 
+
  
 
|-
 
|-
 
|  00:52
 
|  00:52
| We do it by adding a '''dot''' and the method name.
+
| We do it by adding a 'dot' and the '''method''' name.
 
+
  
 
|-
 
|-
 
|  00:56
 
|  00:56
| So '''Arrays '''''dot '''''toString''' means '''toString''' method from the  '''Arrays''' class.
+
| So, '''Arrays''' dot '''toString''' means '''toString''' method from the  '''Arrays''' '''class'''.
  
 
|-
 
|-
|   01:05
+
| 01:05
|Now Switch to eclipse.
+
| Now switch to '''eclipse'''.
 
+
  
 
|-
 
|-
 
|  01:08
 
|  01:08
 
| We have already created a '''class''' '''ArraysDemo'''.
 
| We have already created a '''class''' '''ArraysDemo'''.
 
  
 
|-
 
|-
 
|  01:13
 
|  01:13
| Let us now import the '''class Arrays'''.
+
| Let us now '''import''' the '''class''' '''Arrays'''.
  
 
|-
 
|-
 
|  01:16  
 
|  01:16  
| The '''import''' statement is written before the '''class '''definition.
+
| The '''import''' statement is written before the '''class''' definition.
 
+
  
 
|-
 
|-
 
|  01:22
 
|  01:22
|So Before '''public class''', type
+
|So, before '''public class''', type:
 
+
  
 
|-
 
|-
 
|  01:26
 
|  01:26
|import '''java.util.Arrays semicolon'''
+
|'''import java.util.Arrays''' semicolon
 
+
  
 
|-
 
|-
 
|  01:46
 
|  01:46
|This statement says that '''java''' contains a '''package '''called '''util''' which contains the class '''Arrays''' and it has to be imported.
+
|This statement says that '''java''' contains a '''package''' called '''util''' which contains the class '''Arrays''' and it has to be imported.
  
 
|-
 
|-
 
|  01:59
 
|  01:59
| Now let us add an '''array.'''
+
| Now, let us add an '''array.'''
 
+
  
 
|-
 
|-
 
|  02:01
 
|  02:01
|Inside the '''main '''function,type
+
|Inside the '''main''' function, type:
 
+
  
 
|-
 
|-
 
|  02:03
 
|  02:03
|'''int marks '''''open and close square brackets''''' '''''equal to within brackets '''''2, 7, 5, 4, 8 '''''  
+
|'''int marks''' open and close square brackets equal to within curly brackets '''2, 7, 5, 4, 8 '''  
  
 
|-
 
|-
 
|02:20
 
|02:20
|Now we shall use a method available in the '''Arrays''' '''class''' to get a string representation of the array and print it.
+
|Now we shall use a method available in the '''Arrays''' '''class''' to get a string representation of the '''array''' and print it.
 
+
  
 
|-
 
|-
 
|  02:28
 
|  02:28
|SoType '''String mStr '''''equal to''''' Arrays '''''dot '''''toString ''''' Paranthesis inside Paranthesis ''''' will give the array name i.emarks '''''  
+
|So, type: '''String mStr''' equal to ''' Arrays''' dot ''toString'' parentheses inside parentheses  will give the array name i.e. '''marks'''.
  
 
|-
 
|-
 
|  02:50
 
|  02:50
|Now this '''toString''' method will give the string representation of the array.
+
|Now, this '''toString''' method will give the '''string''' representation of the array.
 
+
  
 
|-
 
|-
 
|  02:56
 
|  02:56
| we shall print the marks.
+
| We shall print the marks.
 
+
  
 
|-
 
|-
 
|  02:58
 
|  02:58
|So, type '''System '''''dot '''''out '''''dot '''''println ''''inside Paranthesis''''' type mStr '''''
+
|So, type '''System ''' dot '''out''' dot '''println''' inside parentheses type '''mStr;'''
 
+
  
 
|-
 
|-
 
|  03:12
 
|  03:12
|Now let us look at the output so save and run the program
+
|Now, let us look at the output. So '''save''' and '''run''' the program.
  
 
|-
 
|-
 
| 03:18
 
| 03:18
| As we can see in the output, the '''toString''' method has given a string representation of the '''array.'''
+
| As we can see in the output, the '''toString''' '''method''' has given a string representation of the '''array.'''
 
+
  
 
|-
 
|-
 
|  03:26
 
|  03:26
|Now let us look at sorting the elements of the '''array'''.
+
|Now, let us look at sorting the elements of the '''array'''.
  
 
|-
 
|-
 
|  03:31
 
|  03:31
| So before the line '''Arrays '''''dot '''''toString '''''  '''type '''Arrays '''''dot '''''sort within parenthesis ''' the Array name i.e marks'''
+
| So, before the line '''Arrays''' dot '''toString''' type: '''Arrays''' dot '''sort''' within parentheses the Array name i.e '''marks'''.
+
  
 
|-  
 
|-  
 
|  03:46
 
|  03:46
|So the '''sort '''method in the '''Arrays class''', sorts the elements of the array passed to it.
+
|So, the '''sort''' '''method''' in the '''Arrays class''' sorts the elements of the '''array''' passed to it.
 
+
  
 
|-
 
|-
 
|  03:53
 
|  03:53
|Now we are sorting the element of the array '''marks''' and then printing the string form of it.
+
|Now we are sorting the elements of the array '''marks''' and then printing the '''string''' form of it.
 
+
  
 
|-
 
|-
 
|  04:04
 
|  04:04
|Let us look at the output.So save and run
+
|Let us look at the output. So '''save''' and '''run'''.
  
 
|-
 
|-
 
|  04:11
 
|  04:11
|  As we can see in the output the '''sort''' method has sorted to  the array in the ascending order
+
|  As we can see in the output, the '''sort''' '''method''' has sorted the '''array''' in the ascending order.
 
+
  
 
|-
 
|-
 
|  04:19
 
|  04:19
|Note that the '''sort''' method has changed the array itself.
+
|Note that the '''sort''' '''method''' has changed the '''array''' itself.
 
+
  
 
|-
 
|-
 
|  04:22
 
|  04:22
|This type of sorting is called''' inplace sorting'''.  
+
|This type of sorting is called '''inplace sorting'''.  
 
+
  
 
|-
 
|-
 
|  04:26
 
|  04:26
 
|It means that the array which contains the elements is changed as a result of sorting.
 
|It means that the array which contains the elements is changed as a result of sorting.
 
  
 
|-
 
|-
 
|  04:33
 
|  04:33
|The next method we are going to look at, is '''fill'''
+
|The next '''method''' we are going to look at is '''fill'''.
  
 
|-
 
|-
 
| 04:38
 
| 04:38
|  The fill method takes two arguments.  
+
|  The '''fill''' '''method''' takes two '''argument'''s.  
 
+
+
  
 
|-
 
|-
 
|  04:43
 
|  04:43
 
|Remove the sorting line and
 
|Remove the sorting line and
 
  
 
|-
 
|-
 
|  04:50
 
|  04:50
|Type '''Arrays '''''dot '''''fill '''''within brackets''''' the name of the arrays i.e marks;'''
+
|type: '''Arrays''' dot '''fill''' within brackets the name of the array i.e '''marks;'''
  
 
|-
 
|-
 
| 05:05  
 
| 05:05  
|This is our first argument and second is the value that should be filled in the array we will give it 6 and semicolon. Save and Run
+
|This is our first '''argument''' and second is the value that should be filled in the array, we will give it 6 and semicolon. '''Save''' and '''Run'''.
 
   
 
   
 
|-
 
|-
 
| 05:24
 
| 05:24
|  As we can see, as the name goes, the fill method fills the array with the given argument i.e 6
+
|  As we can see, as the name goes, the '''fill''' '''method''' fills the array with the given argument i.e 6.
 
+
  
 
|-
 
|-
 
| 05:32  
 
| 05:32  
|The next method we are going to look at, is '''copyOf'''
+
|The next method we are going to look at is '''copyOf'''.
  
 
|-
 
|-
 
|  05:37
 
|  05:37
|   We are going to copy all the elements of the array '''marks''' into the array '''marksCopy'''
+
| We are going to copy all the elements of the array '''marks''' into the array '''marksCopy'''.
  
 
|-
 
|-
 
|  05:44
 
|  05:44
|So remove arrays dot fill
+
|So, remove 'arrays dot fill'.
 
|-
 
|-
 
|  05:48
 
|  05:48
| And Type '''int marksCopy []; '''
+
| And type: '''int marksCopy[];'''
  
 
|-
 
|-
 
|  05:59
 
|  05:59
| next line,   Type '''marksCopy = arrays. copyOf(marks, 5);'''
+
| Next line, type: '''marksCopy = Arrays.copyOf(marks, 5);'''
 
+
  
 
|-
 
|-
 
|  06:25
 
|  06:25
|This method takes two arguments.  
+
|This method takes two '''arguments'''.  
 
+
  
 
|-
 
|-
 
|  06:29
 
|  06:29
|The first argument is the name of the  array from which you want to copy the elements.i.e marks
+
|The first '''argument''' is the name of the  array from which you want to copy the elements.i.e '''marks'''.
  
 
|-
 
|-
 
|06:39
 
|06:39
the second is the no.of elements to copy overhere we will copy 5.
+
The second is the no.of elements to copy, over here we will copy 5.
 
|-
 
|-
 
|  06:47
 
|  06:47
|Then in arrays dot tostring change''' marks''' to '''marks copy'''
+
|Then, in '''arrays''' dot '''toString''', change '''marks''' to '''marksCopy'''.
 
+
 
+
 
+
  
 
|-
 
|-
 
|  06:55
 
|  06:55
|  Now save and run the program
+
|  Now '''save''' and '''run''' the program.
  
 
|-
 
|-
Line 269: Line 229:
 
| 07:10
 
| 07:10
 
| Let us see what happens if we change the no.of elements to be copied.
 
| Let us see what happens if we change the no.of elements to be copied.
 
  
 
|-
 
|-
 
|  07:15
 
|  07:15
|Let's'''Change 5''' to '''3'''.
+
|Let's Change '''5''' to '''3'''.
 
+
 
+
  
 
|-
 
|-
 
| 07:19
 
| 07:19
| | Save and Run   
+
| '''Save''' and '''Run'''.  
  
 
|-
 
|-
 
|  07:24
 
|  07:24
 
|As we can see, only the first three elements have been copied.
 
|As we can see, only the first three elements have been copied.
 
  
 
|-
 
|-
Line 292: Line 248:
 
|-
 
|-
 
|  07:39
 
|  07:39
|  So Change '''3''' to '''8'''
+
|  So, change '''3''' to '''8'''.
 
+
  
 
|-
 
|-
 
| 07:44
 
| 07:44
|Save and Run the program
+
|'''Save''' and '''Run''' the program.
 
+
  
 
|-
 
|-
 
|  07:48
 
|  07:48
|As we can see, the extra elements have been set to the default value, which is 0.
+
|As we can see, the extra elements have been set to the default value which is 0.
 
+
  
 
|-
 
|-
 
| 07:54  
 
| 07:54  
|Next we'll see how to copy a range of values.
+
|Next, we'll see how to copy a range of values.
  
 
|-
 
|-
 
|  07:58  
 
|  07:58  
|  So Change '''copyOf '''to''' copyOfRange '''and''' 8''' to '''1, 4'''
+
|  So, change '''copyOf''' to '''copyOfRange''' and '''8''' to '''1, 4'''.
 
   
 
   
 
|-
 
|-
 
|  08:15
 
|  08:15
|  This methods  copies all the elements starting from  the index 1 and stopping at index 3.
+
|  This '''method''' copies all the elements starting from  the index 1 and stopping at index 3.
 
+
  
 
|-
 
|-
 
| 08:27
 
| 08:27
| Save and Run   
+
| '''Save''' and '''Run'''.  
  
 
|-
 
|-
 
|  08:31
 
|  08:31
 
|As we can see, the elements from index 1 to  3 have been copied.
 
|As we can see, the elements from index 1 to  3 have been copied.
 
  
 
|-
 
|-
 
|  08:39
 
|  08:39
|Note that we have given 1, 4  as our arguments  
+
|Note that we have given 1, 4  as our '''arguments'''.
 
+
  
 
|-
 
|-
 
|  08:47
 
|  08:47
|But even, then the element at index 4 has not been copied.
+
|But, even then the element at index 4 has not been copied.
 
+
  
 
|-
 
|-
 
|  08:50
 
|  08:50
|Only the elements till index 3 have been copied. It stops one index before the given range
+
|Only the elements till index 3 have been copied. It stops one index before the given range.
  
 
|-
 
|-
 
|  09:01
 
|  09:01
| So This behaviour ensures that continuity of ranges is maintained.
+
| So, this behavior ensures that continuity of ranges is maintained.
 
+
  
 
|-
 
|-
 
|  09:07
 
|  09:07
|(0, 4) implies from index 0 to index 3
+
|(0, 4) implies from index 0 to 3.
  
 
|-
 
|-
 
|  09:12
 
|  09:12
|(4, 6) will implies index from 4 to   5
+
|(4, 6) will imply index from 4 to 5.
 
+
  
 
|-
 
|-
 
|  09:17
 
|  09:17
|So it behaves as if (0, 4) + (4, 6) = (0, 5)
+
|So it behaves as if (0, 4) + (4, 6) = (0, 5).
  
 
|-
 
|-
 
|  09:26
 
|  09:26
|  This brings us o the end of this tutorial.  
+
|  This brings us to the end of this tutorial.  
  
 
|-
 
|-
 
|  09:31
 
|  09:31
|In this tutorial we have learnt
+
|In this tutorial, we have learnt:
  
 
|-
 
|-
 
|  09:33
 
|  09:33
|how to '''import the class Arrays'''.
+
|How to '''import''' the '''class''' '''Arrays'''.
  
 
|-
 
|-
 
|  09:36
 
|  09:36
|Perform array operations like  '''to strings''',sort, copy, fill.
+
|Perform array operations like  '''toStrings''', '''sort''', '''copy''', '''fill'''.
  
 
|-
 
|-
 
|  09:44
 
|  09:44
|   For assignment
+
| For assignment:
  
 
|-
 
|-
 
|  09:46
 
|  09:46
|Read about the Arrays.equals method and find out what is does.
+
| Read about the '''Arrays.equals''' method and find out what it does.
  
 
|-
 
|-
 
|  09:53
 
|  09:53
|To know more about the '''Spoken Tutorial''' project,  
+
|To know more about the Spoken Tutorial project,  
 
|-
 
|-
 
|  09:55
 
|  09:55
|Watch the video available at[http://spoken-tutorial.org/What_is_a_Spoken_Tutorial ]   
+
|watch the video available at [http://spoken-tutorial.org/What_is_a_Spoken_Tutorial].  
  
 
|-
 
|-
 
|  10:02
 
|  10:02
| It summarises the Spoken Tutorial project
+
| It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
 
|  10:05
 
|  10:05
| If you do not have good bandwidth, you can download and watch it
+
| If you do not have good bandwidth, you can download and watch it.
  
 
|-
 
|-
 
|  10:09
 
|  10:09
|  The Spoken Tutorial Project Team.
+
|  The Spoken Tutorial project team: Conducts workshops using Spoken Tutorials, gives certificates to those who pass an online test.  
|-
+
|  10:10
+
Conducts workshops using '''spoken tutorials'''  .gives certificates for those who pass an online test.  
+
 
|-
 
|-
 
|  10:16
 
|  10:16
Line 410: Line 354:
 
|-
 
|-
 
|  10:22
 
|  10:22
| '''Spoken Tutorial '''Project is a part of the '''Talk to a Teacher''' project and is supported by the '''National Mission on Education through ICT, MHRD, Government of India.
+
| Spoken Tutorial project is a part of the Talk to a Teacher project and is supported by the National Mission on Education through ICT, MHRD, Government of India.
 
|-
 
|-
 
|  10:31
 
|  10:31
| '''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'''.
  
 
|-
 
|-
Line 421: Line 365:
 
|-
 
|-
 
| 10:43
 
| 10:43
|This is Prathmesh Salunke Signing off. Jai Hind.
+
|This is Prathmesh Salunke, signing off. Jai Hind.
 
+
 
+
  
 
|}
 
|}

Latest revision as of 15:16, 28 March 2017

Time Narration
00:02 Welcome to the spoken tutorial on Array Operations in java.
00:07 In this tutorial, you will learn how to:
00:09 import the class Arrays and
00:12 perform basic operations on arrays.
00:15 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 arrays in Java.
00:30 If not, for relevant tutorials, please visit our website which is as shown. [1]
00:35 The methods for array operations are available in a class called Arrays.
00:40 To access them, we need to import that class.
00:43 It is done by the statement import java.util.Arrays semicolon.
00:50 We can access a method from the class.
00:52 We do it by adding a 'dot' and the method name.
00:56 So, Arrays dot toString means toString method from the Arrays class.
01:05 Now switch to eclipse.
01:08 We have already created a class ArraysDemo.
01:13 Let us now import the class Arrays.
01:16 The import statement is written before the class definition.
01:22 So, before public class, type:
01:26 import java.util.Arrays semicolon
01:46 This statement says that java contains a package called util which contains the class Arrays and it has to be imported.
01:59 Now, let us add an array.
02:01 Inside the main function, type:
02:03 int marks open and close square brackets equal to within curly brackets 2, 7, 5, 4, 8
02:20 Now we shall use a method available in the Arrays class to get a string representation of the array and print it.
02:28 So, type: String mStr equal to Arrays dot toString parentheses inside parentheses will give the array name i.e. marks.
02:50 Now, this toString method will give the string representation of the array.
02:56 We shall print the marks.
02:58 So, type System dot out dot println inside parentheses type mStr;
03:12 Now, let us look at the output. So save and run the program.
03:18 As we can see in the output, the toString method has given a string representation of the array.
03:26 Now, let us look at sorting the elements of the array.
03:31 So, before the line Arrays dot toString type: Arrays dot sort within parentheses the Array name i.e marks.
03:46 So, the sort method in the Arrays class sorts the elements of the array passed to it.
03:53 Now we are sorting the elements of the array marks and then printing the string form of it.
04:04 Let us look at the output. So save and run.
04:11 As we can see in the output, the sort method has sorted the array in the ascending order.
04:19 Note that the sort method has changed the array itself.
04:22 This type of sorting is called inplace sorting.
04:26 It means that the array which contains the elements is changed as a result of sorting.
04:33 The next method we are going to look at is fill.
04:38 The fill method takes two arguments.
04:43 Remove the sorting line and
04:50 type: Arrays dot fill within brackets the name of the array i.e marks;
05:05 This is our first argument and second is the value that should be filled in the array, we will give it 6 and semicolon. Save and Run.
05:24 As we can see, as the name goes, the fill method fills the array with the given argument i.e 6.
05:32 The next method we are going to look at is copyOf.
05:37 We are going to copy all the elements of the array marks into the array marksCopy.
05:44 So, remove 'arrays dot fill'.
05:48 And type: int marksCopy[];
05:59 Next line, type: marksCopy = Arrays.copyOf(marks, 5);
06:25 This method takes two arguments.
06:29 The first argument is the name of the array from which you want to copy the elements.i.e marks.
06:39 The second is the no.of elements to copy, over here we will copy 5.
06:47 Then, in arrays dot toString, change marks to marksCopy.
06:55 Now save and run the program.
07:01 We see that the elements of the array marks have been copied to the array marksCopy.
07:10 Let us see what happens if we change the no.of elements to be copied.
07:15 Let's Change 5 to 3.
07:19 Save and Run.
07:24 As we can see, only the first three elements have been copied.
07:31 Let us see what happens if the no.of elements to be copied is greater than the total no.of elements in the array.
07:39 So, change 3 to 8.
07:44 Save and Run the program.
07:48 As we can see, the extra elements have been set to the default value which is 0.
07:54 Next, we'll see how to copy a range of values.
07:58 So, change copyOf to copyOfRange and 8 to 1, 4.
08:15 This method copies all the elements starting from the index 1 and stopping at index 3.
08:27 Save and Run.
08:31 As we can see, the elements from index 1 to 3 have been copied.
08:39 Note that we have given 1, 4 as our arguments.
08:47 But, even then the element at index 4 has not been copied.
08:50 Only the elements till index 3 have been copied. It stops one index before the given range.
09:01 So, this behavior ensures that continuity of ranges is maintained.
09:07 (0, 4) implies from index 0 to 3.
09:12 (4, 6) will imply index from 4 to 5.
09:17 So it behaves as if (0, 4) + (4, 6) = (0, 5).
09:26 This brings us to the end of this tutorial.
09:31 In this tutorial, we have learnt:
09:33 How to import the class Arrays.
09:36 Perform array operations like toStrings, sort, copy, fill.
09:44 For assignment:
09:46 Read about the Arrays.equals method and find out what it does.
09:53 To know more about the Spoken Tutorial project,
09:55 watch the video available at [2].
10:02 It summarizes the Spoken Tutorial project.
10:05 If you do not have good bandwidth, you can download and watch it.
10:09 The Spoken Tutorial project team: Conducts workshops using Spoken Tutorials, gives certificates to those who pass an online test.
10:16 For more details, please write to contact @ spoken HYPHEN tutorial DOT org.
10:22 Spoken Tutorial project is a part of the Talk to a Teacher project and is supported by the National Mission on Education through ICT, MHRD, Government of India.
10:31 More information on this mission is available at spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro.
10:39 This tutorial has been contributed by TalentSprint. Thanks for joining.
10:43 This is Prathmesh Salunke, signing off. Jai Hind.

Contributors and Content Editors

Gaurav, Krupali, PoojaMoolya, Sandhya.np14, Sneha