- 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);
Advertisements