Java null
String plant = null; stores no letters, and System.out.println(plant) writes null. The screen is one line. There are no quotes around null, and there is no digit on that line.
The name holds no letters
Open Mint.java. The file name stays Mint.java, because public class Mint is still the name of the file. This page does not rename the file, and it does not change public class Mint. Delete int count if that line is still there, including (int), 40.0, 40.9, and 40. Delete double weight if it is still there. Delete boolean ripe if it is still there, including true and false. Delete plant.length and delete charAt. Delete any import line, any reader line, and any nextLine line. The file you keep has no import, no Scanner, no nextLine, no count, no weight, no ripe, and no parentheses. An unused import does not by itself make javac fail, and it does not write null either. The word is written only by the writing line that uses the name.
Inside main, the storing line is String plant = null;. String is the kind word. It says this name can hold letters, or it can hold no letters at all. plant is the name, and it starts with a small p. The = sign stores. The word is null, every letter small: n, u, l, l. There is no capital N. There are no quotes around null. There is no digit. The semicolon ends the line. This line stores no letters. It does not write the screen. Storing is not writing. The screen stays blank through this line. null is not a short way to write the number 0. null is not the word leaf with the letters missing from the screen only. Nothing is stored. The letters leaf are not waiting somewhere in this name.
On this page, this kind holds either letters between quotes, such as leaf, or the word null with no quotes. You do not invent a third word. String plant = none; treats none as a name. This file does not have a name none. javac writes an error. String plant = empty; does the same. The word you are allowed to write, with this kind word and with no quotes, is null. The file you keep uses null.
The writing line is the bare name: System.out.println(plant);. No quotes, and no dot. Java reads the name plant, writes what that name holds, and ends the line. For the file you keep, the name holds no letters, so the writing line writes the word null. The letters of the name, p, l, a, n, t, are not on the screen. String is not on the screen. System is not on the screen. The semicolon is not on the screen. The word null is on the screen, as one line. Save the file.
The file you keep
Save this as Mint.java. It is the file this page keeps. One kind word, String. One name, plant. One word, null, all small letters, no quotes, no digit. One writing line, and that line uses the bare name. There is no length and no charAt.
public class Mint {
public static void main(String[] args) {
String plant = null;
System.out.println(plant);
}
}
Read it from the top. public class Mint names the file. It does not write the screen. public static void main(String[] args) is where Java starts. The word String on that main line is still not a storing line. The storing line is the later one, String plant = null;. It writes nothing. System.out.println(plant); writes null and ends the line. One line on the screen. No quotes. No second line. There is no int line in the file you keep.
What the screen shows
In the folder that contains this Mint.java, type javac Mint.java. When the file is fine, that command writes no line. The word null after String 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 same two commands are what you type on Windows and on macOS. This page does not quote the shell prompt. The program writes null. It does not wait for you to type. The word was already in the file. If java Mint waits, nextLine is still in the file. Delete that line and keep String plant = null; and the one writing line. The program finishes after the writing line.
The screen shows null. One line. No quotes. If the screen shows plant, the writing line has quotes around the name: System.out.println("plant");. Those quotes mark the letters p, l, a, n, t, so the stored word is not written. If the screen shows leaf, the storing line still says "leaf". Delete those quotes and the letters, and write null with no quotes. If the screen shows 40, or 40.0, or 4, the casting file or the numbers file is still in place. Delete the int line and the parentheses. If the screen shows true or false, ripe is still in the file. If the screen shows mint, you are still on an older file. If the screen shows a blank line and not the word null, the storing line has quotes with nothing between them: String plant = "";. That is not the file you keep. The file you keep has the word null and no quotes. You do not reinstall Java for a screen that shows the wrong line.
A screen that shows null does not, by itself, prove the file. String plant = "null"; with quotes around those four letters also writes null, because the quotes hold n, u, l, l. The screen can look the same. The file does not. The file you keep has String, and it has null with no quotes. When you judge this page, look for the kind word and look for the absence of quotes. Do not judge the file from the screen alone.
Quotes hold the letters null
Quotes around the word are letters, not the empty name. String plant = "null"; stores four letters. javac writes no line. java Mint writes null. That run is allowed, and it is not the file you keep. The file you keep has no quotes, so the name holds no letters. When you are repairing the kept file, delete the quotes so the line is String plant = null; again. Do not delete the word null with them.
📊 The storing line and the screen
| The storing line | The screen |
|---|---|
| String plant = null; | null |
| String plant = "null"; | null |
| String plant = "leaf"; | leaf |
| int count = null; | javac writes an error |
Read the table against a run, not instead of one. For String plant = null;, javac writes no line and java Mint writes null. For String plant = "null";, javac writes no line and java Mint writes null, and the file still has quotes. For String plant = "leaf";, javac writes no line and java Mint writes leaf. For int count = null;, javac writes an error, so you do not type java Mint. After each check, put String plant = null; back, with no quotes. The kept screen is null, one line.
The name has to exist before a line uses it. If System.out.println(plant); is written above String plant = null;, javac writes an error. The writing line names plant before plant exists. Move the storing line above the writing line. Do not write String a second time for the same name. String plant = "leaf"; placed under a line that already created plant is a different error. javac writes an error and does not stay quiet. The name is created once. A later line can put letters in without writing String again, once plant already exists: plant = "leaf";. That line only replaces what the name holds. It is allowed. It is not the file you keep. The file you keep has one storing line, and that line says null.
String plant; with no = null, followed by the writing line, makes javac write an error. The name would exist as a kind, and it would hold no word yet, not even null. Put = null on the creating line, the way the file you keep has it. String plant = nullnull; treats nullnull as one name. This file does not have that name. javac writes an error. The word is null, and a missing space does not glue it into a third word that works. String plant = null ; with a space before the semicolon is still the word null. javac writes no line, and the screen is still null. The file you keep has no extra space, but that space is not a second value.
A capital letter is not the word. String plant = Null; treats Null as a name, because the first letter is a capital N. This file does not have a name Null. javac writes an error. It does not stay quiet. The screen does not show Null, because you do not run java Mint while javac is writing an error. The word in the file you keep is null, all small. Put the small letters back.
null is not a whole number
A whole number is the kind from the numbers page. int count = null; asks that kind to hold no letters. null does not fit. javac writes an error. It does not turn null into 0. It does not write null. boolean ripe = null; asks the two-word kind to hold null. That kind holds true or false only. javac writes an error. It does not turn null into false. There is no screen to read, because you do not type java Mint while javac is writing an error. You do not need the exact words of these errors. Delete the int line and the boolean line when you are repairing the file you keep, and write String plant = null; again.
A question after the name is a different failure, and it is not a javac failure. The second file stores null, then asks how many letters that name holds.
public class Mint {
public static void main(String[] args) {
String plant = null;
System.out.println(plant.length());
}
}
This is the second file. It is not the file you keep. Type javac Mint.java. The file is fine as far as javac can see, so javac writes no line. The word null does not make javac fail, and length does not make javac fail either. Then type java Mint. The program does not write a number. It does not write 4, and it does not write 0, and it does not write null. java Mint writes an error. You do not need the exact words of that error. The name holds no letters, so there is no count of letters to write. If the screen shows 4, plant still holds leaf, and length is counting those four letters. Delete "leaf" and keep null, or, for the file you keep, delete length entirely. The writing line in the file you keep is System.out.println(plant); with no dot and no length. After you have seen the error, put the kept file back.
You can now store no letters in a name and write the word null without quotes and without a digit. String plant = null; stores no letters. System.out.println(plant); writes null and ends the line. Quotes around null store four letters, and the screen can look the same, so you judge the file. int count = null; and boolean ripe = null; each make javac write an error. Null with a capital N is a name this file does not have. plant.length() after null lets javac stay quiet and makes java Mint write an error. The next page leaves this empty name. It looks at more than one value kept under a single name.
The screen is the word null
The file you keep writes null. The name on the writing line is plant, and plant is not on the screen. There are no quotes in that file. One println is one line. The same screen from quotes is four letters, not the file you keep. A digit does not belong in the file you keep. A question after the name is not the file you keep.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 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