Difference between revisions of "Java/C3/Static-Variables/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| border=1 | <center>'''Time'''</center> | <center>'''Narration'''</center> |- | 00:01 | Welcome to the Spoken Tutorial on '''Static Variables.''' |- |00:05 | In this tuto...")
 
Line 1: Line 1:
 
 
{| border=1
 
{| border=1
| <center>'''Time'''</center>
+
|<center>'''Time'''</center>
| <center>'''Narration'''</center>
+
|<center>'''Narration'''</center>
  
 
|-
 
|-
| 00:01
+
|00:01
| Welcome to the Spoken Tutorial on '''Static Variables.'''
+
|Welcome to the Spoken Tutorial on '''Static Variables.'''
  
 
|-
 
|-
 
|00:05
 
|00:05
| In this tutorial we will learn about:
+
|In this tutorial we will learn about: What are''' static variables'''
  
* What are''' static variables'''
+
|-
* Creating''' static variables '''and
+
|00:10
* How to''' '''use''' static variables'''
+
| Creating''' static variables '''and How to use''' static variables'''
  
 
|-
 
|-
 
|00:17
 
|00:17
| Here we are using
+
|Here we are using '''Ubuntu 12.04''''''JDK 1.7 '''and '''Eclipse 4.3.1'''
 
+
* '''Ubuntu 12.04'''
+
* '''JDK 1.7 '''and
+
* '''Eclipse 4.3.1'''
+
  
 
|-
 
|-
| 00:27
+
|00:27
| To follow this tutorial, you must have knowledge of basics of''' Java''' and''' Eclipse IDE.'''
+
|To follow this tutorial, you must have knowledge of basics of''' Java''' and''' Eclipse IDE.'''
  
 
|-
 
|-
| 00:35
+
|00:35
|You should also have the knowledge of''' classes, objects '''and''' instance variables''' in''' Java.'''
+
|You should also have the knowledge of''' classes, objects ''' and''' instance variables''' in''' Java.'''
  
 
|-
 
|-
| 00:43
+
|00:42
 
|If not, for relevant''' Java '''tutorials, please visit the link shown.
 
|If not, for relevant''' Java '''tutorials, please visit the link shown.
  
 
|-
 
|-
| 00:49
+
|00:49
| A''' static variable''' is a variable which is associated with the entire''' class.'''
+
|A''' static variable''' is a variable which is associated with the entire''' class.'''
  
 
|-
 
|-
| 00:55
+
|00:55
|It is also called a '''class variable.''' It is declared using the''' static keyword.'''
+
|It is also called a''' class variable.'''
  
 
|-
 
|-
| 01:02
+
|00:58
| We have seen about static variable briefly in the earlier tutorial.  
+
|It is declared using the''' static keyword.'''
  
 
|-
 
|-
| 01:08
+
| 01:02
|In this tutorial we will see it in detail. Let us illustrate the usage of''' static variables''' with an example.
+
| We have seen about '''static variable''' briefly in the earlier tutorial.
  
 
|-
 
|-
| 01:16
+
|01:08
|Consider a''' class''' created to represent student enrollments in an organization.
+
|In this tutorial we will see it in detail.
  
 
|-
 
|-
| 01:23
+
|01:11
|This class contains the '''Name, Id , Branch''' and''' Total Count''' of students enrolled.
+
| Now we will switch to''' Eclipse''' and create a new '''project''' called '''StaticVariableDemo'''.
  
 
|-
 
|-
| 01:30
+
|01:18
|Now let us visualize what happens when student enrollments are done.
+
|Inside this '''project''' we will create the necessary classes to demonstrate the usage of''' Static variables.'''
  
 
|-
 
|-
| 01:36
+
| 01:26
|By default, '''Total Count''' is 0. The''' Name''' of the first student is '''ADIL.''' '''Id''' is''' IT101. Branch''' is''' IT.'''
+
| So right click on '''src''' folder and click '''New '''-> '''Class''', and type the name of the class as''' StudentEnroll''' and press '''Enter'''.
  
 
|-
 
|-
| 01:48
+
| 01:37
|Now the''' Total Count''' is updated as 1.
+
| Let us illustrate the usage of''' static variables''' with an example.
  
 
|-
 
|-
| 01:52
+
|01:42
|Similarly when the second student''' AMAL '''gets enrolled, '''Total Count''' is updated to 2.
+
|Consider a''' class''' created to represent student enrollments in an organisation.
  
 
|-
 
|-
| 01:59
+
|01:49
|When the third student''' CAROL''' gets enrolled,''' Total Count''' is updated to 3.
+
|This class contains the '''Name, Id , Branch''' and''' Total Count''' of students enrolled.
  
 
|-
 
|-
| 02:06
+
|01:56
|Now we can identify that the variable''' Total Count''' is common to all the objects and has a single value.
+
|Now let us visualize what happens when student enrollments are done.
  
 
|-
 
|-
| 02:14
+
|02:02
|So the variable''' Total Count''' can be represented as a''' static variable'''.
+
|By default '''Total Count''' is 0. The''' Name''' of the first student is '''ADIL.'''
  
 
|-
 
|-
| 02:20
+
|02:09
|We can also see that the variables''' Name, Id''' and''' Branch''' have their own copies for each object.
+
|'''Id''' is''' IT101.''' '''Branch''' is''' IT.'''
  
 
|-
 
|-
| 02:28
+
|02:14
|Also they have specific values for each object. So these variables can be treated as''' instance variables.'''
+
|Now the''' Total Count''' is updated as 1.
  
 
|-
 
|-
| 02:38
+
|02:18
| Now let us explore the differences between''' instance variables''' and''' static variables.'''
+
|Similarly when the second student''' AMAL '''gets enrolled, '''Total Count''' is updated to 2.
  
 
|-
 
|-
| 02:45
+
|02:25
|Every object has its own copies for '''instance variables.'''
+
|When the third student''' CAROL''' gets enrolled,''' Total Count''' is updated to 3.
  
 
|-
 
|-
| 02:50
+
|02:32
|'''Id, Name, Branch''' are examples of instance variables.
+
|Now we can identify that the variable''' Total Count''' is common to all the '''objects''' and has a single value.
  
 
|-
 
|-
| 02:55
+
|02:40
|'''Static variables''' in a class share a single copy with all objects in that class.
+
|So the variable''' Total Count''' can be represented as a''' static variable'''.
  
 
|-
 
|-
| 03:02
+
|02:45
|'''Total Count''' is an example of static variable.
+
|We can also see that the variables''' Name, Id''' and''' Branch''' have their own copies for each '''object'''.
  
 
|-
 
|-
| 03:06
+
|02:54
| When a class is loaded  a ''' static variable''' occupies a single fixed memory location
+
|Also they have specific values for each '''object'''.
 
+
whereas '''Instance variables''' of each object occupy separate''' '''memory locations.
+
  
 
|-
 
|-
| 03:19
+
|02:59
| Now let us look at the sample code representing the student enrollment class.
+
|So these variables can be treated as''' instance variables'''
  
 
|-
 
|-
| 03:25
+
| 03:04
|The name of the class is''' StudentEnroll.''' The instance variables are declared as''' id, name''' and''' branch.'''
+
| Now let us look at the code representing the '''student enrollment class'''.
  
 
|-
 
|-
| 03:35
+
|03:09
|The variable''' count''' is declared as static since it is common to the whole class.
+
|The '''instance variables''' are declared as''' id, name''' and''' branch.'''
  
 
|-
 
|-
| 03:41
+
|03:16
| Now we will switch to''' Eclipse''' and create a new project called '''StaticVariableDemo'''.
+
|The variable''' count''' is declared as '''static''' since it is common to the whole '''class'''.
  
 
|-
 
|-
| 03:48
+
|03:22
|Inside this project we will create the necessary classes to demonstrate the usage of''' Static variables.'''
+
|When a '''class''' is loaded a''' static variable''' occupies a single fixed memory location.
  
 
|-
 
|-
|03:56
+
|03:28
| So right click on '''src''' folder and click on '''new '''-> '''class''', and type the name of the class as''' StudentEnroll''' and Press '''Enter'''.
+
|Whereas '''Instance variables''' of each '''object''' occupy separate memory locations.
  
 
|-
 
|-
| 04:07
+
|03:35
|Now type the code which was shown in the earlier slide.
+
|Now click on''' Source ->''' and select''' Generate Constructor using Fields,'''
  
 
|-
 
|-
|04:12
+
|03:41
| Now click on''' source ->''' and select''' Generate Constructor using Fields.''' Delete the''' super''' keyword from the generated code.
+
|Delete the''' super keyword''' from the generated code.
  
 
|-
 
|-
|04:21
+
|03:45
| This '''constructor''' can initialize the values of the''' id, name''' and''' branch '''fields.
+
|This '''constructor''' can initialise the values of the''' id, name''' and''' branch '''fields.
  
 
|-
 
|-
| 04:28
+
|03:51
|We also need to increment the value of the variable''' count''' by one every time an object is created.
+
|We also need to increment the value of the variable''' count''' by one every time an '''object''' is created.
  
 
|-
 
|-
| 04:36
+
|03:59
|So inside the constructor type, '''count ++ semicolon.'''
+
|So inside the '''constructor''' type- '''count ++ semicolon'''
  
 
|-
 
|-
|04:42
+
|04:05
| Now we will add a''' '''method '''showData'''( ) to this class to print the values of all the variables.
+
|Now we will add a '''method showData'''( ) to this '''class''' to print the the values of all the variables.
  
 
|-
 
|-
| 04:50
+
|04:13
|So type''' public void showData( )'''  within brackets type the following code to print the values of''' id, name, branch '''and '''total number of students enrolled'''.
+
|So type''' public void showData( )'''  within brackets type the following code to print the values of''' id, name, branch,''' and total number of students enrolled.
  
 
|-
 
|-
| 05:04
+
|04:27
| Now right click on the '''default package''' click on '''new '''-> '''class''' and then type name as''' Demo.'''
+
|Now right-click on the '''default package''' and click on '''New '''-> '''Class''' and then type name as''' Demo.'''
  
 
|-
 
|-
| 05:12
+
|04:36
|Inside this class we will have the '''main''' method.
+
|Inside this '''class,''' we will have the '''main method'''.
  
 
|-
 
|-
| 05:16
+
|04:39
 
|So type '''main''' and then press ctrl+space to generate the''' main method.'''
 
|So type '''main''' and then press ctrl+space to generate the''' main method.'''
  
 
|-
 
|-
| 05:22
+
|04:46
| Now we need to print the Student Enrollment data.
+
|Now we need to print the '''Student Enrollment data'''.
  
 
|-
 
|-
| 05:27
+
|04:50
 
|We will create a few objects of''' StudentEnroll class''' to represent student enrollments.
 
|We will create a few objects of''' StudentEnroll class''' to represent student enrollments.
  
 
|-
 
|-
| 05:34
+
|04:57
|So type''' '''the following code. '''StudentEnroll s1 equals new StudentEnroll'''
+
|So type the following code ''' StudentEnroll s1 equals new StudentEnroll'''
  
 
|-
 
|-
| 05:41
+
|05:04
|Now we can pass the values of different arguments. Within brackets type''' IT101 '''as''' id, ADIL''' as''' name '''and''' IT''' as '''branch.'''
+
|Now we can pass the values of different '''arguments'''.
  
 
|-
 
|-
| 05:54
+
|05:08
|Now let us invoke the''' showData''' method to print the enrollment details. So type
+
|Within brackets type''' IT101 '''as''' id, ADIL''' as''' name '''and''' IT''' as '''branch.'''
  
'''s1.showData( )'''.
+
|-
 +
|05:17
 +
|Now let us invoke the''' showData''' method to print the enrollment details.  
  
 
|-
 
|-
| 06:03
+
| 05:22
|Now run the '''Demo''' program.
+
|So type '''s1.showData( )'''. Now run the '''Demo''' program
  
 
|-
 
|-
| 06:06
+
|05:29
 
|We can see that the values of the instance variables corresponding to''' s1''' get printed.
 
|We can see that the values of the instance variables corresponding to''' s1''' get printed.
  
 
|-
 
|-
| 06:13
+
|05:36
 
|Also note that the value of the number of student enrollments is 1.
 
|Also note that the value of the number of student enrollments is 1.
  
 
|-
 
|-
| 06:19
+
|05:42
|This is because we have created only 1 object.
+
|This is because we have created only 1 '''object'''.
  
 
|-
 
|-
| 06:23
+
|05:47
|Now type the following code to create one more object''' s2.'''
+
|Now type the following code to create one more '''object s2.'''
  
 
|-
 
|-
| 06:28
+
|05:52
|The''' showData''' method can be called once again using''' s2.'''
+
|The''' showData method''' can be called once again using''' s2.'''
  
 
|-
 
|-
| 06:33
+
|05:56
 
|Again run the '''Demo''' Program.
 
|Again run the '''Demo''' Program.
  
 
|-
 
|-
| 06:36
+
|05:59
 
|We can see that the values of the instance variables corresponding to''' s2''' get printed.
 
|We can see that the values of the instance variables corresponding to''' s2''' get printed.
  
 
|-
 
|-
| 06:43
+
|06:06
 
|Also note that the value of''' number of student''' enrollments is updated to 2 for both''' s1''' and''' s2.'''
 
|Also note that the value of''' number of student''' enrollments is updated to 2 for both''' s1''' and''' s2.'''
  
 
|-
 
|-
| 06:51
+
|06:14
|Now create one more object''' s3.'''
+
|Now create one more '''object s3.'''
  
 
|-
 
|-
| 06:54
+
|06:18
|Now Let us Invoke the''' showData''' method again using''' s3.'''
+
|Now let us Invoke the''' showData method''' again using''' s3.'''
  
 
|-
 
|-
| 07:00
+
|06:23
 
|Run the '''Demo''' Program again.
 
|Run the '''Demo''' Program again.
  
 
|-
 
|-
| 07:02
+
|06:26
|We can see that the values of the instance variables corresponding to''' s3''' get printed.
+
|We can see that the values of '''instance variables''' corresponding to''' s3''' get printed.
  
 
|-
 
|-
| 07:09
+
|06:32
|Also note that the value of''' '''number of student enrollments is now updated to 3 in all the cases.
+
|Also note that the value of''' number of student''' enrollments is now updated to 3 in all the cases.
  
 
|-
 
|-
| 07:17
+
|06:41
|Now we can understand that the value of the number of student enrollments is common to all the objects.
+
|Now we can understand that value of number of student enrollments is common to all the '''objects'''.
  
 
|-
 
|-
|07:25
+
|06:48
| Come back to slides. The''' static''' modifier, is also used along with the final modifier.
+
|Come back to slides.
  
 
|-
 
|-
| 07:33
+
|06:51
|It is done to define a''' constant''' which is common to the entire class.
+
|The''' static modifier''' is also used along with the '''final modifier'''.
 
+
 
 
|-
 
|-
| 07:38
+
|06:56
|Conventionally, the names of such constant variables are spelled in uppercase letters.
+
|It is done to define a''' constant''' which is common to the entire '''class'''.
  
 
|-
 
|-
|07:44
+
|07:01
| If the name is composed of more than one word, the words are separated by '''an underscore.'''
+
|Conventionally, the names of such '''constant variables''' are spelt in uppercase letters.
  
 
|-
 
|-
| 07:51
+
|07:08
|As an Example, if all the students are getting enrolled to the same organisation say''' IITB'''.
+
|Now come back to '''eclipse'''.
  
 
|-
 
|-
| 07:59
+
|07:11
|It can be represented by using a constant static variable say''' ORG_NAME'''.
+
|Open the '''StudentEnroll class''' and type the '''variable declaration''' as  '''public static final String ORG_NAME = “IITB”;'''
  
 
|-
 
|-
| 08:06
+
|07:23
|Usually we declare such constants with a '''public''' visibility.
+
|As an example, if all the students are getting enrolled to the same organisation, say''' IITB'''.
  
 
|-
 
|-
|08:11
+
|07:31
 +
|It can be represented by using a '''constant static variable''' say''' ORG_NAME.'''
  
| A Static variable can be accessed directly from another class by using its own class name.
+
|-
 
+
|07:38
For Example: StudentEnroll.ORG_NAME;
+
|If the name is composed of more than one word, the words are separated by an''' underscore.'''
  
 
|-
 
|-
| 08:24
+
|07:44
| Now come back to eclipse.
+
|Usually we declare such '''constants''' with a '''public '''visibility.
  
 
|-
 
|-
| 08:27
+
| 07:49
|Open the '''StudentEnroll''' class and type the variable declaration as '''public static final String ORG_NAME = “IITB”;'''
+
| Now go to the '''Demo class '''and type the following code.
+
|-
+
| 08:39
+
|Now go to the '''Demo class '''and type the following code
+
  
 
|-
 
|-
| 08:45
+
|07:55
|Here you can see that '''ORG_NAME '''is accessed by using its class name '''StudentEnroll.'''
+
|Here you can see that '''ORG_NAME '''is accessed by using its '''class''' name '''StudentEnroll.'''
  
 
|-
 
|-
| 08:53
+
| 08:03
|Now run the '''Demo''' Program again.
+
| Now run the '''Demo''' Program again.
  
 
|-
 
|-
| 08:56
+
|08:06
 
|We can see that the '''ORGANISATION''' name is getting printed as''' IITB.'''
 
|We can see that the '''ORGANISATION''' name is getting printed as''' IITB.'''
  
 
|-
 
|-
|09:01
+
|08:11
| Let us summarize. In this tutorial we have learnt about
+
|Let us summarize. In this tutorial we have learnt about
  
* What is a static variable and when it is used
+
|-
* How to create and invoke the static variables
+
|08:17
 +
| What is a '''static variable''' and when it is used
  
 
|-
 
|-
| 09:15
+
|08:21
| As an Assignment. Design a class''' CarService''' to represent a Car Service Station.
+
| How to create and invoke the '''static variables'''
  
 
|-
 
|-
| 09:22
+
|08:25
|This class should contain variables to represent the following details.
+
|As an Assignment. Design a '''class CarService''' to represent a Car Service Station.
  
 
|-
 
|-
| 09:27
+
|08:32
|'''Name''' of the Service Station. Car '''make''', '''model''' and '''reg. no''' - which are in for service.
+
|This '''class''' should contain variables to represent the following details:
 +
'''Name''' of the Service Station
  
'''No. of Cars in''' for Service.
+
|-
 +
|08:39
 +
|Car '''make''', '''model''' and '''register number''' - which are in for service
  
 
|-
 
|-
| 09:37
+
|08:44
|Identify the instance variables and static variables.
+
|'''No. of Cars in''' for Service
  
 
|-
 
|-
| 09:41
+
|08:47
|Declare them using suitable keywords.
+
|Identify the '''instance variables''' and '''static variables'''
  
 
|-
 
|-
| 09:45
+
|08:51
|Define a''' constructor''' to initialize the values for Car make, model and regno.
+
|Declare them using suitable keywords
  
 
|-
 
|-
| 09:51
+
|08:55
|Define a method''' show( )''' to print the values of all the variables.
+
|Define a''' constructor''' to initialise the values for Car '''make, model''' and '''register number'''
  
 
|-
 
|-
| 09:57
+
|09:01
|Also create a''' Demo''' class containing the main method to verify the results.
+
|Define a '''method show( )''' to print the values of all the variables
  
i.e Create a few objects of''' CarService.'''
+
|-
 +
|09:07
 +
|Also create a''' Demo class''' containing the '''main method''' to verify the results
 +
i.e Create a few '''objects''' of''' CarService'''
  
 
|-
 
|-
| 10:06
+
|09:16
|Invoke the''' show( ) '''method using these objects.
+
|Invoke the''' show( ) method''' using these '''objects'''
  
 
|-
 
|-
| 10:10
+
|09:20
|Also access the static variables directly using the class name.
+
|Also access the '''static variables''' directly using the '''class''' name.
  
 
|-
 
|-
|10:15
+
|09:25
| The video at the following link summarizes the Spoken Tutorial Project. Please download and watch it.
+
|The video at the following link summarizes the Spoken Tutorial Project. Please download and watch it.
  
 
|-
 
|-
| 10:22
+
|09:32
| The Spoken Tutorial Project Team
+
|The Spoken Tutorial Project Team Conducts workshops using spoken tutorials and
 
+
Gives certificates on passing the online tests
Conducts workshops using spoken tutorials and
+
 
+
Gives certificates on passing the online tests.
+
  
 
|-
 
|-
| 10:32
+
|09:41
 
|For more details, please write to us.
 
|For more details, please write to us.
  
 
|-
 
|-
|10:35
+
|09:45
| Spoken Tutorial Project is funded by the NMEICT, MHRD, Government of India.
+
|Spoken Tutorial Project is funded by the NMEICT, MHRD, Government of India.
  
 
|-
 
|-
| 10:41
+
|09:51
 
|More information on this Mission is available at the link shown.
 
|More information on this Mission is available at the link shown.
  
 
|-
 
|-
| 10:46
+
|09:56
| This script has been contributed by:
+
|This script has been contributed by: Department of Information Technology, Amal Jyothi College of Engineering
  
Department of Information Technology, Amal Jyothi College of Engineering.
+
|-
 
+
|10:03
This is Priya from IIT Bombay signing off. Thanks for joining.
+
|This is Priya from IIT Bombay signing off. Thanks for joining.
  
 
|}
 
|}

