#2-Known is a drop! JAVA - Datatypes
Source: Dev.to
Data types in JAVA
A datatype in programming defines the type of data a variable can hold, how much memory it occupies, and what operations can be performed on it.
Java is a statically‑typed language because variable types are checked at compile time and must be explicitly declared.
Java has primitive data types and non‑primitive data types.
Variable Nomenclature
Rules
- Must start with a letter,
_, or$ - Cannot start with a number
- Cannot use Java keywords
- Case‑sensitive
- No spaces allowed
Conventions (Best Practice)
- Use
camelCase→studentAge,totalMarks - Use meaningful names
- Avoid single‑letter names (except
i,jin loops) - Constants →
UPPERCASE(e.g.,MAX_SIZE,PI)
Primitive Datatypes

Why Byte Size Matters for Different Data Types
- Range matters because it defines what numbers a variable can safely store.
- Too small → overflow / wrong results
- Too large → wastes memory
Understanding 2’s Complement

Default Values
If a field is declared but not initialized, the compiler assigns a default value (typically 0 for numeric types, false for boolean, and null for reference types). Relying on these defaults is generally considered bad programming style.
Using Underscore Characters in Numeric Literals (Java 7+)
Underscores can appear anywhere between digits to improve readability.
long creditCardNumber = 1234_5678_9012_3456L;
long socialSecurityNumber = 999_99_9999L;
float pi = 3.14_15F;
long hexBytes = 0xFF_EC_DE_5E; // hexadecimal literal
long hexWords = 0xCAFE_BABE;
byte by = 0b0010_0101; // binary literal, value 37 decimal