Is null an instance of anything?

No, there is no type which null is an instanceof.

15.20.2 Type Comparison Operator instanceof

RelationalExpression:
    RelationalExpression instanceof ReferenceType

At run time, the result of the instanceof operator is true if the value of the RelationalExpression is not null and the reference could be cast to the ReferenceType without raising a ClassCastException. Otherwise the result is false.

This means that for any type E and R, for any E o, where o == null, o instanceof R is always false.


What set does 'null' belong to?

JLS 4.1 The Kinds of Types and Values

There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.


What is null?

As the JLS quote above says, in practice you can simply pretend that it's "merely a special literal that can be of any reference type".

In Java, null == null (this isn't always the case in other languages). Note also that by contract, it also has this special property (from java.lang.Object):

public boolean equals(Object obj)

For any non-null reference value x, x.equals(null) should return false.

It is also the default value (for variables that have them) for all reference types:

JLS 4.12.5 Initial Values of Variables

  • Each class variable, instance variable, or array component is initialized with a default value when it is created:
    • For all reference types, the default value is null.

How this is used varies. You can use it to enable what is called lazy initialization of fields, where a field would have its initial value of null until it's actually used, where it's replaced by the "real" value (which may be expensive to compute).

There are also other uses. Let's take a real example from java.lang.System:

public static Console console()

Returns: The system console, if any, otherwise null.

This is a very common use pattern: null is used to denote non-existence of an object.

Here's another usage example, this time from java.io.BufferedReader:

public String readLine() throws IOException

Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.

So here, readLine() would return instanceof String for each line, until it finally returns a null to signify the end. This allows you to process each line as follows:

String line;
while ((line = reader.readLine()) != null) {
   process(line);
}

One can design the API so that the termination condition doesn't depend on readLine() returning null, but one can see that this design has the benefit of making things concise. Note that there is no problem with empty lines, because an empty line "" != null.

Let's take another example, this time from java.util.Map<K,V>:

V get(Object key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Here we start to see how using null can complicate things. The first statement says that if the key isn't mapped, null is returned. The second statement says that even if the key is mapped, null can also be returned.

In contrast, java.util.Hashtable keeps things simpler by not permitting null keys and values; its V get(Object key), if returns null, unambiguously means that the key isn't mapped.

You can read through the rest of the APIs and find where and how null is used. Do keep in mind that they aren't always the best practice examples.

Generally speaking, null are used as a special value to signify:

  • Uninitialized state
  • Termination condition
  • Non-existing object
  • An unknown value

How is it represented in the memory?

In Java? None of your concern. And it's best kept that way.


Is null a good thing?

This is now borderline subjective. Some people say that null causes many programmer errors that could've been avoided. Some say that in a language that catches NullPointerException like Java, it's good to use it because you will fail-fast on programmer errors. Some people avoid null by using Null object pattern, etc.

This is a huge topic on its own, so it's best discussed as answer to another question.

I will end this with a quote from the inventor of null himself, C.A.R Hoare (of quicksort fame):

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

The video of this presentation goes deeper; it's a recommended watch.

Answer from polygenelubricants on Stack Overflow
Top answer
1 of 14
330

Is null an instance of anything?

No, there is no type which null is an instanceof.

15.20.2 Type Comparison Operator instanceof

RelationalExpression:
    RelationalExpression instanceof ReferenceType

At run time, the result of the instanceof operator is true if the value of the RelationalExpression is not null and the reference could be cast to the ReferenceType without raising a ClassCastException. Otherwise the result is false.

This means that for any type E and R, for any E o, where o == null, o instanceof R is always false.


What set does 'null' belong to?

JLS 4.1 The Kinds of Types and Values

There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.


What is null?

As the JLS quote above says, in practice you can simply pretend that it's "merely a special literal that can be of any reference type".

In Java, null == null (this isn't always the case in other languages). Note also that by contract, it also has this special property (from java.lang.Object):

public boolean equals(Object obj)

For any non-null reference value x, x.equals(null) should return false.

It is also the default value (for variables that have them) for all reference types:

JLS 4.12.5 Initial Values of Variables

  • Each class variable, instance variable, or array component is initialized with a default value when it is created:
    • For all reference types, the default value is null.

How this is used varies. You can use it to enable what is called lazy initialization of fields, where a field would have its initial value of null until it's actually used, where it's replaced by the "real" value (which may be expensive to compute).

There are also other uses. Let's take a real example from java.lang.System:

public static Console console()

Returns: The system console, if any, otherwise null.

This is a very common use pattern: null is used to denote non-existence of an object.

Here's another usage example, this time from java.io.BufferedReader:

public String readLine() throws IOException

Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.

So here, readLine() would return instanceof String for each line, until it finally returns a null to signify the end. This allows you to process each line as follows:

String line;
while ((line = reader.readLine()) != null) {
   process(line);
}

One can design the API so that the termination condition doesn't depend on readLine() returning null, but one can see that this design has the benefit of making things concise. Note that there is no problem with empty lines, because an empty line "" != null.

Let's take another example, this time from java.util.Map<K,V>:

V get(Object key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Here we start to see how using null can complicate things. The first statement says that if the key isn't mapped, null is returned. The second statement says that even if the key is mapped, null can also be returned.

In contrast, java.util.Hashtable keeps things simpler by not permitting null keys and values; its V get(Object key), if returns null, unambiguously means that the key isn't mapped.

You can read through the rest of the APIs and find where and how null is used. Do keep in mind that they aren't always the best practice examples.

Generally speaking, null are used as a special value to signify:

  • Uninitialized state
  • Termination condition
  • Non-existing object
  • An unknown value

How is it represented in the memory?

In Java? None of your concern. And it's best kept that way.


Is null a good thing?

This is now borderline subjective. Some people say that null causes many programmer errors that could've been avoided. Some say that in a language that catches NullPointerException like Java, it's good to use it because you will fail-fast on programmer errors. Some people avoid null by using Null object pattern, etc.

This is a huge topic on its own, so it's best discussed as answer to another question.

I will end this with a quote from the inventor of null himself, C.A.R Hoare (of quicksort fame):

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

The video of this presentation goes deeper; it's a recommended watch.

2 of 14
33

Is null an instance of anything?

No. That is why null instanceof X will return false for all classes X. (Don't be fooled by the fact that you can assign null to a variable whose type is an object type. Strictly speaking, the assignment involves an implicit type conversion; see below.)

What set does 'null' belong to?

It is the one and only member of the null type, where the null type is defined as follows:

"There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type." JLS 4.1

What is null?

See above. In some contexts, null is used to denote "no object" or "unknown" or "unavailable", but these meanings are application specific.

How is it represented in the memory?

That is implementation specific, and you won't be able to see the representation of null in a pure Java program. (But null is represented as a zero machine address / pointer in most if not all Java implementations.)

🌐
Upwork
upwork.com › resources › articles › {name}
Null in Java: Understanding the Basics - Upwork
August 5, 2024 - Hoare introduced null to signify a reference that does not point to any object, believing it would be a convenient way to handle uninitialized variables or missing data. However, he later referred to it as his "billion-dollar mistake" due to the numerous bugs and issues it has caused in software development over the years. Java's creators included null to provide a standard way to represent the absence of a value in object-oriented programming.
Discussions

java.lang.RuntimeException: null - Support & Bug Reports - Forge Forums
A better way to browse. Learn more · A full-screen app on your home screen with push notifications, badges and more More on forums.minecraftforge.net
🌐 forums.minecraftforge.net
August 15, 2025
FResult: A unified approach to null safety and error handling in Java
Nice as an exercise for the person who wrote that. Other than that it goes against the idiom and is unlikely to gain traction. Of course, this approach works very well for languages that support pattern matching. More on reddit.com
🌐 r/java
44
66
May 23, 2021
Why ConcurrentHashMap does not support null values

The title would more correctly be "Why does ConcurrentHashMap not support null keys or values". Neither supports nulls.

The reason ConcurrentHashMap does not support null keys is that Doug Lea didn't want to include key masking, the use of a special value for signifying NULL such as NULL_OBJECT in zathar's example in ConcurrentHashMap. Null values are disallowed because with null values in the map the result of get() is ambiguous as to whether the key was not found or the mapping for that key is null, ie. you are required to use containsKey() to determine if there is a mapping for a key, get() is ambiguous because the mapping could be key -> null

For HashMap/Hashtable :

 Object value;
 if(map.containsKey(key))
    value = map.get(key);
else
    throw new NoSuchElementException("No mapping for " + key);

For ConcurrentHashMap/TreeMap:

 Object value = map.get(key);
 if(null == value) 
     throw new NoSuchElementException("No mapping for " + key);

Generally, allowing null membership in Collections is regarded as a mistake. All future Java APIs especially collections will be null hostile. Null, if used in the API at all, will be used for signifying conditions (such as no mapping for a key being present) rather than as a value of the collection.

More on reddit.com
🌐 r/java
9
32
February 23, 2011
Java lang null pointer exception when using a spinner...
I am assuming this is line 24? spinner.setAdapter(adapter); And spinner is null? According to the docs, findViewById returns "The view if found or null otherwise." Verify that R.id.spinner actually points at something that exists. More on reddit.com
🌐 r/androiddev
10
2
October 2, 2014
🌐
Rollbar
rollbar.com › home › how to catch and fix nullpointerexception in java
NullPointerException Crash Your Java App? Here's How to Fix It
1 week ago - NullPointerException is the most frequently thrown exception in Java applications, accounting for countless crashes.
🌐
heise online
heise.de › en › news › Spring-Framework-7-brings-new-concept-for-null-safety-and-relies-on-Java-25-11078745.html
Spring Framework 7 brings new concept for null safety and relies on Java 25 | heise online
3 weeks ago - For the JDK, Spring Framework 7 targets Java 25, and for Enterprise Java, Jakarta EE 11 is the base. For interoperability with Kotlin, it relies on version 2.2 of the programming language, and for unit tests, it works with JUnit 6.0. To prevent errors from handling null pointers -- the inventor of the null reference, Tony Hoare, apologized in 2009 for the "billion-dollar mistake"-- the current Spring Framework uses JSpecify.
🌐
DataCamp
datacamp.com › doc › java › null
null Keyword in Java: Usage & Examples
Java keywordsIntroduction To JavaJava File HandlingJava Language BasicsJava ArraysJava Object-Oriented Programming ... The null keyword in Java is a literal that represents a null reference, one that points to no object.
🌐
Spring
spring.io › blog › 2025 › 11 › 12 › null-safe-applications-with-spring-boot-4
Null-safe applications with Spring Boot 4
3 weeks ago - If you make it explicit, nullability becomes a zero cost abstraction for expressing the potential absence of value, backward compatible with existing APIs. JSpecify has been designed to provide a set of annotations, with related documentation allowing Java codebases to express explicitly the ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › null-pointer-exception-in-java
Null Pointer Exception in Java - GeeksforGeeks
August 5, 2025 - In Java, "null" is a special value that can be assigned to object references to indicate the absence of a value.
🌐
Kotlin
kotlinlang.org › docs › java-to-kotlin-nullability-guide.html
Nullability in Java and Kotlin | Kotlin Documentation
1 month ago - Learn more about null safety in Kotlin. The most important difference between Kotlin's and Java's type systems is Kotlin's explicit support for nullable types. It is a way to indicate which variables can possibly hold a null value. If a variable can be null, it's not safe to call a method on the variable because this can cause a NullPointerException.
🌐
Baeldung
baeldung.com › home › java › what is the null type in java?
What Is the null Type in Java? | Baeldung
January 8, 2024 - In the world of Java, the null type is pervasive, and it’s hard to use the language without encountering it. In most cases, the intuitive understanding that it represents nothingness or lack of something suffices to program effectively.
🌐
Baeldung
baeldung.com › home › java › avoid check for null statement in java
Avoid Check for Null Statement in Java | Baeldung
January 8, 2024 - Here, @NonNull makes it clear that the argument cannot be null. If the client code calls this method without checking the argument for null, FindBugs would generate a warning at compile time. Developers generally rely on IDEs for writing Java code.
🌐
W3Schools
w3schools.com › sql › sql_null_values.asp
SQL NULL Values - IS NULL and IS NOT NULL
SELECT CustomerName, ContactName, Address FROM Customers WHERE Address IS NOT NULL; Try it Yourself » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected] · If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected] · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
W3Schools
w3schools.com › java › java_ref_keywords.asp
Java Keywords
Java has a set of keywords that are reserved words that cannot be used as variables, methods, classes, or any other identifiers: Note: true, false, and null are not keywords, but they are literals and reserved words that cannot be used as identifiers.
🌐
Sumo Logic
sumologic.com › log search › search query language › search operators › isnull, isempty, isblank
isNull, isEmpty, isBlank Search Operators | Sumo Logic Docs
1 month ago - * The isNull operator checks a string and returns a boolean value: true if the string is null, or false if the string is not null.
🌐
codestudy
codestudy.net › blog › best-way-to-verify-string-is-empty-or-null
Best Way to Verify if a String is Empty or Null in Java: Performance & Memory-Efficient Methods — codestudy.net
November 3, 2025 - In Java, handling strings is a fundamental task, and one common requirement is verifying whether a string is `null`, empty, or blank (contains only whitespace). Incorrectly checking these conditions can lead to bugs like `NullPointerException` (NPE), invalid business logic, or unnecessary memory ...
🌐
DEV Community
dev.to › cheol_jeon_9e29b98fdb7e1e › jplus-a-java-superset-with-null-safety-and-boilerplate-elimination-46md
JPlus – A Java Superset with Null Safety and Boilerplate Elimination - DEV Community
October 22, 2025 - JPlus is a modern programming language and compiler that acts as a superset of Java — bringing the benefits of null safety, concise syntax, and powerful declarative features while remaining fully interoperable with existing Java code and libraries.
🌐
GeeksforGeeks
geeksforgeeks.org › java › types-of-java-variables
Types of Java Variables - GeeksforGeeks
October 3, 2025 - Instance Variables are not mandatory to initialize; take default values based on data type (0 for int, null for String, etc.). Scope is throughout the class, except in static contexts. Accessed only through objects of the class. Instance Variables can be initialized using constructors or instance blocks. Example: This example demonstrates the use of instance variables, which are declared within a class and initialized via a constructor, with default values for uninitialized primitive types. ... import java.io.*; class Geeks { // Declared Instance Variable public String geek; public int i; publ
🌐
SAP Community
community.sap.com › t5 › technology-q-a › error-with-select-null-from-cannot-convert-sql-type-char-byte-to-java-type › qaq-p › 14229033
Error with 'Select null from...': Cannot convert SQL type CHAR BYTE to Java type int.
September 26, 2025 - Since Hibernate version >= 6.6.0.CR1, SQL statements like the following are generated in certain @ManyToMany configurations: select null from ... where ... This leads to the following error with the current JDBC driver sapdbc-7.6.11.jar and our MaxDB (full strack trace is attached below): com.sap.db...
🌐
Medium
medium.com › square-corner-blog › non-null-is-the-default-58ffc0bb9111
Non-null is the Default. Using annotations to make Java’s type… | by Jesse Wilson | Square Corner Blog | Medium
April 18, 2019 - The entire language is non-null by default and only types suffixed with ? can be null. If you’re calling Java APIs from Kotlin, you need to be a bit more careful. The language doesn’t yet honor @ParametersAreNonnullByDefault when it’s used to call Java APIs.
🌐
DEV Community
dev.to › headf1rst › solving-the-billion-dollar-mistake-modern-java-null-safety-with-jspecify-and-nullaway-2ie7
Solving the Billion-Dollar Mistake: Modern Java Null Safety with JSpecify and NullAway - DEV Community
September 24, 2025 - JSpecify is more than just a set of annotations; it provides a clear specification for null safety, ensuring consistent behavior across tools like IDEs and static analyzers. ... Unspecified: The default state in Java, where a value may or may not be null.
🌐
Forge Forums
forums.minecraftforge.net › home › minecraft forge › support & bug reports › java.lang.runtimeexception: null
java.lang.RuntimeException: null - Support & Bug Reports - Forge Forums
August 15, 2025 - ---- Minecraft Crash Report ---- // Embeddium instance tainted by mods: [oculus] // Please do not reach out for Embeddium support without removing these mods first. // ------- // I bet Cylons wouldn't have this problem. Time: 2025-08-14 20:57:03 Description: Rendering overlay java.lang.RuntimeExc...