Loading...

Java Output

You want the screen to show a different word. The file is still Mint.java, and the writing command is still the line you already know. On the last page the quotes held mint, so the screen was mint. On this page you put a different word between those quotes, then you add a second writing line, then you see what the screen does when a writing line does not end the line. You are not installing Java again. You are not looking for which line writes the screen, and you are not adding a note. You already know the writing line, and you already know a note stays off the screen. The new work is the letters the screen shows.

The word between the quotes

Open Mint.java and find System.out.println("mint");. The screen shows the word between the quotes. The quotes themselves are not letters for the screen. They mark where that word starts and where it ends. Change the word. Leave the rest of the line as it is: System.out.println stays, the opening quote stays, the closing quote stays, and the semicolon stays. Only the letters between the quotes change. Where the file had mint, write leaf, all small letters. The line is now System.out.println("leaf");. Save the file. The file name is still Mint.java, because the line public class Mint is still the name of the file. This page does not rename the file.

The file you keep

Save this as Mint.java. It is the file this page keeps. It has one writing line, and that line holds leaf between the quotes. There is no note in this file. There is no second writing line yet.

the file you keep

java
public class Mint {
    public static void main(String[] args) {
        System.out.println("leaf");
    }
}

Read it from the top and decide what the screen can receive. The first line is public class Mint. That line names the file. It does not write the screen, and it did not write the screen on the earlier pages either. The next line is public static void main(String[] args). That is where Java starts. None of those words are letters for the screen. Inside main there is one command: System.out.println("leaf");. System.out.println is the writing command. The quotes hold leaf. The semicolon ends the command. Java runs that command because it sits inside main and it is not behind //. The screen receives leaf. It does not receive the quotes, the semicolon, the word System, or the word main.

Run it the same way as before. In the folder that contains this Mint.java, type javac Mint.java. When the file is fine, that command writes no line. A changed word between the quotes does not make javac write a line, and it does not make javac fail. Then type java Mint. Do not type .java after java. The screen shows leaf. One line. No quotes. No semicolon. The word mint is not on the screen, because mint is no longer between the quotes. If the screen still shows mint, the quotes still contain mint. Look at the letters between the quotes before you type the commands again. You do not reinstall Java for a screen that still says mint.

The screen copies the letters between the quotes, and it copies them as they are. System.out.println("Leaf"); writes Leaf, with a capital L. System.out.println("leaf"); writes leaf, with a small l. The file you keep uses the small l, so its screen is leaf and not Leaf. A space is also a letter the screen can show, if you type the space inside the quotes. System.out.println("leaf stem"); writes one line, leaf stem, with the space that you put between the two words. The quotes still do not appear. This is one writing line, so it is one screen line, even though two words are inside it. An empty pair of quotes is different. System.out.println(""); writes a line that has no letters, and then ends that line. The screen looks blank. The command did run. The quotes simply held nothing. That blank line is not the file you keep. The file you keep holds leaf.

A second line

One writing line gives one screen line. A second screen line needs a second writing line. Under System.out.println("leaf"); add System.out.println("stem");. Each command has its own quotes and its own semicolon. leaf stays in the first pair of quotes. stem, all small letters, goes in the second pair. Java runs the first command, ends that line, then runs the second command and ends that line too. The screen order is the file order. The command you wrote first is the line the screen shows first.

This is the second file. You are looking at two screen lines. The file you were keeping had one writing line and the screen was leaf. This one has two writing lines. Save it as Mint.java when you want to see this screen, then put the single writing line back if you want the file this page keeps.

two lines, leaf then stem

java
public class Mint {
    public static void main(String[] args) {
        System.out.println("leaf");
        System.out.println("stem");
    }
}

In the same folder, type javac Mint.java. The file is fine, so javac writes no line. Then type java Mint. The screen shows leaf, and the next line of the screen is stem. Two lines. leaf is on top because System.out.println("leaf"); is the first writing command. stem is under it because System.out.println("stem"); is the second. The quotes are on neither line. If stem is on top and leaf is under it, the two writing lines in the file are in that swapped order. The screen is not choosing an order of its own. Move the stem command back under the leaf command, save, and run java Mint again. You do not need a new kind of command to get the second line. You need a second System.out.println, with its own word between its own quotes.

print does not end the line

