Java "NullPointerException" Program
Here we are going to learn what NullPointerException in java with an example. So let's start the simple java null pointer exception program.
When we call any method by using any reference which is assigned null value then nullpointerexception occurs in java. Let's take a simple example of Java NullPointerExcepton which is given below.
NullPointerException Example in Java
class NullPointerExceptionExample
{
public void show()
{
System.out.println("not running");
}
public static void main(String args[])
{
NullPointerExceptionExample npl = null;//assigning null value to this reference
npl.show();
}
}
Now above java program will throw NullPointerException.
So, here we learned what is null pointer exception in java and when it occurs in java programs.
I think this is one of the best blog for me because this is really helpful for me. Thanks for sharing this valuable information
ReplyDeleteinternship meaning | internship meaning in tamil | internship work from home | internship certificate format | internship for students | internship letter | Internship completion certificate | internship program | internship certificate online | internship graphic design
Happy Morning team, this was Great article! Your example code provided helps to understand NullPointerException in Java in a simple and easy-to-follow manner. The clear explanation of when and why this exception occurs will help developers to avoid it in their code. Thanks for sharing this article. Refer Infycle Technologies.
ReplyDelete