Revision as of 17:23, 13 January 2017

Time
Narration
00:01 Welcome to the Spoken Tutorial on Static Variables.
00:05 In this tutorial we will learn about: What are static variables
00:10 Creating static variables and How to use static variables
00:17 Here we are using Ubuntu 12.04, JDK 1.7 and Eclipse 4.3.1
00:27 To follow this tutorial, you must have knowledge of basics of Java and Eclipse IDE.
00:35 You should also have the knowledge of classes, objects and instance variables in Java.
00:42 If not, for relevant Java tutorials, please visit the link shown.
00:49 A static variable is a variable which is associated with the entire class.
00:55 It is also called a class variable.
00:58 It is declared using the static keyword.
01:02 We have seen about static variable briefly in the earlier tutorial.
01:08 In this tutorial we will see it in detail.
01:11 Now we will switch to Eclipse and create a new project called StaticVariableDemo.
01:18 Inside this project we will create the necessary classes to demonstrate the usage of Static variables.
01:26 So right click on src folder and click New -> Class, and type the name of the class as StudentEnroll and press Enter.
01:37 Let us illustrate the usage of static variables with an example.
01:42 Consider a class created to represent student enrollments in an organisation.
01:49 This class contains the Name, Id , Branch and Total Count of students enrolled.
01:56 Now let us visualize what happens when student enrollments are done.
02:02 By default Total Count is 0. The Name of the first student is ADIL.
02:09 Id is IT101. Branch is IT.
02:14 Now the Total Count is updated as 1.
02:18 Similarly when the second student AMAL gets enrolled, Total Count is updated to 2.
02:25 When the third student CAROL gets enrolled, Total Count is updated to 3.
02:32 Now we can identify that the variable Total Count is common to all the objects and has a single value.
02:40 So the variable Total Count can be represented as a static variable.
02:45 We can also see that the variables Name, Id and Branch have their own copies for each object.
02:54 Also they have specific values for each object.
02:59 So these variables can be treated as instance variables
03:04 Now let us look at the code representing the student enrollment class.
03:09 The instance variables are declared as id, name and branch.
03:16 The variable count is declared as static since it is common to the whole class.
03:22 When a class is loaded a static variable occupies a single fixed memory location.
03:28 Whereas Instance variables of each object occupy separate memory locations.
03:35 Now click on Source -> and select Generate Constructor using Fields,
03:41 Delete the super keyword from the generated code.
03:45 This constructor can initialise the values of the id, name and branch fields.
03:51 We also need to increment the value of the variable count by one every time an object is created.
03:59 So inside the constructor type- count ++ semicolon
04:05 Now we will add a method showData( ) to this class to print the the values of all the variables.
04:13 So type public void showData( ) within brackets type the following code to print the values of id, name, branch, and total number of students enrolled.
04:27 Now right-click on the default package and click on New -> Class and then type name as Demo.
04:36 Inside this class, we will have the main method.
04:39 So type main and then press ctrl+space to generate the main method.
04:46 Now we need to print the Student Enrollment data.
04:50 We will create a few objects of StudentEnroll class to represent student enrollments.
04:57 So type the following code StudentEnroll s1 equals new StudentEnroll
05:04 Now we can pass the values of different arguments.
05:08 Within brackets type IT101 as id, ADIL as name and IT as branch.
05:17 Now let us invoke the showData method to print the enrollment details.
05:22 So type s1.showData( ). Now run the Demo program
05:29 We can see that the values of the instance variables corresponding to s1 get printed.
05:36 Also note that the value of the number of student enrollments is 1.
05:42 This is because we have created only 1 object.
05:47 Now type the following code to create one more object s2.
05:52 The showData method can be called once again using s2.
05:56 Again run the Demo Program.
05:59 We can see that the values of the instance variables corresponding to s2 get printed.
06:06 Also note that the value of number of student enrollments is updated to 2 for both s1 and s2.
06:14 Now create one more object s3.
06:18 Now let us Invoke the showData method again using s3.
06:23 Run the Demo Program again.
06:26 We can see that the values of instance variables corresponding to s3 get printed.
06:32 Also note that the value of number of student enrollments is now updated to 3 in all the cases.
06:41 Now we can understand that value of number of student enrollments is common to all the objects.
06:48 Come back to slides.
06:51 The static modifier is also used along with the final modifier.
06:56 It is done to define a constant which is common to the entire class.
07:01 Conventionally, the names of such constant variables are spelt in uppercase letters.
07:08 Now come back to eclipse.
07:11 Open the StudentEnroll class and type the variable declaration as public static final String ORG_NAME = “IITB”;
07:23 As an example, if all the students are getting enrolled to the same organisation, say IITB.
07:31 It can be represented by using a constant static variable say ORG_NAME.
07:38 If the name is composed of more than one word, the words are separated by an underscore.
07:44 Usually we declare such constants with a public visibility.
07:49 Now go to the Demo class and type the following code.
07:55 Here you can see that ORG_NAME is accessed by using its class name StudentEnroll.
08:03 Now run the Demo Program again.
08:06 We can see that the ORGANISATION name is getting printed as IITB.
08:11 Let us summarize. In this tutorial we have learnt about
08:17 What is a static variable and when it is used
08:21 How to create and invoke the static variables
08:25 As an Assignment. Design a class CarService to represent a Car Service Station.
08:32 This class should contain variables to represent the following details:

Name of the Service Station

08:39 Car make, model and register number - which are in for service
08:44 No. of Cars in for Service
08:47 Identify the instance variables and static variables
08:51 Declare them using suitable keywords
08:55 Define a constructor to initialise the values for Car make, model and register number
09:01 Define a method show( ) to print the values of all the variables
09:07 Also create a Demo class containing the main method to verify the results

i.e Create a few objects of CarService

09:16 Invoke the show( ) method using these objects
09:20 Also access the static variables directly using the class name.
09:25 The video at the following link summarizes the Spoken Tutorial Project. Please download and watch it.
09:32 The Spoken Tutorial Project Team Conducts workshops using spoken tutorials and
Gives certificates on passing the online tests
09:41 For more details, please write to us.
09:45 Spoken Tutorial Project is funded by the NMEICT, MHRD, Government of India.
09:51 More information on this Mission is available at the link shown.
09:56 This script has been contributed by: Department of Information Technology, Amal Jyothi College of Engineering
10:03 This is Priya from IIT Bombay signing off. Thanks for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14