Java/C2/Relational-Operations/English
Title of script: Relational Operators in Java
Author: TalentSprint
Keywords: boolean, comparison, relational operator, video tutorial
Visual Cue | Description |
Slide 1
Welcome |
Welcome to the spoken tutorial on Relational Operators in Java. |
Slide 2
Learning Outcomes |
In this tutorial, we will learn about the
|
Slide 3
Tools Used |
For this tutorial we are using
Ubuntu 11.10, JDK 1.6 and Eclipse 3.7 |
Slide 4
Prerequisites |
To follow this tutorial, you must have knowledge of data types in Java
website as shown. |
Slide 5
Boolean data type |
Relational operators are used to check for conditions.
|
Slide 6
Relational Operators |
Here is a list of the Relational operators available.
We shall look into each of them in detail. |
Switch to Eclipse. | |
Minimize Slides and open Eclipse
Eclipse should contain the following code public class BooleanDemo{ public static void main(String[] args){ } } |
Here we have the Eclipse IDE and the skeleton required for the rest of the code.
|
In the main method, type
boolean b; Highlight boolean b
|
Type boolean b;
|
In the next line, type
b = weight > 40; System.out.println(b);
|
We shall define a variable weight and check for a condition using that variable.
|
Point to output | As we can see, the output is True. |
Change 45 to 30 | Let us see what happens if the value is less than 40.
|
We can see that the output is False as expected. | |
Highlight > symbol. | This way, the greater than symbol is used to check if one value is greater than the other.
|
Change weight > 40 to weight < 40
Highlight the condition.
|
let us change greater than to less than symbol.
So We are checking if the value of weight is less than 40.
Save Run |
Point to output
Save and Run |
As we can see, the output is True as expected.
|
We see that we get a False because the condition,
| |
Change weight < 40 to weight == 40
|
To do that, we use two equal to symbols.
|
As we can see, the output is False because the value of weight is not equal to 40. | |
Now let us change the weight to 40 and see the output.
Save and Run. | |
Point to output
|
As we can see, the output is True
|
Change weight == 40 to weight <= 40
Save and Run. |
Next we'll see how to check for less than or equal to.
change the double equal to to less than equal to.
|
Point to output | the output is True as expected.
|
Change weight = 40 to weight = 30
Save and Run. Point to output |
Change 40 to 30.
Save and Run.
|
Change 40 to 50. | Let say 50
Save and Run. |
As we can see, the output is False because the value of weight is not equal to 40.
| |
Similarly we use a greater than symbol followed by an equal to symbol for checking greater than or equal to.
| |
Change weight <= 40 to weight >= 40 | Change less than equal to to greater than equal to
|
Change 45 to 30 | Let us change weight to a value less than 40. Lets say 30.
|
We get a false because the value of weight is not greater than 40 and also not equal to 40. | |
Change weight >= 40 to weight != 40
Save and Run.
|
Next, we’ll see how to check for not equal to
|
Point to output | As we can see, the output is true because the values of weight is not equal to 40. |
Let us change the weight to 40 and see the output.
Change 30to 40. Save. Run. | |
We get a false because the condition weight not equal to 40 is false. | |
The not equal to condition can be thought of as opposite of equal to condition. | |
This is how we use the various relational operators to compare data in Java. | |
Minimize the Eclipse window and switch to slides.
Summary |
This brings us to the end of this tutorial.
about the boolean data type The relational operators and how to use relational operators to compare two values |
Slide 7Assignment
|
As an assignment for this tutorial, find out if the two expressions shown are equivalent? |
Slide 8About the Spoken Tutorial Project
|
To know more about the Spoken Tutorial project,
|
Slide 9Spoken Tutorial WorkshopsThe Spoken Tutorial Project Team
|
The Spoken Tutorial Project Team,
|
Slide 10Acknowledgement
|
Spoken Tutorial Project is a part of the Talk to a Teacher project.
|
Slide 11About the contributor
|
This tutorial has been contributed by TalentSprint. Thanks for joining.
|