Visual Cue
|
Narration
|
Slide 1
|
Welcome to the spoken tutorial on Creating Classes
|
Slide 2
Learning Objectives
|
In this tutorial, we will learn about
- A class in real world
- A class in Java
- Structure of a Java class
- Syntax for a Java class
- A simple example of Java class
|
Slide 3
System Requirements
|
Here we are using
- Ubuntu version 11.10
- JDK 1.6
- Eclipse 3.7.0
|
Slide 4
Prerequisite
|
To follow this tutorial you must know how to write, compile and run a simple Java program in Eclipse.
If not, please see the spoken-tutorial on these topics available at spoken-tutorial.org.
|
Slide 5
A class in real world
|
Now let us see what is a class in real world.
Whatever we can see in this world are all objects.
All the objects can be categorized into special groups.
Each group is termed as a class.
For example human being is a class.
We are all different objects of this class.
We all have different properties like eyes, legs, hands etc.
These are common to the human being class.
Seeing, eating, walking etc are behaviors that are common to the human being class.
|
Slide 6
A class in Java
|
A class is the blueprint from which individual objects are created.
|
Slide 7
Structure of a Java Class
|
A class defines:
A set of properties called variables
A set of behaviors called methods.
|
Slide 8
|
Now, let us see the syntax for declaring classes
modifier – class -classname within brackets variable, constructor and method declarations.
We will learn about these in detail in the coming tutorials.
|
Switch to eclipse
Click on File>> New>> Java Project
|
Let us now create a simple class using Eclipse.
I have already opened Eclipse.
Now let us create a Project.
So click on File, go to New and click on Java Project.
|
Point to New Project Wizard
Type ClassDemo.
Click Finish.
|
In the New Project Wizard, enter the Project name as ClassDemo with C and D in capital.
Then click on Finish.
|
Point to the Project ClassDemo.
|
We see that the Project ClassDemo is created.
|
So, right click on ClassDemo.
Go to New-> Class
Type Name as Student
Select public static void main.
Click Finish.
|
We will now create a Java class Student.
So right click on ClassDemo, go to New and click on Class.
In the New Java Class wizard type the Name as Student.
We can see that the modifier here is public.
This shows that the class is visible to all the classes everywhere.
If a class has no modifier which is the default , it is visible only within its own package.
We will learn about packages in the later tutorials.
Now, here I have selected public.
In the method stubs select public static void main.
Then click on Finish.
We can see that class named Student is created.
Now, let me remove the comments.
|
public class Student {
int roll_no;
String name;
void studentDetail() {
System.out.println(“The roll number is” + roll_no);
System.out.println(“The name is” + name);
}
public static void main(String[] args) {
System.out.println(“We have created a class with 2 variables and 1 method”);
}
}
|
A Student class can contain properties like Name, Roll Number, Marks etc.
So inside this class Student let me declare two variables Roll Number and Name.
So, I will type int roll underscore number semicolon.
Then String name semicolon.
So I have declared two variables.
Now a class also contains methods.
So let me create a method named StudentDetail.
This method will give the detail of each student.
So let me type void studentDetail opening and closing brackets, curly brackets open.
Now, this method will give the name and roll number of the Student.
So, type System dot out dot println within brackets and double quotes The roll number is plus roll underscore number semicolon.
Next line type System dot out dot println within brackets and double quotes The name is plus name and semicolon.
Now, inside the main method we will type System dot out dot println within brackets and double quotes We have created a class with two variables and 1 method.
Now, save the file by pressing Control and S keys simultaneously.
Run the program by pressing Control and F11 keys simultaneously.
|
Highlight the output
|
We get the output as :
We have created a class with 2 variables and 1 method
just as we had typed in the main method.
Thus we have successfully created a class.
|
Slide 9
Summary
|
So, in this tutorial we learnt about a class in java and how to create a class in java.
|
Slide 10
|
For self assessment create a class named Employee with variables emp underscore number and emp underscore name .
Method printEmployee which displays the Employee information.
|
Slide 11
|
Watch the video available at http://spoken-tutorial.org/What_is_a_Spoken_Tutorial
- It summarises the Spoken Tutorial project
- If you do not have good bandwidth, you can download and watch it
|
Slide 12
|
The Spoken Tutorial Project Team
- Conducts workshops using spoken tutorials
- Gives certificates for those who pass an online test
- For more details, please write to contact@spoken-tutorial.org
|
Slide 13
|
Spoken Tutorial Project is a part of the Talk to a Teacher project
|
Slide 14
|
We come to the end of this tutorial.
Thanks for joining us.
This is Arya Ratish signing off.
Good bye and Jai Hind.
|
|
|
|
|
|
|
|
|
|
|
|
|