Difference between revisions of "Java/C2/Creating-object/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
|| ''Time'''
+
|| '''Time'''
 
|| '''Narration'''
 
|| '''Narration'''
 
|-
 
|-
Line 8: Line 8:
 
|-
 
|-
 
| 00:05   
 
| 00:05   
|  In this tutorial we will learn about:
+
|  In this tutorial, we will learn about: '''Reference Variables'''
 
+
 
+
* Reference Variables
+
* Constructing objects and
+
* Memory Allocation for objects
+
 
+
  
 +
Constructing '''objects''' and Memory Allocation for '''objects'''.
  
 
|-
 
|-
 
| 00:13
 
| 00:13
| Here, we are using :
+
| Here, we are using : '''Ubuntu 11.10''', '''JDK 1.6''' and '''Eclipse IDE 3.7.0'''
 
+
* Ubuntu 11.10
+
* JDK 1.6 and
+
* Eclipse IDE 3.7.0
+
 
+
 
+
  
 
|-
 
|-
 
|  00:23
 
|  00:23
|   To follow this tutorial you must know how to create a simple '''class '''using '''Eclipse'''.
+
| To follow this tutorial, you must know how to create a simple '''class''' using '''Eclipse'''.
 
+
  
 
|-
 
|-
 
| 00:29
 
| 00:29
|If not please see the '''spoken-tutorial''' on these topics available at  
+
|If not, please see the Spoken Tutorial on these topics available at '''Spoken''' hyphen '''Tutorial''' dot org.
 
+
'''spoken '''''hyphen''''' tutorial '''''dot '''''org.'''
+
  
 
|-
 
|-
 
| 00:38  
 
| 00:38  
| | We know that''' variables''' and '''methods''' together form the '''members''' of a '''class'''.
+
| We know that '''variables''' and '''methods''' together form the members of a '''class'''.
 
+
  
 
|-
 
|-
 
| 00:43
 
| 00:43
|To access the members of a class , we need to create an object for the class.
+
|To access the members of a '''class''', we need to create an '''object''' for the class.
  
 
|-
 
|-
 
|00:48    
 
|00:48    
| | Now let us see what an''' object '''is.
+
| Now, let us see what an '''object''' is.
 
+
  
 
|-
 
|-
 
| 00:52
 
| 00:52
|An '''object '''is an '''instance''' of a class.
+
|An '''object''' is an '''instance''' of a '''class'''.
 
+
  
 
|-
 
|-
 
| 00:55
 
| 00:55
 
|Each object consist of '''state''' and '''behavior'''.
 
|Each object consist of '''state''' and '''behavior'''.
 
  
 
|-
 
|-
 
| 00:58
 
| 00:58
|Recall the example of '''human being class''' we had discussed in the earlier tutorial.
+
|Recall the example of 'human being' '''class''', we had discussed in the earlier tutorial.
 
+
  
 
|-
 
|-
 
| 01:04
 
| 01:04
 
|Object stores its state in '''fields''' or '''variables.'''
 
|Object stores its state in '''fields''' or '''variables.'''
 
  
 
|-
 
|-
 
| 01:08
 
| 01:08
|It exposes its behavior through''' methods'''.
+
|It exposes its behavior through '''methods'''.
 
+
 
+
 
+
  
 
|-
 
|-
 
|  01:11
 
|  01:11
|  Now let us learn about''' reference variables.'''
+
|  Now let us learn about '''reference variables.'''
 
+
  
 
|-
 
|-
 
| 01:15
 
| 01:15
 
|We know about the 8 primitive data types in Java.
 
|We know about the 8 primitive data types in Java.
 
  
 
|-
 
|-
 
| 01:19
 
| 01:19
|All other types refer to objects rather than primitives.
+
|All other types refer to '''objects''' rather than primitives.
 
+
  
 
|-
 
|-
 
| 01:23
 
| 01:23
|Variables that refer to objects are '''reference variables'''.
+
|'''Variables''' that refer to '''objects''' are '''reference variables'''.
  
 
|-
 
|-
 
|  01:28
 
|  01:28
| Let us go back to the '''Student class''' which we have already created in the earlier''' tutorial'''.
+
| Let us go back to the '''Student class''' which we have already created in the earlier tutorial.
 
+
  
 
|-
 
|-
 
| 01:37
 
| 01:37
 
|Now, let me remove the '''main''' '''method''' from this '''class'''.
 
|Now, let me remove the '''main''' '''method''' from this '''class'''.
 
  
 
|-
 
|-
 
| 01:49
 
| 01:49
|Now'''Save '''the '''file''' by pressing '''Control '''and '''S '''keys simultaneously.
+
|Now, '''Save''' the file by pressing '''Control''' and '''S''' keys simultaneously.
 
+
  
 
|-
 
|-
 
| 01:55
 
| 01:55
|Now create another '''class''' named '''TestStudent '''inside the same''' project.'''
+
|Now, create another '''class''' named '''TestStudent''' inside the same '''project.'''
 
+
  
 
|-
 
|-
 
| 02:00
 
| 02:00
 
|I have already created it.
 
|I have already created it.
 
  
 
|-
 
|-
 
| 02:03
 
| 02:03
|In this '''class '''I have the''' main method.'''
+
|In this '''class''', I have the '''main method.'''
 
+
  
 
|-
 
|-
 
| 02:06
 
| 02:06
|No inside the main''' method '''I will create an''' object '''of the''' Student class.'''
+
|Now, inside the '''main method''' I will create an '''object''' of the '''Student class.'''
 
+
  
 
|-
 
|-
 
| 02:11
 
| 02:11
|For that, inside the '''main method''', type  
+
|For that, inside the '''main method''', type:
 
+
  
 
|-
 
|-
 
| 02:17
 
| 02:17
|'''Student '''''space''''' stud1''' ''equal to'' '''new''' ''space'' '''Student''' ''opening and closing brackets, semicolon''.
+
|'''Student''' space '''stud1''' equal to '''new''' space '''Student''' opening and closing brackets semicolon.
 
+
  
 
|-
 
|-
 
| 02:34
 
| 02:34
|Thus we have created an '''object''' of the '''Student class'''.
+
|Thus, we have created an '''object''' of the '''Student class'''.
 
+
  
 
|-
 
|-
 
| 02:37
 
| 02:37
|Here,''' Student''' is the name of the''' class '''for which the '''object '''is to be created.
+
|Here, '''Student''' is the name of the '''class''' for which the '''object''' is to be created.
 
+
  
 
|-  
 
|-  
 
| 02:47
 
| 02:47
|'''stud1''' is a '''reference variable''' referring to one '''object '''of the '''Student''' class.
+
|'''stud1''' is a '''reference variable''' referring to one '''object''' of the '''Student''' '''class'''.
 
+
  
 
|-
 
|-
 
| 02:53
 
| 02:53
|And the''' new keyword''' allocates space for the new '''object''' to be created.
+
|And the '''new''' keyword allocates space for the new '''object''' to be created.
 
+
  
 
|-
 
|-
 
| 02:59
 
| 02:59
 
|Please note that '''stud1''' is not the '''object''' of the '''Student class'''.
 
|Please note that '''stud1''' is not the '''object''' of the '''Student class'''.
 
  
 
|-
 
|-
 
| 03:03
 
| 03:03
 
|It only holds the reference of the new '''object''' created.
 
|It only holds the reference of the new '''object''' created.
 
 
 
  
 
|-
 
|-
 
|  03:09
 
|  03:09
 
|  Now, let us see what '''stud1''' contains.
 
|  Now, let us see what '''stud1''' contains.
 
  
 
|-
 
|-
 
| 03:13
 
| 03:13
|So next line type '''System''' ''dot '''''out''' ''dot '''''println''' within brackets and double quotes '''stud1''' '''contains''' space ''plus '''''stud1''''' ''and then''' '''''semicolon''.
+
|So, next line, type: '''System''' dot '''out''' dot '''println''' within brackets and double quotes '''stud1''' '''contains''' space plus '''stud1''' and then semicolon.
 
+
  
 
|-
 
|-
 
| 03:44
 
| 03:44
|Now, '''save '''and''' run '''the '''file TestStudent''' ''dot''''' java'''.
+
|Now, '''save''' and '''run''' the file '''TestStudent''' dot '''java'''.
  
 
|-
 
|-
 
|  03:53
 
|  03:53
 
| We get the output as follows.
 
| We get the output as follows.
 
  
 
|-
 
|-
 
| 03:56
 
| 03:56
|So here '''Student '''is the name of the '''class '''of the new '''object '''created.
+
|So, here '''Student''' is the name of the '''class''' of the new '''object '''created.
 
+
  
 
|-
 
|-
 
| 04:03
 
| 04:03
 
|The second part is the '''memory address''' of the new '''object''' created.
 
|The second part is the '''memory address''' of the new '''object''' created.
 
  
 
|-
 
|-
 
| 04:08
 
| 04:08
|We can access the '''fields '''and '''methods''' of the '''Student class''' using '''stud1'''.
+
|We can access the '''fields''' and '''methods''' of the '''Student class''' using '''stud1'''.
 
+
  
 
|-
 
|-
Line 216: Line 167:
 
| 04:18
 
| 04:18
 
|  Now, I will create one more '''object''' of the '''Student class'''.
 
|  Now, I will create one more '''object''' of the '''Student class'''.
 
  
 
|-
 
|-
 
| 04:24
 
| 04:24
|So, I will type '''Student '''''space '''''stud2 '''''equal to '''''new '''''space '''''Student '''''opening and closing brackets semi-colon.''
+
|So, I will type: '''Student''' space '''stud2''' equal to '''new''' space '''Student''' opening and closing brackets semicolon.
  
 
|-
 
|-
| 04:47
+
|04:47
| Now type next line '''System''''' dot'' '''out '''''dot '''''println''' ''within brackets and double quotes '''''stud2 contains space '''''plus '''''stud2 '''and then ''semicolon.''
+
| Now, type: next line '''System''' dot '''out''' dot '''println''' within brackets and double quotes '''stud2 contains''' space plus '''stud2''' and then semicolon.  
 
+
  
 
|-
 
|-
 
| 05:19
 
| 05:19
|Now, let us save and run this file.
+
|Now, let us '''save''' and '''run''' this file.
  
 
|-
 
|-
 
|  05:25
 
|  05:25
| We can see that here '''stud1 '''and '''stud2 '''refers to two different '''objects'''.
+
| We can see that, here, '''stud1''' and '''stud2''' refer to two different '''objects'''.
 
+
  
 
|-
 
|-
 
| 05:31
 
| 05:31
|That is, '''stud1 '''and '''stud2''' are referring to two different students.
+
|That is, '''stud1''' and '''stud2''' are referring to two different students.
 
+
  
 
|-
 
|-
Line 246: Line 193:
  
 
|-
 
|-
|   05:44
+
| 05:44
| Now, we can make a change here.
+
| Now, we can make a change here.
 
+
  
 
|-
 
|-
 
| 05:51
 
| 05:51
|Here type '''Student stud2''' ''equal to'' '''stud1.'''
+
|Here, type: '''Student stud2''' equal to '''stud1.'''
 
+
  
 
|-
 
|-
 
| 06:01
 
| 06:01
|Now, '''save''' and '''run''' this''' file'''.
+
|Now, '''save''' and '''run''' this file.
 
+
 
+
 
+
  
 
|-
 
|-
 
| 06:06
 
| 06:06
|   We can see that here both''' stud1''' and '''stud2 '''refers to the same '''object.'''
+
| We can see that, here, both '''stud1''' and '''stud2 '''refer to the same '''object.'''
 
+
  
 
|-
 
|-
 
| 06:12
 
| 06:12
|That means both '''stud1 '''and '''stud2 '''are referring to the same '''student''' with a roll number and name.
+
|That means, both '''stud1''' and '''stud2 '''are referring to the same '''student''' with a roll number and name.
  
 
|-
 
|-
 
|  06:31
 
|  06:31
| So in this tutorial we learnt about
+
| So, in this tutorial, we learnt about:
  
 
|-
 
|-
 
| 06:34
 
| 06:34
|Reference variables
+
| Reference variablesCreating object using new operator  
|-
+
|06:35
+
| Creating object using new operator  
+
 
|-
 
|-
 
| 06:38   
 
| 06:38   
|And  Assigning references
+
|And  assigning references.
 
+
 
+
  
 
|-
 
|-
 
| 06:41
 
| 06:41
| For self assessment  
+
| For self assessment,
 
|-
 
|-
 
| 06:43
 
| 06:43
| create another '''class''' named '''TestEmployee'''.
+
| Create another '''class''' named '''TestEmployee'''.
 
|-
 
|-
 
| 06:46
 
| 06:46
| Create an '''object '''of the '''Employee class'''  with ''reference variable'' as '''emp1'''.
+
| Create an '''object''' of the '''Employee class'''  with '''reference variable''' as '''emp1'''.
 
+
 
+
  
 
|-
 
|-
 
|  06:52
 
|  06:52
| To know more about the spoken tutorial project.
+
| To know more about the spoken tutorial project,
 
|-
 
|-
 
| 06:55
 
| 06:55
|Watch the video available at [http://spoken-tutorial.org/What_is_a_Spoken_Tutorial http://spoken-][http://spoken-tutorial.org/What_is_a_Spoken_Tutorial tutorial.org/What_is_a_Spoken_Tutorial]
+
|watch the video available at [http://spoken-tutorial.org/What_is_a_Spoken_Tutorial].
 
+
 
|-
 
|-
 
| 06:58
 
| 06:58
| It summarises the Spoken Tutorial project  
+
| It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
 
| 07:01
 
| 07:01
| 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.
 
+
 
+
  
 
|-
 
|-
 
|  07:05
 
|  07:05
| | The Spoken Tutorial Project Team
+
| The Spoken Tutorial project team:
  
 
|-
 
|-
 
| 07:07
 
| 07:07
|Conducts workshops using spoken tutorials  
+
|Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
| 07:10
 
| 07:10
| Gives certificates for those who pass an online test  
+
| Gives certificates to those who pass an online test.
  
 
|-
 
|-
 
| 07:14
 
| 07:14
 
| For more details, please write to contact@spoken-tutorial.org  
 
| For more details, please write to contact@spoken-tutorial.org  
 
 
  
 
|-
 
|-
 
| 07:20
 
| 07:20
|  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.
  
 
|-
 
|-
 
| 07:24
 
| 07:24
|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.
 
|-
 
|-
 
| 07:31
 
| 07:31
| More information on this Mission is available at  
+
| More information on this mission is available at [http://spoken-tutorial.org/NMEICT-Intro].  
  [http://spoken-tutorial.org/NMEICT-Intro http://spoken-tutorial.org/NMEICT-Intro]
+
 
+
 
+
  
 
|-
 
|-
 
| 07:40
 
| 07:40
| Thus we  have come to the end of this tutorial.
+
| Thus, we  have come to the end of this tutorial.
  
 
|-
 
|-
 
| 07:43
 
| 07:43
|This is Arya Ratish from IIT Bombay signing off.
+
|This is Arya Ratish from IIT Bombay, signing off.
  
 
|-
 
|-
 
| 07:46
 
| 07:46
 
|Thanks for joining us.
 
|Thanks for joining us.

Latest revision as of 15:21, 28 March 2017

Time Narration
00:01 Welcome to the spoken tutorial on Creating objects.
00:05 In this tutorial, we will learn about: Reference Variables

Constructing objects and Memory Allocation for objects.

00:13 Here, we are using : Ubuntu 11.10, JDK 1.6 and Eclipse IDE 3.7.0
00:23 To follow this tutorial, you must know how to create a simple class using Eclipse.
00:29 If not, please see the Spoken Tutorial on these topics available at Spoken hyphen Tutorial dot org.
00:38 We know that variables and methods together form the members of a class.
00:43 To access the members of a class, we need to create an object for the class.
00:48 Now, let us see what an object is.
00:52 An object is an instance of a class.
00:55 Each object consist of state and behavior.
00:58 Recall the example of 'human being' class, we had discussed in the earlier tutorial.
01:04 Object stores its state in fields or variables.
01:08 It exposes its behavior through methods.
01:11 Now let us learn about reference variables.
01:15 We know about the 8 primitive data types in Java.
01:19 All other types refer to objects rather than primitives.
01:23 Variables that refer to objects are reference variables.
01:28 Let us go back to the Student class which we have already created in the earlier tutorial.
01:37 Now, let me remove the main method from this class.
01:49 Now, Save the file by pressing Control and S keys simultaneously.
01:55 Now, create another class named TestStudent inside the same project.
02:00 I have already created it.
02:03 In this class, I have the main method.
02:06 Now, inside the main method I will create an object of the Student class.
02:11 For that, inside the main method, type:
02:17 Student space stud1 equal to new space Student opening and closing brackets semicolon.
02:34 Thus, we have created an object of the Student class.
02:37 Here, Student is the name of the class for which the object is to be created.
02:47 stud1 is a reference variable referring to one object of the Student class.
02:53 And the new keyword allocates space for the new object to be created.
02:59 Please note that stud1 is not the object of the Student class.
03:03 It only holds the reference of the new object created.
03:09 Now, let us see what stud1 contains.
03:13 So, next line, type: System dot out dot println within brackets and double quotes stud1 contains space plus stud1 and then semicolon.
03:44 Now, save and run the file TestStudent dot java.
03:53 We get the output as follows.
03:56 So, here Student is the name of the class of the new object created.
04:03 The second part is the memory address of the new object created.
04:08 We can access the fields and methods of the Student class using stud1.
04:15 We will learn about these in the coming tutorials.
04:18 Now, I will create one more object of the Student class.
04:24 So, I will type: Student space stud2 equal to new space Student opening and closing brackets semicolon.
04:47 Now, type: next line System dot out dot println within brackets and double quotes stud2 contains space plus stud2 and then semicolon.
05:19 Now, let us save and run this file.
05:25 We can see that, here, stud1 and stud2 refer to two different objects.
05:31 That is, stud1 and stud2 are referring to two different students.
05:37 They have different roll numbers and names.
05:44 Now, we can make a change here.
05:51 Here, type: Student stud2 equal to stud1.
06:01 Now, save and run this file.
06:06 We can see that, here, both stud1 and stud2 refer to the same object.
06:12 That means, both stud1 and stud2 are referring to the same student with a roll number and name.
06:31 So, in this tutorial, we learnt about:
06:34 Reference variables, Creating object using new operator
06:38 And assigning references.
06:41 For self assessment,
06:43 Create another class named TestEmployee.
06:46 Create an object of the Employee class with reference variable as emp1.
06:52 To know more about the spoken tutorial project,
06:55 watch the video available at [1].
06:58 It summarizes the Spoken Tutorial project.
07:01 If you do not have good bandwidth, you can download and watch it.
07:05 The Spoken Tutorial project team:
07:07 Conducts workshops using spoken tutorials.
07:10 Gives certificates to those who pass an online test.
07:14 For more details, please write to contact@spoken-tutorial.org
07:20 Spoken Tutorial Project is a part of the Talk to a Teacher project.
07:24 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
07:31 More information on this mission is available at [2].
07:40 Thus, we have come to the end of this tutorial.
07:43 This is Arya Ratish from IIT Bombay, signing off.
07:46 Thanks for joining us.

Contributors and Content Editors

Arya Ratish, Devisenan, Gaurav, PoojaMoolya, Sandhya.np14, Sneha