Java/C2/Creating-object/English-timed

From Script | Spoken-Tutorial
Revision as of 15:21, 28 March 2017 by PoojaMoolya (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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