Skip to content
AstralSurgeLearnings XP 0 Streak 0
AstralSurgeLearnings

Core Java Fundamentals I: Identifiers, Primitive Data Types, and Literals

A mastery of Java begins with its foundational primitives: how source code entities are named (identifiers), how the JVM encodes binary values (data types), and how literal values are represented in memory.

1. Java Identifiers

An identifier is the user-defined name given to a class, variable, method, or label. The Java compiler enforces strict grammatical rules:

  • Allowed Characters: Letters (A-Z, a-z), currency symbols ($), and connecting characters (_). Digits (0-9) are permitted but cannot start an identifier.
  • Case Sensitivity: Identifiers are strictly case-sensitive (salary and Salary are distinct).
  • Reserved Keywords: None of Java's 50+ reserved keywords (such as public, class, goto) can be used as identifiers.

2. Primitive Data Types in Java

Java defines 8 primitive data types whose sizes and ranges are strictly guaranteed across all processor architectures:

Type Size Binary Representation Value Range Default Value
byte8 bits (1 byte)Two's complement-128 to 1270
short16 bits (2 bytes)Two's complement-32,768 to 32,7670
int32 bits (4 bytes)Two's complement-2,147,483,648 to 2,147,483,647 (-2^31 to 2^31 - 1)0
long64 bits (8 bytes)Two's complement-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (-2^63 to 2^63 - 1)0L
float32 bits (4 bytes)IEEE 754 Single precision~1.4E-45 to ~3.4E+38 (6-7 decimal precision)0.0f
double64 bits (8 bytes)IEEE 754 Double precision~4.9E-324 to ~1.7E+308 (15-16 decimal precision)0.0d
booleanJVM dependentLogical booleantrue / falsefalse
char16 bits (2 bytes)Unsigned 16-bit Unicode0 to 65,535 ('\u0000' to '\uffff')'\u0000'

3. Java Literals & Numeric Formatting

Literals represent constant values assigned directly to variables. Java supports numeric separation with underscores for enhanced readability:

// Decimal literal
int dec = 100;

// Hexadecimal literal (prefixed with 0x)
int hex = 0x2A; // Evaluates to 42

// Binary literal (prefixed with 0b)
int bin = 0b101010; // Evaluates to 42

// Long literals require 'L' suffix
long population = 8_000_000_000L;

// Floating point numbers default to double; 'F' denotes float
float temp = 98.6F;
double pi = 3.1415926535;

4. Implicit Primitive Widening Promotions

When evaluating binary numeric expressions, Java automatically promotes types according to the following precedence hierarchy:

byte -> short -> int -> long -> float -> double

Note that operations involving operands smaller than int (such as adding two byte values) automatically promote both operands to int before performing the addition.

0 Comments