Java System Input and Output I/O
Usually, close contact with the new programming language begins with printing something to a console. We will see, how it’s done in the Java language.
System Output
We can pass any primitive data type as an argument, if the object has toString implementation it will display it as defined. Java code has a little bit of boilerplate code:
Also, we can pass expression as a parameter:
It prints the result of an expression which is 30.
To display multiple outputs on a single line:
Pro Tip: in some IDEs like in Intellij, there is a useful shortcut that will write down the whole expression:
sout + tab
System Input
The easy way to work with input data to use Java’s prebuilt Scanner class. It works like this, input some data(but it always a String) to the console and then you can store data, or perform some action with it. Before using the Scanner class we must first import it:
The programme above is taking the user name and displays it to the console.
In future articles, we will see proper ways to test your code, including data.