Difference between revisions of "Java/C2/User-Input/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(5 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
|-
 
|-
 
|  00:02
 
|  00:02
| Welcome to the spoken-tutorial on '''Taking user input''' in '''Java''' '''using BufferedReader''' .
+
| Welcome to the spoken-tutorial on taking '''User input''' in '''Java''', using '''BufferedReader''' .
  
 
|-
 
|-
 
|  00:09
 
|  00:09
|  In this tutorial we will learn:
+
|  In this tutorial, we will learn:
  
 
|-
 
|-
Line 17: Line 17:
 
|-
 
|-
 
|  00:13
 
|  00:13
| About InputStreamReader and BufferedReader
+
|About InputStreamReader and BufferedReader.
  
 
|-
 
|-
 
| 00:17
 
| 00:17
|  To follow this tutorial you must know:
+
|  To follow this tutorial, you must know
  
 
|-
 
|-
 
|  00:19
 
|  00:19
|how to write, compile and run a simple java program in '''Eclipse'''
+
|how to write, compile and run a simple java program in '''Eclipse'''.
 
|-
 
|-
 
|  00:24
 
|  00:24
| You must also know   about the '''datatypes''' in '''Java'''
+
| You must also know about the '''data types''' in '''Java'''.
 
|-
 
|-
 
|  00:27
 
|  00:27
| If not, please refer to the '''spoken tutorial''' on these topics available at '''spoken''' ''hyphen'' '''tutorial''' ''dot'' '''org.'''
+
| If not, please refer to the '''spoken tutorial''' on these topics available at '''spoken''' hyphen '''tutorial''' dot '''org.'''
 
+
 
+
  
 
|-
 
|-
 
|  00:35
 
|  00:35
|  Here, I am using,
+
|  Here, I am using:
 
+
 
'''Ubuntu v 11.10'''
 
'''Ubuntu v 11.10'''
 
 
'''JDK 1.6''' and
 
'''JDK 1.6''' and
 
+
'''Eclipse IDE 3.7.0'''
'''Eclipse IDE   3.7.0'''
+
  
 
|-
 
|-
Line 51: Line 46:
 
|-
 
|-
 
|  00:48
 
|  00:48
|It is a '''class''' in java which is used to read text from an input stream.
+
|It is a '''class''' in java which is used to read text from an '''input stream'''.
  
 
|-
 
|-
 
|  00:53
 
|  00:53
|It provides efficient way to read array of characters and lines.
+
|It provides efficient way to read '''array''' of '''characters''' and '''lines'''.
 
+
  
 
|-
 
|-
 
|00:59
 