Look at the end of the writing command you have been using. println ends with the letters ln. Those letters are the line end. The command writes the letters between the quotes, and then it ends the line, so the next writing command starts on a fresh line. print is the same writing command without those two letters. System.out.print("leaf"); writes leaf and does not end the line. The next System.out.print starts where that word stopped. Nothing in the command inserts a space for you. If the first quotes hold leaf and the second quotes hold stem, and neither pair holds a space, the screen shows leafstem as one line.

This is the third file. It is not the file you keep. Save it long enough to see the single line leafstem. Both commands are print, not println. There is no space inside either pair of quotes.

one line, leafstem

java
public class Mint {
    public static void main(String[] args) {
        System.out.print("leaf");
        System.out.print("stem");
    }
}

Type javac Mint.java. The file is fine, so javac writes no line. print is a real command. Using it does not make javac fail. Then type java Mint. The screen shows leafstem. One line. No space between leaf and stem. No quotes. leaf is still first, because System.out.print("leaf"); is the first command, and stem is glued on after it, because System.out.print("stem"); does not start a new line. If you see leaf and then stem on a second line, the commands in the file are println, not print. The letters ln are still on the command, so each command ended its line. Take ln off both commands if the screen you want is the single word leafstem.

The program writes leafstem and finishes without ending the line. The terminal may draw its own prompt on that same line, after leafstem. The prompt belongs to the terminal. It is not a word from Mint.java, and it is not part of the line you are checking. Check the letters between the quotes: leafstem. Do not try to match the prompt. Windows and macOS draw different prompts, and this page does not teach those prompts. The program's line is the same on both: leafstem, with no line end after it.

A space has to be inside the quotes

If you want a space on that same line, the space has to be one of the letters between the quotes. The writing command will not invent it. Change the first command to System.out.print("leaf "); with a space after the f, still inside the quotes. Leave the second command as System.out.print("stem");. Java writes leaf, then writes the space you put after the f, then writes stem, and still does not end the line. The screen shows leaf stem. The space you see is the space that was inside the first quotes. A space typed outside the quotes, between the two commands, is only a gap in the file. It is not a letter for the screen. You can break the two commands onto two lines in the file, or put a blank line between them, and the screen is still one line. Line breaks in the file are not line ends on the screen. Only the line-ending command, println, ends a screen line. print never does, no matter how the file is spaced around it.

Put the file back to the one you keep when you are done looking at leafstem and leaf stem. The writing line in the file you keep is System.out.println("leaf"); and there is no second writing line. java Mint then shows leaf again, one line, and the line does end. If you leave a print in the file by mistake, the next run will not end that line. The check is the letters on the command: println ends the line, print does not.

The mistake that drops the quotes

The word the screen shows has to sit between quotes. The mistake is to delete the quotes and leave the word bare: System.out.println(leaf);. leaf without quotes is not a word for the screen. Java reads it as a name, and this file does not have that name. The next page is about names. This page stops at the quotes. Save this fourth file only long enough to see that javac does not stay quiet, then put the quotes back. This is not the file you keep.

the quotes removed

java
public class Mint {
    public static void main(String[] args) {
        System.out.println(leaf);
    }
}

Type javac Mint.java. This time javac writes an error. It does not stay quiet. The file is not fine, because leaf has no quotes and no meaning in this file yet. You do not need the exact words of that error. The useful fact is that javac wrote a line at all. When javac writes an error, do not type java Mint. There is no new screen to read until the file is fine again. Put the quotes back, so the line is System.out.println("leaf"); again. Save. Type javac Mint.java once more. Now javac writes no line. Then java Mint shows leaf. The quotes were the whole repair. You do not reinstall Java, and you do not remove the writing line. A writing line with the quotes removed is not a blank screen from a note. A note would have left javac quiet. This mistake makes javac speak.

You can now change the screen by changing the letters between the quotes. System.out.println("leaf"); writes leaf and ends the line. A second System.out.println writes the next line, in the order you wrote the commands in the file. System.out.print writes its letters and does not end the line, so a following print continues on that same line, and a space appears only when you put it inside the quotes. If javac writes an error on a bare word, the quotes are missing. The next page gives a word a name, so a writing line can use that name instead of only a quoted word.

The screen is the quoted word

The file you keep writes leaf. One println is one line. Two println commands are two lines, first command first. Two print commands are one line, and leafstem has no space because neither pair of quotes held a space. The quotes, the semicolon, and the name of the file stay off the screen.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
7
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 Instructions

  • Read each question carefully
  • Select the best answer for each question
  • You can retake the quiz as many times as you want
  • Your progress will be shown at the top