- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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);
- Related Articles
- What is Java String literal?
- Is null a keyword in Java?
- Hexadecimal integer literal in Java
- What is 0 (zero) - A decimal literal or An octal literal in C++
- Why String literal is stored in String Constant Pool in Java?
- What is the difference between a String object and a String literal in Java?
- Hexadecimal literal of type long in Java
- Pattern LITERAL field in Java with examples
- What is a function literal in JavaScript?
- What is a string literal in C++?
- Check if a String is empty ("") or null in Java
- Concatenate null to a string in Java
- Check if a String is whitespace, empty ("") or null in Java
- Check if a String is not empty ("") and not null in Java
- Calling a method using null in Java\n

Advertisements