Java Core Concepts: Method Overloading, Memory Allocation, and Object Construction

Method Overloading

Method overloading occurs when a class contains multiple methods sharing the same name but possessing unique parameter lists. A parameter list is considered unique if it differs in any of the following criteria:

  1. The data types of the parameters.
  2. The total number of parameters.
  3. The sequence or order of the parameters.

Object-Oriented Fundamentals

Object-oriented programming (OOP) focuses on defining entities through fields (attributes) and behaviors. While OOP provides a high-level structure for organizing code, it remains complementary to procedural programming, as the logic within methods still follows procedural flows.

Properties and Default Values

In Java, fields represent the state or static characteristics of an object. If a field is not manually initialized, the Java Virtual Machine (JVM) assigns a default value based on its type:

Data Type Default Value
Character \u0000
Boolean false
Reference Type null
Numeric (int, double, etc.) 0 or 0.0

Fields have a scope that encompasses the entire class body, allowing them to be accessed by any method within that class.

JVM Memory Architecture

The JVM utilizes two primary regions for data management: the Stack and the Heap.

Stack Memory

The Stack stores local variables, including primitive data types and memory addresses (references) of objects. The lifecycle of data in the Stack is strictly tied to the execution block. Once the current scope (the surrounding curly braces) finishes execution, the associated stack frames and variables are reclaimed immediately.

Heap Memory

The Heap is used for dynamic memory allocation, housing all objects and arrays. Whenever the new keyword is used, a new segment of memory is allocated in the Heap. While the object resides in the Heap, the variable pointing to it in the Stack merely holds its memory address.

// 'score' is a primitive stored in the Stack
int score = 95; 

// 'student' is a reference in the Stack pointing to an object in the Heap
Student student = new Student("Alice"); 

Equality Comparisons with the == Operator

The behavior of the == operator depends on the types being compared:

  • Primitive vs. Primitive: Compares the actual values.
  • Reference vs. Reference: Compares the memory addresses to see if both point to the same object in the Heap.
  • Primitive vs. Wrapper Object: The wrapper is automatically unboxed, and the comparison is performed on the values.
Integer countObj = new Integer(10);
int countPrim = 10;

// Returns true because countObj is unboxed to compare values
System.out.println(countObj == countPrim);

The Object Construction Lifecycle

When a new object is instantiated, the JVM follows a specific sequence of operations:

  1. Memory Allocation: Space is reserved in the Heap, and fields are initialized to their default values (e.g., 0 or null).
  2. Explicit Initialization: If fields are assigned values at the point of declaration, those assignments are executed now.
  3. Constructor Execution: The logic defined within the class constructor is processed.
  4. Address Assignment: The memory address of the fully initialized object is returned to the reference variable.

Key Rules for Constructors

Constructors are special methods used to initialize objects. They must adhere to the following rules:

  • They are invoked exclusively via the new keyword.
  • They must share the exact same name as the class.
  • They do not have a return type (not even void), and they cannot use return to pass back a value.
  • If no constructor is manually defined, the compiler provides a default no-argument constructor automatically.

Tags: java JVM Object-Oriented Programming Memory Management programming fundamentals

Posted on Sun, 26 Jul 2026 17:13:35 +0000 by HGeneAnthony