Difference between revisions of "Java/C2/Numerical-Datatypes/English-timed"
From Script | Spoken-Tutorial
Sandhya.np14 (Talk | contribs) |
|||
Line 19: | Line 19: | ||
| 00:13 | | 00:13 | ||
| How to use them to '''store numerical data.''' | | How to use them to '''store numerical data.''' | ||
− | |||
− | |||
|- | |- | ||
| 00:18 | | 00:18 | ||
| For this tutorial we are using | | For this tutorial we are using | ||
− | |||
* '''Ubuntu 11.10''', | * '''Ubuntu 11.10''', | ||
* '''JDK 1.6''' and | * '''JDK 1.6''' and | ||
* '''Eclipse 3.7.0''' | * '''Eclipse 3.7.0''' | ||
− | |||
− | |||
|- | |- | ||
| 00:27 | | 00:27 | ||
| To follow this tutorial, you must '''know how to write and run a simple java program in Eclipse'''. | | To follow this tutorial, you must '''know how to write and run a simple java program in Eclipse'''. | ||
− | |||
|- | |- | ||
| 00:34 | | 00:34 | ||
| If not, for relevant tutorial please visit our website as shown | | If not, for relevant tutorial please visit our website as shown | ||
− | |||
− | |||
− | |||
|- | |- | ||
| 00:42 | | 00:42 | ||
| The data type used to store integers is called '''int''' | | The data type used to store integers is called '''int''' | ||
− | |||
|- | |- | ||
| 00:47 | | 00:47 | ||
| The data type used to store decimal numbers is called '''float.''' | | The data type used to store decimal numbers is called '''float.''' | ||
− | |||
|- | |- | ||
Line 65: | Line 54: | ||
| 01:10 | | 01:10 | ||
| We have created a class '''NumericalData''' and added the main method to it. | | We have created a class '''NumericalData''' and added the main method to it. | ||
− | |||
|- | |- | ||
Line 74: | Line 62: | ||
| 01:20 | | 01:20 | ||
| '''int distance''' ''equal to '''''28''' | | '''int distance''' ''equal to '''''28''' | ||
− | |||
|- | |- | ||
Line 83: | Line 70: | ||
| 01:33 | | 01:33 | ||
| The name '''distance''' is called an integer variable. | | The name '''distance''' is called an integer variable. | ||
− | |||
|- | |- | ||
Line 92: | Line 78: | ||
| 01:47 | | 01:47 | ||
| '''System '''''dot '''''out '''''dot '''''println. In parentheses '''distance.''' | | '''System '''''dot '''''out '''''dot '''''println. In parentheses '''distance.''' | ||
− | |||
|- | |- | ||
Line 105: | Line 90: | ||
| 02:14 | | 02:14 | ||
| We can see that the value ''' 28''' has been stored in distance and it has been printed. | | We can see that the value ''' 28''' has been stored in distance and it has been printed. | ||
− | |||
|- | |- | ||
Line 114: | Line 98: | ||
| 02:25 | | 02:25 | ||
| change '''28''' to '''24''' | | change '''28''' to '''24''' | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 129: | Line 110: | ||
| 02:39 | | 02:39 | ||
|'''int '''can also store negative values. | |'''int '''can also store negative values. | ||
− | |||
|- | |- | ||
| 02:42 | | 02:42 | ||
| Change 24 to ''minus'' 25 | | Change 24 to ''minus'' 25 | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 149: | Line 126: | ||
| 03:02 | | 03:02 | ||
| The Data type '''int '''is enough for most of our programming needs. | | The Data type '''int '''is enough for most of our programming needs. | ||
− | |||
|- | |- | ||
| 03:06 | | 03:06 | ||
| But it can only store values up to a limit. | | But it can only store values up to a limit. | ||
− | |||
|- | |- | ||
Line 167: | Line 142: | ||
| 03:34 | | 03:34 | ||
| The error message says,the number is out of range for a variable of the type '''int''' | | The error message says,the number is out of range for a variable of the type '''int''' | ||
− | |||
|- | |- | ||
Line 176: | Line 150: | ||
| 03:49 | | 03:49 | ||
| To store large numbers, Java provides the '''long''' data type. | | To store large numbers, Java provides the '''long''' data type. | ||
− | |||
|- | |- | ||
Line 189: | Line 162: | ||
| 04:04 | | 04:04 | ||
| add a capital '''L''' at the end of the number. | | add a capital '''L''' at the end of the number. | ||
− | |||
|- | |- | ||
| 04:11 | | 04:11 | ||
| Save it with''' Ctrl, S''' | | Save it with''' Ctrl, S''' | ||
− | |||
|- | |- | ||
| 04:16 | | 04:16 | ||
| We see that now there is no error. | | We see that now there is no error. | ||
− | |||
|- | |- | ||
| 04:19 | | 04:19 | ||
| Let us run it with '''Ctrl, F11'''. The value has been printed | | Let us run it with '''Ctrl, F11'''. The value has been printed | ||
− | |||
|- | |- | ||
Line 213: | Line 182: | ||
| 04:32 | | 04:32 | ||
| Now let us store a decimal number in a '''int '''variable. | | Now let us store a decimal number in a '''int '''variable. | ||
− | |||
|- | |- | ||
Line 222: | Line 190: | ||
| 04:50 | | 04:50 | ||
| As we can see, there is an error. That is because '''int '''can only store integers. | | As we can see, there is an error. That is because '''int '''can only store integers. | ||
− | |||
|- | |- | ||
Line 231: | Line 198: | ||
| 05:05 | | 05:05 | ||
| change the data type to '''float.''' | | change the data type to '''float.''' | ||
− | |||
|- | |- | ||
Line 240: | Line 206: | ||
| 05:17 | | 05:17 | ||
| save it. | | save it. | ||
− | |||
|- | |- | ||
| 05:19 | | 05:19 | ||
| We see that now their is no error. | | We see that now their is no error. | ||
− | |||
|- | |- | ||
Line 258: | Line 222: | ||
| 05:37 | | 05:37 | ||
| Now let us change the value of the variable distance | | Now let us change the value of the variable distance | ||
− | |||
|- | |- | ||
Line 267: | Line 230: | ||
| 05:53 | | 05:53 | ||
| '''Save''' it and''' Run''' it | | '''Save''' it and''' Run''' it | ||
− | |||
− | |||
|- | |- | ||
| 06:01 | | 06:01 | ||
| we see, that the output is little different from what has been stored. | | we see, that the output is little different from what has been stored. | ||
− | |||
|- | |- | ||
| 06:06 | | 06:06 | ||
| This happens because there is a limit to the precision of a floating point number. | | This happens because there is a limit to the precision of a floating point number. | ||
− | |||
|- | |- | ||
Line 287: | Line 246: | ||
| 06:18 | | 06:18 | ||
| Now let us see the naming rules for variables. | | Now let us see the naming rules for variables. | ||
− | |||
|- | |- | ||
| 06:23 | | 06:23 | ||
| Add a number '''2''' before the name. | | Add a number '''2''' before the name. | ||
− | |||
|- | |- | ||
| 06:30 | | 06:30 | ||
| we see that, there is a '''syntax error.''' | | we see that, there is a '''syntax error.''' | ||
− | |||
|- | |- | ||
| 06:34 | | 06:34 | ||
| This is because a variable name must only start with an '''alphabet''' or an '''underscore'''. | | This is because a variable name must only start with an '''alphabet''' or an '''underscore'''. | ||
− | |||
|- | |- | ||
Line 311: | Line 266: | ||
| 06:45 | | 06:45 | ||
| Now let us add '''the number ''' at the end of the variable name. | | Now let us add '''the number ''' at the end of the variable name. | ||
− | |||
|- | |- | ||
| 06:55 | | 06:55 | ||
| We see that, there is no error. | | We see that, there is no error. | ||
− | |||
|- | |- | ||
Line 328: | Line 281: | ||
| 07:15 | | 07:15 | ||
| we see that there is no error. | | we see that there is no error. | ||
− | |||
|- | |- | ||
| 07:17 | | 07:17 | ||
| Which means an underscore is permitted in a variable name. | | Which means an underscore is permitted in a variable name. | ||
− | |||
|- | |- | ||
| 07:22 | | 07:22 | ||
| But any other''' punctuation''' in a variable name that give an syntax error or other errors. | | But any other''' punctuation''' in a variable name that give an syntax error or other errors. | ||
− | |||
|- | |- | ||
Line 363: | Line 313: | ||
| 07:51 | | 07:51 | ||
| As an assignment for this tutorial, | | As an assignment for this tutorial, | ||
− | |||
|- | |- | ||
Line 372: | Line 321: | ||
| 07:56 | | 07:56 | ||
|see how they are different from int and float. | |see how they are different from int and float. | ||
− | |||
|- | |- | ||
Line 384: | Line 332: | ||
|- | |- | ||
| 08:11 | | 08:11 | ||
− | | It | + | | It summarizes the Spoken Tutorial project |
|- | |- | ||
| 08:14 | | 08:14 | ||
| If you do not have good bandwidth, you can download and watch it | | If you do not have good bandwidth, you can download and watch it | ||
− | |||
|- | |- | ||
| 08:20 | | 08:20 | ||
| The Spoken Tutorial Project Team. Conducts workshops using '''spoken tutorials'''. | | The Spoken Tutorial Project Team. Conducts workshops using '''spoken tutorials'''. | ||
− | |||
|- | |- | ||
Line 403: | Line 349: | ||
| 08:35 | | 08:35 | ||
| '''Spoken Tutorial '''Project is a part of the '''Talk to a Teacher''' project. | | '''Spoken Tutorial '''Project is a part of the '''Talk to a Teacher''' project. | ||
− | |||
|- | |- | ||
| 08:39 | | 08:39 | ||
|It supported by the '''National Mission on Education through ICT, MHRD, Government of India. ''' | |It supported by the '''National Mission on Education through ICT, MHRD, Government of India. ''' | ||
− | |||
|- | |- | ||
Line 417: | Line 361: | ||
| 08:51 | | 08:51 | ||
| This tutorial has been contributed by '''TalentSprint'''. Thanks for joining. | | This tutorial has been contributed by '''TalentSprint'''. Thanks for joining. | ||
− | |||
− | |||
− | |||
|} | |} |
Revision as of 14:28, 20 March 2015
Time | Narration |
00:01 | Welcome to the spoken tutorial on Numerical Datatypes in Java. |
00:07 | In this tutorial, we will learn about: |
00:10 | The various Numerical Datatypes available in Java and |
00:13 | How to use them to store numerical data. |
00:18 | For this tutorial we are using
|
00:27 | To follow this tutorial, you must know how to write and run a simple java program in Eclipse. |
00:34 | If not, for relevant tutorial please visit our website as shown |
00:42 | The data type used to store integers is called int |
00:47 | The data type used to store decimal numbers is called float. |
00:52 | Let us define and use integers first. |
01:02 | Here, we have the Eclipse IDE and the skeleton required for the rest of the code. |
01:10 | We have created a class NumericalData and added the main method to it. |
01:15 | Now let us see how to store a number. |
01:20 | int distance equal to 28 |
01:27 | This statement stores the integer value in the name distance. |
01:33 | The name distance is called an integer variable. |
01:37 | Now we shall use the variable distance to print the value stored in it. |
01:47 | System dot out dot println. In parentheses distance. |
02:01 | This statement prints the value of the variable distance |
02:06 | Save the file and Run it |
02:14 | We can see that the value 28 has been stored in distance and it has been printed. |
02:21 | Now let us change the value stored in the variable. |
02:25 | change 28 to 24 |
02:29 | Save and Run |
02:34 | We see that the output has changed accordingly. |
02:39 | int can also store negative values. |
02:42 | Change 24 to minus 25 |
02:48 | Save and Run '. |
02:56 | As we can see, even negative values can be stored in variables of the type int. |
03:02 | The Data type int is enough for most of our programming needs. |
03:06 | But it can only store values up to a limit. |
03:10 | Let us try to store a large value and see what happens. |
03:25 | As we can see, there is a red line below the number which indicates an error. |
03:34 | The error message says,the number is out of range for a variable of the type int |
03:42 | int takes 32 bits of memory and can store values only from -2 power 31 to 2 power 31. |
03:49 | To store large numbers, Java provides the long data type. |
03:54 | Let us use it to store a large value. |
03:59 | Change int to long and |
04:04 | add a capital L at the end of the number. |
04:11 | Save it with Ctrl, S |
04:16 | We see that now there is no error. |
04:19 | Let us run it with Ctrl, F11. The value has been printed |
04:27 | We can see that large numbers can be stored in a long variable. |
04:32 | Now let us store a decimal number in a int variable. |
04:37 | Change long to int and change the number to 23.5; |
04:50 | As we can see, there is an error. That is because int can only store integers. |
05:00 | To store decimal numbers, we have to use float. |
05:05 | change the data type to float. |
05:10 | And add an f at the end of the value. |
05:17 | save it. |
05:19 | We see that now their is no error. |
05:22 | run it with Control F11 |
05:29 | As we can see, the decimal value has been stored and the value has been printed. |
05:37 | Now let us change the value of the variable distance |
05:46 | Add a lot of numbers after the decimal point as shown. |
05:53 | Save it and Run it |
06:01 | we see, that the output is little different from what has been stored. |
06:06 | This happens because there is a limit to the precision of a floating point number. |
06:11 | It is rounded off to the closest possible number if it cannot be stored accurately. |
06:18 | Now let us see the naming rules for variables. |
06:23 | Add a number 2 before the name. |
06:30 | we see that, there is a syntax error. |
06:34 | This is because a variable name must only start with an alphabet or an underscore. |
06:40 | But generally underscore is not used to start a variable name. |
06:45 | Now let us add the number at the end of the variable name. |
06:55 | We see that, there is no error. |
06:59 | A variable name can have digits but not at the beginning. |
07:04 | Now add an 'underscore' in the middle of the name |
07:15 | we see that there is no error. |
07:17 | Which means an underscore is permitted in a variable name. |
07:22 | But any other punctuation in a variable name that give an syntax error or other errors. |
07:28 | This is how you store numerical data in Java. |
07:35 | This brings us to the end of the tutorial. |
07:38 | In this tutorial we have learnt about the various numerical datatypes. |
07:44 | And How tostore numerical data. |
07:46 | And We have also learnt the rules for naming a variable. |
07:51 | As an assignment for this tutorial, |
07:53 | Read about other numerical data types and |
07:56 | see how they are different from int and float. |
08:00 | Java tutorials are available at the following link. |
08:05 | To know more about the Spoken Tutorial project, watch the video available at the following link. [1] |
08:11 | It summarizes the Spoken Tutorial project |
08:14 | If you do not have good bandwidth, you can download and watch it |
08:20 | The Spoken Tutorial Project Team. Conducts workshops using spoken tutorials. |
08:24 | Gives certificates to those who pass an online test. For more details, please write to contact AT spoken HYPHEN tutorial DOT org. |
08:35 | Spoken Tutorial Project is a part of the Talk to a Teacher project. |
08:39 | It supported by the National Mission on Education through ICT, MHRD, Government of India. |
08:45 | More information on this Mission is available at the following link. |
08:51 | This tutorial has been contributed by TalentSprint. Thanks for joining. |