KwickAcademy Java · 7 min · free
Data Types, Variables and Constants in Java
The eight primitive types with sizes and ranges, reference types, declaring and initialising variables, final constants and default values.
Follows the syllabus of: CBSE Class 11 Information Technology (802), ICSE Class 9 Computer Applications, ICSE Class 10 Computer Applications, ISC Class 11 Computer Science (868)
On screen in this lesson
What is a data type?
| Data type: what kind of value, and how much memory |
| Variable: a named box that holds one value |
| Primitive types: 8 simple built-in types |
| Reference types: objects like String and arrays |
Whole number types
| Type | Size | Range |
|---|---|---|
| byte | 1 byte | -128 to 127 |
| short | 2 bytes | -32768 to 32767 |
| int | 4 bytes | about ±2.1 billion |
| long | 8 bytes | about ±9.2 x 10^18 |
Decimal, char and boolean
| Type | Size | Holds |
|---|---|---|
| float | 4 bytes | about 7 digits |
| double | 8 bytes | about 15 digits |
| char | 2 bytes | one Unicode char |
| boolean | JVM decides | true or false |
Reference types
| Examples: String, arrays, classes, interfaces |
| The variable stores a reference to an object |
| The object itself lives in a separate memory area |
| A reference with no object holds null |
Primitive vs reference
| Point | Primitive | Reference |
|---|---|---|
| Holds | the value | an address |
| Examples | int, char | String, int[] |
| Can be null? | no | yes |
| Name starts | lowercase | Capital (classes) |
Rules while declaring
| Type first, then name: int age; |
| Several at once: int a = 5, b = 7; |
| A long literal ends in L, a float literal in f |
| A local variable must get a value before it is used |
Quick answers
Why is a char 2 bytes in Java?
Because Java uses Unicode, which covers Hindi, Gujarati and many other scripts.
Do local variables get a default value?
No. Only fields, static variables and array elements do.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
How big is a char in Java?44 sec
Is String a primitive type?41 sec
Why won't my program compile after int total;?37 sec
What does final do?36 sec
What does an int field with no value print?40 secThe full lesson, in text
Hello students, welcome to Kwickprep. Why does Java need to know that marks is a whole number and price is a decimal? Because every value needs the right kind of box in memory. Today we learn the eight primitive types, reference types, variables, constants with final, and default values.
Let us start with two new terms. A data type tells Java what kind of value is stored, and how much memory it needs. A variable is a named box in memory that holds one value. Java has eight primitive types, which are simple types built into the language. All other types are reference types, like String, arrays and the classes we write.
Four primitive types store whole numbers, from small to big. Byte uses one byte and stores from minus one twenty eight to one twenty seven. Short uses two bytes, and goes up to about thirty two thousand. Int uses four bytes, and goes up to about two point one billion. It is the usual choice. Long uses eight bytes, for very big values like a phone number or the population of India.
The other four primitive types hold decimals, characters and truth values. Float uses four bytes and is accurate to about seven digits. Double uses eight bytes and is accurate to about fifteen digits, so it is the default for decimals. Char uses two bytes, because Java uses Unicode, which covers Hindi, Gujarati and many other scripts. Boolean holds only true or false. Its exact size is left to the J V M, though many textbooks write one bit.
Now the second family, reference types, also called non primitive types. Examples are String, arrays, classes and interfaces. A reference variable does not hold the object itself. It holds a reference, which is like the address of the object. The object is created separately in memory, usually with the word new. If a reference points to no object at all, its value is null.
Exams often ask for the differences, so compare them side by side. A primitive variable holds the value itself, and a reference variable holds an address. Int and char are primitive, and String and arrays are reference types. A primitive can never be null, but a reference can. Primitive type names are lowercase, while class names like String start with a capital.
Declaring means telling Java the type and name. Initialising means giving the first value. Here, int marks equals ninety two does both in one line. Char grade holds A in single quotes, and double fee holds fourteen ninety nine point five zero. When we print fee, Java prints fourteen ninety nine point five, because the extra zero is not shown.
Remember four rules while declaring variables. The type comes first, then the name, then a semicolon. You can declare several variables of one type, separated by commas. A big long value needs an L at the end, and a float value needs an f, or you get a compile error. A local variable, one declared inside a method, must get a value before you use it. Otherwise the error says, variable might not have been initialized.
Some values should never change, like the number of days in a week. The keyword final makes a variable a constant, which means its value is fixed after it is set. By convention, constant names are written in capitals, so DAYS. Days times twenty four is one hundred sixty eight, and that is printed.
Here are the rules for final. A final variable gets its value only once. If you write DAYS equals eight later, the compiler stops with, cannot assign a value to final variable DAYS. Constant names are written in capitals, with underscores between words. Constants also make code easier to read, because a name like DAYS explains what seven means.
Java gives default values, but only to instance variables, static variables and array elements. Whole number types start at zero. Float and double start at zero point zero. Char starts at the null character, backslash u zero zero zero zero, which prints as nothing visible. Boolean starts as false. Every reference type, like String or an array, starts as null.
Here, four static variables are declared with no values. Static means they belong to the class itself. Pause and predict the output. The int n is zero and the boolean ok is false. The String s is null and the double d is zero point zero. But if you declare int n inside main without a value and print it, you get a compile error instead. Local variables get no default.
Let us revise what we learned today. Java has eight primitive types: byte, short, int, long, float, double, char and boolean. Reference types hold addresses, and they can be null. Declare the type, then the name, and give local variables a value before use. Final makes a constant, written in capitals. Default values apply to fields and array elements, but never to local variables. Now write the size of each primitive type from memory.
Courses that teach this
| Course | Unit |
|---|---|
| CBSE Class 11 Information Technology (802) | Part B, Unit 5: Fundamentals of Java Programming |
| ICSE Class 9 Computer Applications | Elementary Concept of Objects and Classes |
| ICSE Class 10 Computer Applications | Class as the Basis of All Computation |
| ISC Class 11 Computer Science (868) | Object-Oriented Programming with Java |
| ISC Class 12 Computer Science (868) | Primitive Values, Wrapper Classes, Types and Casting |
| GSEB Std 11 Computer Studies | Advanced Scripting |
| GSEB Std 12 Computer Studies | Object-Oriented Concepts and Java Basics |
| Programming All levels Java | Classes, Objects and Methods |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

