Reference values
Description
A reference points to an object.
Explanation
A reference can also be null when it points to no object.
Example
String name = "Aditi";← Chapter 2 — Core Syntax & Data
mixed
Non-primitive values are objects or references to objects. Strings, arrays, classes, and interfaces are common examples.
A String represents text and offers useful methods. Unlike a primitive, it can refer to an object and has behavior such as length and substring.
A reference points to an object.
A reference can also be null when it points to no object.
String name = "Aditi";Strings provide operations for text.
String objects are immutable, so methods return new strings.
int letters = name.length();A String is written with double quotes. Because strings are objects, compare their text with equals rather than ==, which compares references.
public class StringTypeDemo {
public static void main(String[] args) {
String learner = "Aditi";
System.out.println(learner.length());
}
}