Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 7
    In j2ee projects,Nullpointer exception is very common.Some cases reference variables got null values.So You should check the variable initialization properly.And during conditional statement you should always check that flag or reference contains null or not like:- if(flag!=0) { ur code that uses flag } Commented Apr 17, 2015 at 12:58
  • 18
    It is worth mentioning that some IDEs (e.g. Eclipse) offer automatic nullity analisys based on customizable annotations (e.g. @Nullable as listed above) and warn about potential errors. It is also possible to infer and generate such annotations (e.g. IntelliJ can do that) based on existing code structure. Commented Mar 5, 2016 at 10:34
  • 7
    First thing should do is before using a nullable object, you should check whether is it null, using if (obj==null).If it is null then you should write code to handle that also. Commented Feb 17, 2017 at 6:52
  • 7
    IMO, it is preferable to avoid returning null objects in methods when possible and use annotation when null input parameters are not allowed in order to, by contract, reduce the amount of ´if (obj==null)´ in the code and improve the code readability. Commented Feb 27, 2017 at 9:43
  • 7
    Read this ... before you accept these "best practices" as truth: satisfice.com/blog/archives/27 Commented May 21, 2017 at 7:52