The word “print” does not mean the printing using a tangible printer. We use that word to tell that we are displaying something on the screen.
It is easy in JAVA.
Let’s identify the important features of the two statements given above.
- The “S” in the word “System” should be capital.
- Whatever given inside the brackets will be printed.
- If you want to print a string, you need to use inverted commas.
- If you want to print a predefined variable, just use the variable name.
- Use “print”(first statement) to keep the cursor in the same line.
- Use “println”(second statement) to move the cursor to the next line.
Whatever you type in java, you need to type inside the main class.
More zoomed picture is given below.
Can you understand what happened?
First “Hello Java” is printed. Since we used just the “print”, the cursor is not moved down. Then again “Hello Java” is printed without a space even. That is why you get “JavaHello” word in the middle.
Let’s print it in a polite manner.
Likewise you can print a predefined variable also.
I made 2 variables , an integer and a string.
Then I printed them.
Now we’ll learn how to concatenate inside a print statement.
System.out.println(“I am “+ age + ” years old. \n My school is ” + school);
Concatenation in JAVA is done by the plus (+) sign.
The “\n” takes the cursor to the next line. So the cursor will be moved to the next line in the middle of the print statement.
Just look at the output now.
So that’s it for this section. See you soon in the next section.