|00:59
| To make use of ''BufferedReader ''' , we need to import three '''classes''' from the''' java '''''dot''''' io package.'''
+
| To make use of ''BufferedReader'' , we need to '''import''' three classes from the '''java '''dot''' io package.'''
  
 
|-
 
|-
 
|  01:05
 
|  01:05
 
|These three '''classes''' are:
 
|These three '''classes''' are:
 
+
'''IOException'''
* '''IOException'''
+
'''InputStreamReader''' and
* '''InputStreamReader''' and
+
'''BufferedReader'''
* '''BufferedReader'''
+
  
 
|-
 
|-
Line 80: Line 73:
 
|-
 
|-
 
| 01:21
 
| 01:21
|  All the input that we take from the user will be in the form of '''String'''.
+
|  All the input that we take from the user will be in the form of '''string'''.
  
 
|-
 
|-
 
|  01:26
 
|  01:26
|It has to be then typecasted or converted to the particular datatype.
+
|It has to be then typecasted or converted to the particular data type.
  
 
|-
 
|-
Line 96: Line 89:
 
|-
 
|-
 
|  01:39
 
|  01:39
|Once you import the three '''classes,''' you need to create an object of '''InputStreamReader'''.
+
|Once you import the three '''classes''', you need to create an object of '''InputStreamReader'''.
  
 
|-
 
|-
Line 104: Line 97:
 
|-
 
|-
 
|  01:49
 
|  01:49
|We will learn about this in detail, when we write our program.
+
|We will learn about this in detail when we write our program.
  
 
|-
 
|-
Line 117: Line 110:
 
| 02:00  
 
| 02:00  
 
|We will begin with importing the '''java.io package'''.
 
|We will begin with importing the '''java.io package'''.
 
  
 
|-
 
|-
 
|  02:04
 
|  02:04
|So type, before the class '''import''' ''space'' '''java''' ''dot'' '''io '''''dot'' '''star''' semi colon.
+
|So, type: before the '''class''', '''import''' space '''java''' dot '''io ''' dot '''star''' semicolon.
  
 
|-
 
|-
 
|  02:13
 
|  02:13
 
|This will import the classes '''InputStreamReader, BufferedReader and IOException.'''
 
|This will import the classes '''InputStreamReader, BufferedReader and IOException.'''
 
  
 
|-
 
|-
 
|  02:20
 
|  02:20
| Now  We will make use of '''BufferedReader '''inside the main method.
+
| Now, we will make use of '''BufferedReader '''inside the '''main method'''.
  
 
|-
 
|-
 
|  02:25
 
|  02:25
|We need to throw an '''IOException''' in whatever method we use the '''BufferedReader'''.
+
|We need to '''throw''' an '''IOException''' in whatever '''method''' we use the '''BufferedReader'''.
  
 
|-
 
|-
 
|  02:31
 
|  02:31
|So right after the main method type '''throws space IOException.'''
+
|So, right after the '''main method''' type: '''throws space IOException.'''
  
 
|-
 
|-
Line 146: Line 137:
 
|-
 
|-
 
|  02:45
 
|  02:45
|'''Exceptions '''are errors which occur in Java when some unexpected circumstances occur.
+
|'''Exceptions '''are '''errors''' which occur in Java when some unexpected circumstances occur.
  
 
|-
 
|-
Line 162: Line 153:
 
|-
 
|-
 
|  03:05
 
|  03:05
|When we use '''BufferedReader, exception error''' always take place.
+
|When we use ''BufferedReader'', exception error always takes place.
  
 
|-
 
|-
Line 170: Line 161:
 
|-
 
|-
 
|  03:16
 
|  03:16
|We will learn about '''Exception Handling''' in the coming tutorials.
+
|We will learn about ''Exception Handling'' in the coming tutorials.
  
 
|-
 
|-
Line 178: Line 169:
 
|-
 
|-
 
|  03:24
 
|  03:24
|For that, inside the main method type '''InputStreamReader''' ''space'' '''isr''' ''equalto'' '''new''' ''space'' '''InputStreamReader'''   parentheses.
+
|For that, inside the '''main method''' type: '''InputStreamReader''' space '''isr''' equalto '''new''' space '''InputStreamReader''' parentheses.
  
 
|-
 
|-
 
|  03:44
 
|  03:44
| Within  parentheses, type '''System''' ''dot'' '''in '''and then semicolon.
+
| Within  parentheses, type: '''System''' dot '''in '''and then semicolon.
  
 
|-
 
|-
 
|  03:52
 
|  03:52
|'''InputStreamReader '''is a '''class''' in '''java'''which allows us to take the user  input .
+
|'''InputStreamReader '''is a '''class''' in '''java''' which allows us to take the '''user''' input .
  
 
|-
 
|-
 
|  04:01
 
|  04:01
|'''System '''''dot''''' in'''tells the''' java compiler''' to take the '''input''' from the user using keyboard.
+
|'''System '''dot''' in''' tells the''' java compiler''' to take the '''input''' from the user, using keyboard.
  
 
|-
 
|-
 
|  04:10
 
|  04:10
|The input that '''System '''''dot '''''in '''takes is stored in the '''object''' of '''InputStreamReader '''for sometime'''.'''
+
|The input that '''System ''' dot '''in '''takes is stored in the '''object''' of '''InputStreamReader '''for sometime'''.'''
  
 
|-
 
|-
Line 202: Line 193:
 
|-
 
|-
 
| 04:22  
 
| 04:22  
|So type, '''BufferedReader''' '''br''' ''equal to '''''new''' ''space'' '''BufferedReader''' and then parentheses.  
+
|So, type: '''BufferedReader space br''' equal to '''new''' space '''BufferedReader''' and then parentheses.  
  
 
|-
 
|-
Line 218: Line 209:
 
|-
 
|-
 
|  04:54
 
|  04:54
|'''Isr '''passes this value to the '''BufferedReader object''' to store it.
+
|'''Isr '''passes this value to the '''BufferedReader''' object to store it.
  
 
|-
 
|-
Line 226: Line 217:
 
|-
 
|-
 
|  05:06
 
|  05:06
|We will first ask the user to enter a '''String'''. So create a variable of '''String type'''
+
|We will first ask the user to enter a '''String'''. So create a variable of '''String''' type.
 
+
  
 
|-
 
|-
 
|  05:14
 
|  05:14
|Type, '''String space str semicolon'''
+
|Type: '''String''' space '''str''' semicolon.
  
 
|-
 
|-
Line 239: Line 229:
 
|-
 
|-
 
|  05:23
 
|  05:23
|So type, '''System '''''dot'' '''out '''''dot'' '''println''' ''within brackets and double quotes'' '''Enter your name'''and then'''semicolon'''.
+
|So, type: '''System '''dot '''out '''dot '''println''' within brackets and double quotes '''Enter your name''' and then semicolon.
  
 
|-
 
|-
 
|  05:33
 
|  05:33
| To take the input as  '''String''' we will type.
+
| To take the input as  '''String''' we will type:
  
 
|-
 
|-
 
|  05:37
 
|  05:37
|  '''str''' ''equal to'' '''br''' ''dot'' '''readLine''' parentheses and then semicolon.
+
|  '''str''' equal to '''br''' dot '''readLine''' parentheses and then semicolon.
  
 
|-
 
|-
 
|  05:45
 
|  05:45
|The readLine method will read the input from the user '''.'''
+
|The '''readLine''' '''method''' will read the input from the user.
  
 
|-
 
|-
 
|  05:51  
 
|  05:51  
|Now, let us take the input as an '''integer'''. Create a variable of type'''int'''.
+
|Now, let us take the input as an '''integer'''. Create a variable of type '''int'''.
 
|-
 
|-
 
|  06:01
 
|  06:01
|So type ''' int n ''' semicolon.''
+
|So, type: ''' int n ''' semicolon.
  
 
|-
 
|-
Line 266: Line 256:
 
|-
 
|-
 
|  06:08
 
|  06:08
| So Type, '''System''' ''dot'' '''out''' ''dot'' '''println''' ''within brackets and double quotes''''' Enter your age''' semicolon.
+
| So, type: '''System''' dot '''out''' dot'''println''' within brackets and double quotes ''' Enter your age''' semicolon.
 
+
 
   
 
   
 
|-
 
|-
 
|  06:21
 
|  06:21
 
|Also, create another variable named '''str1''' of '''String''' type in order to take the input.
 
|Also, create another variable named '''str1''' of '''String''' type in order to take the input.
 
  
 
|-
 
|-
 
|  06:31
 
|  06:31
|Now to take the input as '''String,''' type '''str1 '''''equal to '''''br''' ''dot'' '''readLine''' parentheses  and then semicolon.  
+
|Now, to take the input as '''String,''' type: '''str1 '''equal to '''br''' dot '''readLine''' parentheses  and then semicolon.  
  
 
|-
 
|-
 
|  06:45
 
|  06:45
|To convert it into integer datatype, type '''n''' ''equal to'' '''Integer''' with capital I  ''dot'' '''parseInt''', capital I ''within brackets'' '''str1'''semicolon
+
|To convert it into integer datatype, type: '''n''' equal to '''Integer''' with capital I  dot '''parseInt''', capital I within brackets '''str1''' semicolon.
  
 
|-
 
|-
 
|  07:05
 
|  07:05
|Integer is a class and parseInt is its method.
+
|Integer is a '''class''' and '''parseInt''' is its '''method'''.
  
 
|-
 
|-
Line 296: Line 284:
 
|-
 
|-
 
|  07:22
 
|  07:22
|So, type '''System''' ''dot '''''out''' ''dot'' ''println'' ''within brackets and double quotes'' '''The name''' '''is''' ''plus'' '''str''' ''semicolon''.
+
|So, type: '''System''' dot '''out''' dot ''println'' within brackets and double quotes '''The name''' '''is''' plus '''str''' semicolon.
  
 
|-
 
|-
 
|  07:38
 
|  07:38
|Next line type, '''System''' ''dot'' '''out''' ''dot'' '''println''' '' '' '''The ages '''''plus'' '''n''' and then''semicolon''.
+
|Next line, type: '''System''' dot '''out''' dot '''println''' '''The age is''' plus '''n''' and then semicolon.
  
 
|-
 
|-
 
|  07:50
 
|  07:50
| Now,  '''Save''' the file, press '''Ctrl, S'''keys. Now let us run the program
+
| Now,  '''Save''' the file, press '''Ctrl, S''' keys. Now let us '''run''' the program.
  
 
|-
 
|-
|   07:55
+
| 07:55
|So press''' Control''' and '''F11''' keys.   
+
|So, press''' Control''' and '''F11''' keys.   
  
 
|-
 
|-
|   08:00
+
| 08:00
|  In the output, you are asked to Enter your name.
+
|  In the output, you are asked to enter your name.
  
 
|-
 
|-
 
|  08:03
 
|  08:03
|So type your name. I will type here '''Ramu''',  press '''Enter'''.
+
|So, type your name. I will type here '''Ramu''',  press '''Enter'''.
  
 
|-
 
|-
Line 324: Line 312:
 
|-
 
|-
 
|  08:11
 
|  08:11
| I will type here'''20''' and then press '''Enter'''
+
| I will type here '''20''' and then press '''Enter'''.
  
 
|-
 
|-
Line 332: Line 320:
 
|-
 
|-
 
|  08:15
 
|  08:15
|'''The name is  Ramu'''
+
|'''The name is  Ramu'''  And ''' The age is 20'''.
 
+
|-
+
| 08:16
+
|And ''' The age is 20'''.
+
  
 
|-
 
|-
 
|  08:18
 
|  08:18
|Thus we know how to take an input from the user.
+
|Thus, we know how to take an input from the user.
  
 
|-
 
|-
Line 351: Line 335:
 
|-
 
|-
 
|  08:28
 
|  08:28
|About''' BufferedReader'''
+
| About''' BufferedReader''' And Converting from '''String''' to the desired data type.
|-
+
|  08:29
+
|And Converting from '''String''' to the desired datatype
+
 
+
 
+
  
 
|-
 
|-
 
| 08:33
 
| 08:33
|For self-assessment, take a float, byte and character input from the user and  then display the output     
+
|For self-assessment, take a '''float''', '''byte''' and '''character''' input from the user and  then display the output.      
  
 
|-
 
|-
 
|  08:42
 
|  08:42
|Also take a number as input and divide it by 3 then Display the output on the console.  
+
|Also take a number as input and divide it by 3. Then display the output on the console.  
  
 
|-
 
|-
 
| 08:49
 
| 08:49
|  To know more about the spoken tutorial project;Watch the video available at the following  link   
+
|  To know more about the spoken tutorial project, watch the video available at the following  link.  
  
 
|-
 
|-
 
|  08:54
 
|  08:54
|It summarises the Spoken Tutorial project  
+
|It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
 
|  08:57
 
|  08:57
|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.
  
 
|-
 
|-
 
| 09:02
 
| 09:02
|  The Spoken Tutorial Project Team
+
|  The Spoken Tutorial project team:
  
 
|-
 
|-
 
|  09:04
 
|  09:04
|Conducts workshops using spoken tutorials  
+
|Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
|  09:07
 
|  09:07
|Gives certificates to those who pass an online test  
+
|Gives certificates to those who pass an online test.
  
 
|-
 
|-
Line 396: Line 375:
 
|-
 
|-
 
|  09:18
 
|  09:18
|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.
  
 
|-
 
|-
 
|  09:21
 
|  09:21
|It is supported by the National Mission on Education through ICT, MHRD, Government of India
+
|It is supported by the National Mission on Education through ICT, MHRD, Government of India.
  
 
|-
 
|-
 
|  09:27
 
|  09:27
|More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro
+
|More information on this mission is available at:http://spoken-tutorial.org\NMEICT-Intro.
  
 
|-
 
|-

Latest revision as of 15:37, 28 March 2017

Time Narration
00:02 Welcome to the spoken-tutorial on taking User input in Java, using BufferedReader .
00:09 In this tutorial, we will learn:
00:11 To take user input in Java
00:13 About InputStreamReader and BufferedReader.
00:17 To follow this tutorial, you must know
00:19 how to write, compile and run a simple java program in Eclipse.
00:24 You must also know about the data types in Java.
00:27 If not, please refer to the spoken tutorial on these topics available at spoken hyphen tutorial dot org.
00:35 Here, I am using:

Ubuntu v 11.10 JDK 1.6 and Eclipse IDE 3.7.0

00:44 Now, we will learn what a BufferedReader is!
00:48 It is a class in java which is used to read text from an input stream.
00:53 It provides efficient way to read array of characters and lines.
00:59 To make use of BufferedReader , we need to import three classes from the java dot io package.
01:05 These three classes are:

IOException InputStreamReader and BufferedReader

01:12 We will learn about packages and how to import classes in the coming tutorials.
01:18 Now how is the input taken?
01:21 All the input that we take from the user will be in the form of string.
01:26 It has to be then typecasted or converted to the particular data type.
01:31 We will see that while we write our program to take the user input.
01:35 Now, let us see the syntax to implement BufferedReader.
01:39 Once you import the three classes, you need to create an object of InputStreamReader.
01:45 You also need to create an object of BufferedReader.
01:49 We will learn about this in detail when we write our program.
01:54 So, let us switch to Eclipse.
01:56 I have already opened a class named InputBufferedReader.
02:00 We will begin with importing the java.io package.
02:04 So, type: before the class, import space java dot io dot star semicolon.
02:13 This will import the classes InputStreamReader, BufferedReader and IOException.
02:20 Now, we will make use of BufferedReader inside the main method.
02:25 We need to throw an IOException in whatever method we use the BufferedReader.
02:31 So, right after the main method type: throws space IOException.
02:42 Now, what does this mean?
02:45 Exceptions are errors which occur in Java when some unexpected circumstances occur.
02:52 To prevent Exception errors we make use of throws keyword.
02:57 Throws is a keyword which is used during Exception handling.
03:00 It is used whenever we know that Exception error will definitely occur.
03:05 When we use BufferedReader, exception error always takes place.
03:10 To prevent Exception errors from taking place we make use of throws IOException.
03:16 We will learn about Exception Handling in the coming tutorials.
03:20 Now, we will create an object of InputStreamReader.
03:24 For that, inside the main method type: InputStreamReader space isr equalto new space InputStreamReader parentheses.
03:44 Within parentheses, type: System dot in and then semicolon.
03:52 InputStreamReader is a class in java which allows us to take the user input .
04:01 System dot in tells the java compiler to take the input from the user, using keyboard.
04:10 The input that System dot in takes is stored in the object of InputStreamReader for sometime.
04:17 After this we create an object of BufferedReader.
04:22 So, type: BufferedReader space br equal to new space BufferedReader and then parentheses.
04:36 Inside the parentheses, type the object of InputStreamReader which is isr.
04:43 Now, isr only helps to take the input from the user.
04:48 BufferedReader helps to store the value in the BufferedReader object.
04:54 Isr passes this value to the BufferedReader object to store it.
05:01 Now, let us start taking input from the user.
05:06 We will first ask the user to enter a String. So create a variable of String type.
05:14 Type: String space str semicolon.
05:19 Now ask the user to enter his name.
05:23 So, type: System dot out dot println within brackets and double quotes Enter your name and then semicolon.
05:33 To take the input as String we will type:
05:37 str equal to br dot readLine parentheses and then semicolon.
05:45 The readLine method will read the input from the user.
05:51 Now, let us take the input as an integer. Create a variable of type int.
06:01 So, type: int n semicolon.
06:05 Ask the user to enter his age.
06:08 So, type: System dot out dotprintln within brackets and double quotes Enter your age semicolon.
06:21 Also, create another variable named str1 of String type in order to take the input.
06:31 Now, to take the input as String, type: str1 equal to br dot readLine parentheses and then semicolon.
06:45 To convert it into integer datatype, type: n equal to Integer with capital I dot parseInt, capital I within brackets str1 semicolon.
07:05 Integer is a class and parseInt is its method.
07:11 This method converts the argument passed within the bracket into integer.
07:18 Now, let us display the output for name and age.
07:22 So, type: System dot out dot println within brackets and double quotes The name is plus str semicolon.
07:38 Next line, type: System dot out dot println The age is plus n and then semicolon.
07:50 Now, Save the file, press Ctrl, S keys. Now let us run the program.
07:55 So, press Control and F11 keys.
08:00 In the output, you are asked to enter your name.
08:03 So, type your name. I will type here Ramu, press Enter.
08:08 You will be asked to enter your age.
08:11 I will type here 20 and then press Enter.
08:13 We get the output as :
08:15 The name is Ramu And The age is 20.
08:18 Thus, we know how to take an input from the user.
08:24 In this tutorial we have learnt :
08:26 About InputStreamReader
08:28 About BufferedReader And Converting from String to the desired data type.
08:33 For self-assessment, take a float, byte and character input from the user and then display the output.
08:42 Also take a number as input and divide it by 3. Then display the output on the console.
08:49 To know more about the spoken tutorial project, watch the video available at the following link.
08:54 It summarizes the Spoken Tutorial project.
08:57 If you do not have good bandwidth, you can download and watch it.
09:02 The Spoken Tutorial project team:
09:04 Conducts workshops using spoken tutorials.
09:07 Gives certificates to those who pass an online test.
09:11 For more details, please write to contact@spoken-tutorial.org
09:18 Spoken Tutorial project is a part of the Talk to a Teacher project.
09:21 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
09:27 More information on this mission is available at:http://spoken-tutorial.org\NMEICT-Intro.
09:36 This is Arya Ratish from IIT Bombay.

Thank You for joining.

Contributors and Content Editors

Gaurav, PoojaMoolya, Sandhya.np14, Sneha