Reference data types let you work with objects and store their addresses instead of simple values. This helps you manage complex data like text, lists, or custom things.
Reference data types in Java
ClassName variableName = new ClassName();Reference variables store the address of the object, not the actual data.
You create an object using the new keyword followed by the class constructor.
name.String name = new String("Alice");
Scanner input = new Scanner(System.in);
numbers.int[] numbers = new int[5];
This program creates a String object and an integer array object. It prints the greeting and then prints each score from the array.
import java.util.Scanner; public class ReferenceExample { public static void main(String[] args) { String greeting = new String("Hello, world!"); System.out.println(greeting); int[] scores = new int[3]; scores[0] = 90; scores[1] = 85; scores[2] = 78; System.out.println("Scores:"); for (int score : scores) { System.out.println(score); } } }
Reference variables can be set to null to mean they point to no object.
Two reference variables can point to the same object, so changing the object via one variable affects the other.
Primitive types like int or double store actual values, not references.
Reference data types store addresses to objects, not the actual data.
Use new to create objects and assign their references to variables.
Reference types let you work with complex data like text, arrays, and custom objects.