🧠 Understanding Variables and Memory
let a = 27;
- The value
27
is stored in RAM (Random Access Memory). - A variable
a
acts as a reference or pointer to that memory address.
🔁 Reference and Assignment
a = 97
➝ changes the reference to a new value.- Each assignment changes the reference address of
a
.
a = null;
null
means the reference is empty.- In Java, when a variable becomes
null
, the Garbage Collector clears the memory previously held by that variable.
🧩 Data Types in Java
Java uses data types to define the kind of value a variable can hold.
📌 Variable Creation Syntax
datatype variableName = value;
Multiple variables of the same data type
data_type variableName1 = value1, variableName2 = value2;
Example : String firstName="Arunkumar", lastName = "Selvam";
Syntax of Variable Declaration & Initialization
data_type variableName; (Variable Declaration)
data_type variaableName = value; (Variable Initialization)
String userName; // Variable Declaration
String userName = "Arunkumar"; //Variable Initialization
✍️ Examples of Data Types
Type | Examples |
---|---|
Text | char , String |
Number | int , float , long , double |
📦 Java Data Type Categories
-
Primitive Data Types (Built-in language types):
char
,int
,float
,long
,double
,boolean
-
User-Defined Data Types:
String
(Actually a class, not a primitive)
**
🧮 Binary & Decimal Conversion Study Notes
📌 1 Byte = 8 Bits
A byte contains 8 bits, and each bit is either 0 or 1:
00000000
🔁 Decimal to Binary Conversion
Example: Convert 27 to binary
27 ÷ 2 = 13, remainder 1
13 ÷ 2 = 6, remainder 1
6 ÷ 2 = 3, remainder 0
3 ÷ 2 = 1, remainder 1
1 ÷ 2 = 0, remainder 1
Binary Representation of 27 = 11011
🔁 Binary to Decimal Conversion
Example: Convert 11011
to Decimal
(1 × 2⁴) + (1 × 2³) + (0 × 2²) + (1 × 2¹) + (1 × 2⁰)
= 16 + 8 + 0 + 2 + 1
= 27
🧠 More Practice: Convert 97 to Binary
97 ÷ 2 = 48, remainder 1
48 ÷ 2 = 24, remainder 0
24 ÷ 2 = 12, remainder 0
12 ÷ 2 = 6, remainder 0
6 ÷ 2 = 3, remainder 0
3 ÷ 2 = 1, remainder 1
1 ÷ 2 = 0, remainder 1
Binary of 97 = 1100001
🧮 Convert 1100001
to Decimal
(1 × 2⁶) + (1 × 2⁵) + (0 × 2⁴) + (0 × 2³) + (0 × 2²) + (0 × 2¹) + (1 × 2⁰)
= 64 + 32 + 0 + 0 + 0 + 0 + 1
= 97
Variable Naming Convention
- Variable names are case-sensitive.
- In Java, variable names should follow camelCase (e.g.,
firstName
,lastName
). - They should not start with special characters like & (ampersand), $ (dollar), or _ (underscore).
- Avoid using single-character variables like
x
,y
, orz
.
Byte | -128 to 127 | 0 | |
Short | -32,768 to 32,767 | 0 | |
Int | -2,147,483,648 (-231) to 2,147,483,647 (231-1). | 0 | |
Long | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 0L | |
Float | 6 to 7 decimal point | 0.0f | |
Double | 15 decimal point | 0.0d | |
Char | single character/letter or ASCII values is -128 to 127 | '\u0000' | |
Boolean | true or false values | false |
Bit - Binary Digit - 0, 1s
Base 2 - 0, 1
Base 8 - 01234567
Base 10 - 0123456789
Base 16 - 0123456789ABCDEF
ASCII - American Standard for Code Information Interchange