 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is null a literal in Java?
The null in Java is a literal of the null type. It cannot be cast to a primitive type such as int. float etc. but can be cast to a reference type. Also, null does not have the value 0 necessarily.
A program that demonstrates null in Java is given as follows:
Example
public class Demo {    public static void main(String args[]) {       String str = null;       System.out.println("Value of str is: " + str);    } }  Output
Value of str is: null
Now let us understand the above program.
In the main() method, the String str is initialized as null. Then the value of str is printed. A code snippet which demonstrates this is as follows:
String str = null; System.out.println("Value of str is: " + str);Advertisements
 