Java/C2/Numerical-Datatypes/English-timed
From Script | Spoken-Tutorial
Revision as of 16:55, 20 March 2015 by Sandhya.np14 (Talk | contribs)
Time | Narration |
00:01 | Welcome to the spoken tutorial on Numerical Data types in Java. |
00:07 | In this tutorial, we will learn about: |
00:10 | * The various Numerical Data types 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 tutorials, 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 (-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 might give a 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 data types |
07:44 | and how to store 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. |