null in java
时间: 2023-09-26 09:11:22 浏览: 38
In Java, `null` is a special literal that represents the absence of any value. It is often used to indicate that a variable or object reference does not refer to any object.
For example, if you declare a variable of type `String` but don't assign it a value, it will have the default value of `null`. Similarly, if you assign a variable of type `Object` to `null`, it means that the variable does not refer to any object.
It is important to handle `null` values properly in Java code to avoid potential NullPointerException errors. You can check if a variable or object reference is `null` using the `==` operator, like this:
```
String str = null;
if (str == null) {
System.out.println("str is null");
}
```
This code will print "str is null" because the `str` variable is currently assigned to `null`.