Java Keyboard Input For Day 16 Of Javatober
I have been using CodeGym now for a few days and I think it is good, but at times I feel it is going overboard with the repetition. The past few days have seen me doing a lot of work with input and output streams but due to the exercises I have been working on, I feel like I have almost forgot some of the word we did earlier in the week.
What Did I Learn Today
We have been working a lot on System.out but today I finially got to work with System.in to gather input from the users keyboard. If you move ahead to the code we are describing, you will see its a lot more complex than the usually System.out.println() statement. You see we are using the line:
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Yep, it looks pretty complicated but what is everything doing here, so we can start from the end bit which is "System.in". We need to remember there are two types of streams: Input streams are used to receive data and Output streams are for sending data. In Java, these streams are implemented by the InputStream and OutputStream classes where System.in is an InputStream object. System.out is a stream for sending data to the console, while System.in is for getting data from the keyboard.
We then need to create an InputStreamReader object and pass it an input stream that it will read data from. This is where we have:
new InputStreamReader(System.in)
In this case we use System.in to gather data from the keyboard, but we could use FileInputStream for reading from files and InputStreamReader knows how to read data and convert bytes into characters.
We then use the BufferedReader to read the inputed data, it uses a special area called a buffer to store the and access the data and allows BufferedReader + InputStreamReader to be faster than InputStreamReader alone.
Bufferedreader can read data not only one character at a time (though it can do this with its read() method), but also whole lines at a time! This is done using the readLine() method;
Code For The Day
1 import java.io.*;
2
3 public class Test {
4 public static void main(String[] args) throws Exception {
5
6 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
7 String name = reader.readLine();
8
9 System.out.println(name + " is typing on the keybaord");
10 }
11 }
Output
java Test
test
test is typing on the keybaord
Hello! Your post has been resteemed and upvoted by @ilovecoding because we love coding! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!

Reply !stop to disable the comment. Thanks!
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by run.vince.run from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.