Once you click post assignment, learners in the selected class will immediately be able to see and complete this assignment
Back to Classroom
Null Value
Java Basics Course
Engineers From These Top Companies and Universities Trust EXLskills
1M+ Professionals | 100+ Institutions
This is the EXLskills free and open-source Java Basics Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency.
-->
Is this course FREE?
Yes, this a 100% free course that you can contribute to on GitHub here!
"Null" is a value that signifies "no object". If we declare a new String object and forgets to initialize it with a value, it will have a value of null. A String can also be initialized with a value of null as follows: String varOne = null;. Take a look at the example below.
NullValueExample.java
package exlcode;
public class NullValueExample {
// exampleVariableOne is only declared and not initialised
public static String exampleVariableOne;
public static void main(String[] args) {
System.out.println(exampleVariableOne);
}
}
In Java, variables created from the String class are like containers, they hold a reference to an object. Therefore, creating 10 strings will create 10 objects and 10 different variables that refer to the different objects. If variables that hold objects exist, we need a way to describe those variables that are not holding or referencing anything - this is where the null value comes in. It tells us that nothing is being held or referenced by the String.