Java/C2/Numerical-Datatypes/English
Title of script: Numerical Datatypes in Java
Author: TalentSprint
Keywords: datatype, int, float, numerical data, video tutorial
Visual Cue | Description |
Slide 1
Welcome |
Welcome to the spoken tutorial on Numerical Datatypes in Java. |
Slide 2
Learning Outcomes |
In this tutorial, we will learn about:
|
Slide 3
Tools Used |
For this tutorial we are using
|
Slide 4
Prerequisites |
To follow this tutorial, you must know how to write and run a simple java program in Eclipse.
|
Slide 5
Numerical Datatypes |
The data type used to store integers is called int
|
Minimize slides and switch to Eclipse.
It should contain the following code. Public class NumericalData { public static void main(String[] args) { } } |
Here, we have the Eclipse IDE and skeleton required for the rest of the code. |
Point to the class NumericalData and main method | We have created a class NumericalData and added the main method to it.
|
Type the following code in the main method.
int distance = 28; |
int distance equal to 28
|
Point to the distance | The name distance is called an integer variable.
|
Type the following code after int...
System.out.println(distance); |
System dot out dot println. In parantheses distance.
|
Save and Run the code. | Save the file and Run it
|
Point to the output console | We can see that the value 28 has been stored in distance and it has been printed.
|
Change distance = 28 to distance = 24 | change 28 to 24
|
Save and run the file. | Save and Run
|
Point to the output. | We see that the output has changed accordingly. |
Replace distance = 24 with
distance = -25 |
int can also store negative values.
|
Save and run the code | Save and Run '. |
Point to the output | As we can see, even negative values can be stored in variables of the type int. |
Change distance = 24 to distance = 9876543210 | The Data type int is enough for most of our programming needs.
|
Point to the red line | As we can see, there is a red line below the number which indicates an error. |
Point to the cross mark on the left | The error message says the number is out of range for a variable of the type int
|
To store large numbers, Java provides the long data type.
| |
Change the int to long
|
Change the int to long and
add a capital L at the end of the number.
|
Change long distance = … to int distance = 23.5; | Now let us store a decimal number in a int variable.
|
Point to the error. | As we can see, there is an error. That is because int can only store integers.
|
Change int distance... to float distance
|
change the data type to float.
|
Save and Run. | save it.
|
Point to output | As we can see, the decimal value has been stored and the value has been printed. |
Change 23.5f to 23.123456789f | Now let us change the value of the variable distance
|
Save and Run. | Save it and Run it
|
Point to Output. | we see, that the output is little different from what has been stored.
|
Change distance to 2distance
|
Now let us see the naming rules for variables.
we see that, there is a syntax error.
|
Change 2distance to distance2 | now Let us add a 2 at the end of the variable name.
|
Change distance2 to dist_from | Now add an underscore in the middle of the name
we see that there is no error.
|
Minimize the Eclipse window and switch to slides.
Summary |
This brings us to the end of this tutorial.
In this tutorial we have learnt about the various numerical datatypes. How to use them to store numerical data. We have learnt the rules for naming a variable. |
Slide 7Assignment
|
As an assignment for this tutorial,
see how they are different from int and float.
|
Slide 8About the Spoken Tutorial Project
|
To know more about the Spoken Tutorial project, watch the video available at the following link.
|
Slide 9Spoken Tutorial WorkshopsThe Spoken Tutorial Project Team
|
The Spoken Tutorial Project Team. Conducts workshops using spoken tutorials.
|
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.
|