Difference between revisions of "Java/C2/Numerical-Datatypes/English"
(Created page with ''''Title of script''': Numerical Datatypes in Java '''Author''': TalentSprint '''Keywords: '''datatype, int, float, numerical data, video tutorial {| style="border-spacing:0…') |
|||
Line 5: | Line 5: | ||
'''Keywords: '''datatype, int, float, numerical data, video tutorial | '''Keywords: '''datatype, int, float, numerical data, video tutorial | ||
− | + | ||
{| style="border-spacing:0;" | {| style="border-spacing:0;" | ||
Line 21: | Line 21: | ||
'''Learning Outcomes''' | '''Learning Outcomes''' | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| In this tutorial, | + | | style="border:0.035cm solid #000000;padding:0.097cm;"| In this tutorial, we will learn about: |
* the various '''Numerical Datatypes '''available in '''Java''' and | * the various '''Numerical Datatypes '''available in '''Java''' and | ||
Line 80: | Line 80: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.097cm;"| Point to the '''class NumericalData '''and''' main '''method | | style="border:0.035cm solid #000000;padding:0.097cm;"| Point to the '''class NumericalData '''and''' main '''method | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| We have created a class '''NumericalData''' and added the main method to it. | + | | style="border:0.035cm solid #000000;padding:0.097cm;"| We have created a class '''NumericalData''' and added the main method to it. |
Line 96: | Line 96: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.097cm;"| Point to the '''distance''' | | style="border:0.035cm solid #000000;padding:0.097cm;"| Point to the '''distance''' | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| The name '''distance''' is called | + | | style="border:0.035cm solid #000000;padding:0.097cm;"| The name '''distance''' is called an integer variable. |
Line 112: | Line 112: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.097cm;"| Save and Run the code. | | style="border:0.035cm solid #000000;padding:0.097cm;"| Save and Run the code. | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| | + | | style="border:0.035cm solid #000000;padding:0.097cm;"| '''Save''' the file and '''Run''' it |
Line 140: | Line 140: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.176cm;"| Point to the output. | | style="border:0.035cm solid #000000;padding:0.176cm;"| Point to the output. | ||
− | | style="border:0.035cm solid #000000;padding:0.176cm;"| We | + | | style="border:0.035cm solid #000000;padding:0.176cm;"| We see that the output has changed accordingly. |
|- | |- | ||
Line 156: | Line 156: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.176cm;"| Save and run the code | | style="border:0.035cm solid #000000;padding:0.176cm;"| Save and run the code | ||
− | | style="border:0.035cm solid #000000;padding:0.176cm;"| '''Save''' | + | | style="border:0.035cm solid #000000;padding:0.176cm;"| '''Save''' and '''Run ''''. |
|- | |- | ||
Line 164: | Line 164: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.097cm;"| Change '''distance = 24''' to '''distance = 9876543210''' | | style="border:0.035cm solid #000000;padding:0.097cm;"| Change '''distance = 24''' to '''distance = 9876543210''' | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| Data type '''int '''is enough for most of our programming needs. | + | | style="border:0.035cm solid #000000;padding:0.097cm;"|The Data type '''int '''is enough for most of our programming needs. |
Line 188: | Line 188: | ||
− | Let use It to store a large value. | + | Let us use It to store a large value. |
|- | |- | ||
Line 195: | Line 195: | ||
Change '''9876543210''' to '''9876543210L''' | Change '''9876543210''' to '''9876543210L''' | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| | + | | style="border:0.035cm solid #000000;padding:0.097cm;"| Change the '''int '''to '''long''' and |
− | add a | + | add a capital '''L''' at the end of the number. |
− | Save it | + | Save it with''' Ctrl S''' |
Line 206: | Line 206: | ||
− | Let us run it. | + | Let us run it with '''Ctrl F11'''. The value has been printed |
Line 237: | Line 237: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.097cm;"| '''Save''' and '''Run'''. | | style="border:0.035cm solid #000000;padding:0.097cm;"| '''Save''' and '''Run'''. | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| | + | | style="border:0.035cm solid #000000;padding:0.097cm;"| save it. |
Line 251: | Line 251: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.097cm;"| Change '''23.5f''' to '''23.123456789f''' | | style="border:0.035cm solid #000000;padding:0.097cm;"| Change '''23.5f''' to '''23.123456789f''' | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| Now let us change the value of | + | | style="border:0.035cm solid #000000;padding:0.097cm;"| Now let us change the value of the variable distance |
Line 258: | Line 258: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.176cm;"| '''Save''' and '''Run'''. | | style="border:0.035cm solid #000000;padding:0.176cm;"| '''Save''' and '''Run'''. | ||
− | | style="border:0.035cm solid #000000;padding:0.176cm;"| Save it | + | | style="border:0.035cm solid #000000;padding:0.176cm;"| Save it and Run it |
− | + | ||
− | + | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.176cm;"| Point to '''Output'''. | | style="border:0.035cm solid #000000;padding:0.176cm;"| Point to '''Output'''. | ||
− | | style="border:0.035cm solid #000000;padding:0.176cm;"| | + | | style="border:0.035cm solid #000000;padding:0.176cm;"| we see, that the output is little different from what has been stored. |
Line 284: | Line 283: | ||
− | + | we see that, there is a '''syntax error.''' | |
Line 294: | Line 293: | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.097cm;"| Change '''2distance''' to '''distance2''' | | style="border:0.035cm solid #000000;padding:0.097cm;"| Change '''2distance''' to '''distance2''' | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| Let us add a '''2''' at the end of the name. | + | | style="border:0.035cm solid #000000;padding:0.097cm;"|now Let us add a '''2''' at the end of the variable name. |
Line 300: | Line 299: | ||
− | A variable name can have digits but not at the beginning. | + | A variable name can have digits but not at the beginning. |
− | + | ||
|- | |- | ||
| style="border:0.035cm solid #000000;padding:0.097cm;"| Change '''distance2''' to '''dist_from''' | | style="border:0.035cm solid #000000;padding:0.097cm;"| Change '''distance2''' to '''dist_from''' | ||
− | | style="border:0.035cm solid #000000;padding:0.097cm;"| | + | | style="border:0.035cm solid #000000;padding:0.097cm;"| Now add an underscore in the middle of the name |
− | + | ||
− | + | we see that there is no error. | |
− | + | Which means an underscore is permitted in a variable name | |
− | But any other punctuation in a variable | + | But any other punctuation in a variable that give an syntax error or other errors. |
Revision as of 09:50, 8 May 2013
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.
|