Java Primitive Types
You want a name to hold a whole number that you write in the file, and you want one writing line to show that number. On the last page the name held a line you typed, so the letters were not in the file at all. On this page the number is in the file. The word in front of the name says what kind of value the name holds. int count = 4; stores the whole number 4. System.out.println(count) writes 4. There are no quotes around 4. You are not reading the keyboard. You are not installing Java again, and you are not learning a second way to end a line. You already know a name can hold letters. The new work is a name that holds a whole number, and the kind word that says so.
The kind word sits in front of the name
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 rename the class. The last page started with import java.util.Scanner; and waited for a typed line. This page does not. Delete the import line. Delete the reader line and the nextLine line. The file you keep has no import, no Scanner, and no nextLine. An unused import does not by itself make javac fail, and it also does not write the number. The number is written only by the writing line that uses the number's name.
Inside main, the storing line is int count = 4;. int is the kind word. It says this name holds a whole number: digits, and no decimal point. count is the name, and it starts with a small c. The = sign stores the number. The 4 has no quotes around it. A whole number in this file is not a word between quotes. The semicolon ends the line. This line does not write the screen. Storing is not writing. The screen stays blank through this line.
The writing line is the bare name: System.out.println(count);. No quotes. Java reads the name count, writes the whole number that name is holding, and ends the line. For the file you keep, that number is 4. The letters of the name, c, o, u, n, t, are not on the screen. int is not on the screen. System is not on the screen. The semicolon is not on the screen. Save the file.
The file you keep
Save this as Mint.java. It is the file this page keeps. One kind word, int. One name, count. One whole number, 4, with no quotes and no decimal point. One writing line, and that line uses the bare name.
public class Mint {
public static void main(String[] args) {
int count = 4;
System.out.println(count);
}
}
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. None of those words are the number on the screen. The word String on the main line is still not a storing line. There is no String line in the file you keep. int count = 4; stores the whole number. It writes nothing. System.out.println(count); is the only writing line. It writes 4 and ends the line. One line. No quotes.
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. A whole number in the file 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 4. It does not wait for you to type. The number was already in the file. If java Mint waits, the file still has nextLine in it. Delete that line and keep int count = 4;.
The screen shows 4, one line, no quotes. If the screen shows count, the writing line has quotes around the name: System.out.println("count");. Those quotes mark the letters c, o, u, n, t. Java does not look up the name, so the stored 4 is not written. The file you keep has the bare name. If the screen shows leaf, the writing line is still System.out.println("leaf");, or a String name still holds leaf and the writing line uses that name. The file you keep has neither. If the screen shows mint, you are still on an earlier file. You do not reinstall Java for a screen that shows the wrong line.
A screen that shows 4 does not, by itself, prove the kind. String count = "4"; would also make System.out.println(count); write 4, because the letters between the quotes are the digit 4. The screen looks the same. The file does not. The file you keep has int, and it has 4 with no quotes. String count = "4"; is the letter kind you already know, with a digit written as letters. This page's kept file is the whole-number kind. When you judge the file, look for the kind word and look for quotes. Do not judge the kind from the screen alone.
The creating line has to store the number. int count; with no = 4, followed by System.out.println(count);, makes javac write an error. The name exists as a kind, and it has no number yet. javac does not stay quiet. Do not type java Mint. Put = 4 on the creating line, the way the file you keep has it. You do not need the exact words of the error. The useful fact is that javac wrote a line.
Change the number, keep the writing line
The writing line can stay put while the stored number changes. Under the first writing line, store a new whole number in the same name, then write the name again. The new storing line is count = 9;. It does not start with int. count already exists, so this line only replaces the number the name holds. 4 is replaced by 9. The next writing line is again System.out.println(count);. The screen now has two lines. The first is 4, from the number the name held at that moment. The second is 9, from the number the name holds after count = 9;.
This is the second file. It is not the file you keep. The file you keep has one storing line and one writing line, and its screen is 4. Save this second file as Mint.java when you want to see the number change, then put the single storing line and the single writing line back.
public class Mint {
public static void main(String[] args) {
int count = 4;
System.out.println(count);
count = 9;
System.out.println(count);
}
}
Type javac Mint.java. The file is fine, so javac writes no line. The second storing line is allowed to omit int, and that omission does not make javac fail. Then type java Mint. The screen shows 4, and the next line is 9. Two lines. No quotes. The name count is on neither line. If both lines say 4, the second storing line is missing or still says 4. If both say 9, the first storing line already says 9, or the first writing line sits below the change. The screen follows the order of the lines in the file.
Do not write int a second time for the same name. int count = 9;, placed under a line that already created count, is a different mistake. That line tries to create count again. javac writes an error and does not stay quiet. You do not need the exact words of that error. Do not type java Mint yet. Delete the second int and leave count = 9;. The name is created once. Later lines only change the number it holds. On the file you keep there is no second storing line. After you have seen 4 and then 9, put that file back: one int count = 4; and one System.out.println(count);.
Letters do not fit a whole number
int means a whole number. A word between quotes is letters, the kind you stored on the page before the keyboard page. int count = "leaf"; asks an int name to hold letters. Those do not fit. javac writes an error. It does not stay quiet. There is no screen to read, because you do not type java Mint while javac is writing an error. The repair is to store a whole number with no quotes, int count = 4;, or to change the kind word if you meant letters. Changing the kind word to String makes String count = "leaf";, which is the letter kind, not the file you keep. This page keeps int and keeps 4.
Quotes around the digits are the same mismatch. int count = "4"; still has quotes, so the 4 is letters, one digit long. javac writes an error. It does not turn those letters into the whole number 4. Delete the quotes if the kind word is int. A decimal point is also not a whole number. int count = 4.5; makes javac write an error. The file you keep has 4, with no point and no digit after a point. You do not need the exact words of any of these errors. Each of them is a line from javac, so you do not run java Mint until the storing line is int count = 4; again and javac writes no line.
This third file is the letter mismatch. It is not the file you keep. Save it only until javac writes the error, then put int count = 4; back.
public class Mint {
public static void main(String[] args) {
int count = "leaf";
System.out.println(count);
}
}
Type javac Mint.java. javac writes an error. Do not type java Mint. Replace "leaf" with 4 and delete the quotes, so the line is int count = 4;. Save. Type javac Mint.java again. Now javac writes no line. Then java Mint writes 4.
The name still has to exist before a line uses it. If System.out.println(count); is written above int count = 4;, javac writes an error. The writing line names count before count exists. Move the int line above the writing line. This is the same order you already used for plant and for reader. The file you keep already has that order.
Two kinds in one file
A file can hold a letter name and a whole-number name together. The kind word on each storing line is what makes them different. String plant = "leaf"; stores letters, and the quotes are required around leaf. int count = 4; stores a whole number, and there are no quotes around 4. Two writing lines follow, one for each name. The first writes leaf. The second writes 4. Two screen lines. The names plant and count are not on the screen.
This is the fourth file. It is not the file you keep. The file you keep has only the whole number, and its screen is 4 alone. Save this fourth file when you want to see the two kinds, then put the single int line and the single writing line back.
public class Mint {
public static void main(String[] args) {
String plant = "leaf";
int count = 4;
System.out.println(plant);
System.out.println(count);
}
}
Type javac Mint.java. The file is fine, so javac writes no line. A String line and an int line in the same main are allowed. Then type java Mint. The screen shows leaf, and the next line is 4. If both lines are leaf, the second writing line still uses plant, or count was stored as letters and the writing line prints those letters. If both lines are 4, the String line stores "4" or the first writing line uses count. Look at which name each writing line uses, and look at which storing line has quotes.
You can now store a whole number in a name and write that number without quotes and without the keyboard. int count = 4; stores 4. System.out.println(count); writes 4 and ends the line. A later count = 9; changes the stored number without a second int. Letters, a quoted digit, and a decimal do not fit int, and javac writes an error for each of them. A String name can sit beside the int name, and each writing line shows its own kind. The next page stays with letters. It looks at the String kind more closely than the one line leaf you already know how to store.
The screen is the number the name holds
The file you keep writes 4. The name on the writing line is count, and count is not on the screen. There are no quotes in that file. One println is one line. Changing the stored number between two println lines changes the second screen line only.
🧠 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