Java Comparison
boolean match = 4 == 4; stores the word true, and System.out.println(match) writes true. The screen is one line. The two equal marks sit between the two fours in the file, and they are not on that line.
Two equal marks ask a question
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 total if that line is still there, including 4 + 9, 9 / 4, 10 % 3, and every mark that combines two numbers into one whole number. Delete String[] plants if that line is still there. Delete String plant if that line is still there. Delete int count if that line is still there. Delete boolean ripe if that line is still there with a bare true or bare false and no ask mark. Delete any import line, any reader line, and any nextLine line. The file you keep has no import, no Scanner, no nextLine, no total, no plants, no plant, no count, and no bare ripe line. An unused import does not by itself make javac fail, and it does not write true either. The word is written only by the writing line that uses the name that holds the answer to the ask.
Inside main, the storing line is boolean match = 4 == 4;. boolean is the kind word. It says this name holds one of two words, true or false. match is the name, and it starts with a small m. The first = sign stores. On the right of that first = sit two whole numbers and one ask mark. The first number is 4. The ask mark is two equal marks written together with no space between them: ==. The second number is 4. There are no quotes around either 4. The semicolon ends the line. This line stores one word. It does not write the screen. Storing is not writing. The screen stays blank through this line. The ask mark does not combine 4 and 4 into a larger number. It asks whether the left number matches the right number. When they match, the word stored is true. When they do not match, the word stored is false.
One equal mark and two equal marks are not the same work. One equal mark stores a value under a name. Two equal marks ask whether two values match. boolean match = 4 == 4; has both. The first = stores. The == asks. If you write only one equal mark where the ask belongs, as in boolean match = 4 = 4;, javac writes an error. That line tries to store twice in a way this page does not teach. Keep two equal marks for the ask. Keep one equal mark for the store. The operators page used one mark between two numbers to make a third number, such as 4 + 9. This page uses an ask mark between two numbers that already stand on their own. The ask does not make a third whole number. It makes true or false.
The writing line is the bare name: System.out.println(match);. No quotes, and no ask mark on that line. Java reads the name match, writes the word that name holds, and ends the line. For the file you keep, that word is true. The letters of the name, m, a, t, c, h, are not on the screen. boolean is not on the screen. The two equal marks are not on the screen. The digit 4 is not on the screen. The word true 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, boolean. One name, match. One storing line that writes 4, then two equal marks, then 4, with no quotes around either number. One writing line, and that line uses the bare name. There is no total line, no plants line, and no second writing line.
public class Mint {
public static void main(String[] args) {
boolean match = 4 == 4;
System.out.println(match);
}
}
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 brackets on that main line belong to args, and this page does not read args. boolean match = 4 == 4; stores the word true. It writes nothing. System.out.println(match); writes true and ends the line. One line on the screen. No quotes. No second line. There is no int total line in the file you keep, and there is no line that stores a combined whole number.
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. Two equal marks between two whole numbers do not make javac write a line, and they do 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 true. It does not wait for you to type. The two numbers and the ask mark were already in the file. If java Mint waits, nextLine is still in the file. Delete that line and keep boolean match = 4 == 4; and the one writing line. The program finishes after the writing line.
The screen shows true. One line. No quotes. If the screen shows match, the writing line has quotes around the name: System.out.println("match");. Those quotes mark letters, so the stored word is not written. If the screen shows 13, the operators file is still in place. Delete int total and the plus mark. If the screen shows 4, a writing line may still print a whole number instead of the boolean name. The file you keep writes the word held by match. If the screen shows false, the two numbers on the storing line do not match, which is the second file on this page, not the file you keep. If the screen shows 4 == 4 as letters, the writing line has quotes around those characters. You do not reinstall Java for a screen that shows the wrong line.
A screen that shows true does not, by itself, prove the ask mark. boolean match = true; also writes true. The screen can look the same. The file does not. The file you keep has 4, then ==, then 4. When you judge this page, look for the two equal marks between the two numbers. Do not judge the file from the screen alone.
Spaces around the ask mark are allowed. boolean match = 4==4; with no spaces still stores true, and javac writes no line. boolean match = 4 == 4; with spaces still stores true. The file you keep uses spaces around the ask mark, because the mark is easier to see that way. The spaces are not a second value. A space between the two equal marks is not allowed. boolean match = 4 = = 4; makes javac write an error. Keep the two equal marks together as ==.
The name has to exist before a line uses it. If System.out.println(match); is written above boolean match = 4 == 4;, javac writes an error. The writing line names match before match exists. Move the storing line above the writing line. Do not write boolean a second time for the same name. A later line can replace the word without writing boolean again, once match already exists: match = 4 == 4;. That form is allowed. It is not required. The file you keep creates the name and stores the answer on one line.
When the numbers do not match
Change only the second number. Keep the kind word boolean. Keep the name match. Keep the ask mark as two equal marks. boolean match = 4 == 9; asks whether 4 matches 9. They do not match. The word stored is false. The writing line is still System.out.println(match);. The screen shows false. One line. The name match is not on the screen. The digits 4 and 9 are not on the screen. The ask mark is not on the screen.
public class Mint {
public static void main(String[] args) {
boolean match = 4 == 9;
System.out.println(match);
}
}
This is the second file. It is not the file you keep. Type javac Mint.java. javac writes no line. Then type java Mint. The screen shows false. One line. It does not show 4. It does not show 9. It does not show 4 == 9 as letters. If the screen shows true, you are still on the file you keep, where both numbers are 4. Put this second file in place only when you want to see false from an ask that does not match. After you have seen false, put the kept file back: boolean match = 4 == 4; and one System.out.println(match);. The kept screen is true, one line.
The ask mark does not fix the numbers. It does not change 9 into 4. It only answers. true means the two sides match. false means they do not. The booleans page stored true or false by writing the word itself. This page stores true or false by asking with a mark. Both pages use the same kind word, boolean. Both pages write the same two words on the screen. The file shape is different. The file you keep on this page has the ask mark and two whole numbers.
Other ask marks
Two equal marks are not the only ask mark. A mark that asks whether the numbers are not the same is written as an exclamation mark and an equal mark together: !=. boolean match = 4 != 9; stores true, because 4 and 9 are not the same. boolean match = 4 != 4; stores false, because the numbers are the same. This run is allowed, and it is not the file you keep. Type javac Mint.java. javac writes no line. Then type java Mint. For 4 != 9, the screen shows true. After you have seen that line, put the kept file back.
A mark that asks whether the left number is larger is written as >. boolean match = 9 > 4; stores true. boolean match = 4 > 9; stores false. boolean match = 4 > 4; stores false, because 4 is not larger than 4. A mark that asks whether the left number is smaller is written as <. boolean match = 4 < 9; stores true. boolean match = 9 < 4; stores false. boolean match = 4 < 4; stores false.
A mark that asks whether the left number is larger or the same is written as >=. The equal mark sits against the larger mark with no space. boolean match = 4 >= 4; stores true. boolean match = 9 >= 4; stores true. boolean match = 4 >= 9; stores false. A mark that asks whether the left number is smaller or the same is written as <=. boolean match = 4 <= 4; stores true. boolean match = 4 <= 9; stores true. boolean match = 9 <= 4; stores false. The extra equal mark means "or the same." It is not a second separate ask. Do not put a space inside >= or inside <=. boolean match = 4 > = 4; makes javac write an error.
📊 The ask mark and the screen
| The storing line | The screen |
|---|---|
| boolean match = 4 == 4; | true |
| boolean match = 4 == 9; | false |
| boolean match = 4 != 9; | true |
| boolean match = 9 > 4; | true |
| boolean match = 4 < 9; | true |
| boolean match = 4 >= 4; | true |
| boolean match = 4 <= 9; | true |
Read the table against a run, not instead of one. For the kept ask, javac writes no line and java Mint writes true. For numbers that do not match with ==, the screen is false. For != with 4 and 9, the screen is true. For 9 > 4, the screen is true. For 4 < 9, the screen is true. For 4 >= 4, the screen is true. For 4 <= 9, the screen is true. After each check, put the kept file back: boolean match = 4 == 4; and System.out.println(match);. The kept screen is true, one line.
Quotes around a number turn it into letters. boolean match = "4" == 4; asks Java to compare letters with a whole number in a way this page does not teach. javac writes an error, or the screen is not the word true from the kept file. Delete the quotes. Both sides of the ask mark, on this page, are whole numbers with no quotes. System.out.println(4 == 4); with no match name at all also writes true. The screen can look the same. The file you keep stores the answer under a name first, then writes that name. When you judge this page, look for boolean match and look for the ask mark on the storing line.
This page compares whole numbers. It does not compare letters under quotes with == as the lesson you keep. A later page teaches a different way to ask whether two groups of letters match. If the screen shows leaf, or mint, plants or plant is still in the file. Delete those lines. If the screen shows 13, total is still in the file. Delete that line. Logical marks that combine two true or false answers, such as &&, belong on the next page. This page stores one ask and one answer.
Writing the ask mark as letters does not ask. System.out.println("4 == 4"); writes the characters 4, space, =, =, space, 4. The screen shows 4 == 4. That is not the word true. javac stays quiet. The quotes are what stop the mark from working as an ask. The file you keep has no quotes around the numbers, and the writing line has no quotes around the name.
You can now store true or false by asking whether two whole numbers match, and write that word. boolean match = 4 == 4; stores true. System.out.println(match); writes true and ends the line. boolean match = 4 == 9; writes false. One equal mark stores. Two equal marks ask. Other ask marks write true or false for larger, smaller, or not the same. The next page leaves a single ask. It looks at marks that combine two true or false answers into one answer.
The screen is true or false
The file you keep writes true. The name on the writing line is match, and match is not on the screen. The two equal marks are in the file, and they are not on the screen. 4 and 4 are in the file, and they are not on the screen as digits. Numbers that do not match, and the other ask marks, are not the file you keep. Quotes around the ask write letters, not the answer word.
🧠 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