How to check NULL in IOS or Android !

A null indicates that a variable doesn’t point to any object and holds no value. You can use a basic ‘if’ statement to check a null in a piece of code. Null is commonly used to denote or verify the non-existence of something.

null is an object. Its type is object. null is a special value meaning “no value. undefined is not an object, it’s type is undefined.

The SQL NULL is the term used to represent a missing value. A NULL value in a table is a value in a field that appears to be blank. A field with a NULL value is a field with no value. It is very important to understand that a NULL value is different than a zero value or a field that contains spaces.

An empty string, however, is a value – it is a string of no characters. Null is essentially ‘nothing’ – it’s the default ‘value’ (to use the term loosely) that Java assigns to any Object variable that was not initialized. Null isn’t really a value – and as such, doesn’t have properties.

NullPointerException is a RuntimeException . In Java, a special null value can be assigned to an object reference. NullPointerException is thrown when an application attempts to use an object reference that has the null value. These include: Calling an instance method on the object referred by a null reference.

IOS

The NULL value for Objective-C objects (type id) is nil.

While NULL is used for C pointers (type void *).

  1. nil = (all lower-case) is a null pointer to an Objective-C object.
  2. Nil = (capitalized) is a null pointer to an Objective-C class.
  3. NULL = (all caps) is a null pointer to anything else (C pointers, that is).
  4. [NSNull null] = (singleton) for situations where use of nil is not possible (adding/receiving nil to/from NSArrays e.g.)

 

 

 

  1. #define SAFESTRING(str) ISVALIDSTRING(str) ? str : @””
  2. #define ISVALIDSTRING(str) (str != nil && [str isKindOfClass:[NSNull class]] == NO)
  3. #define VALIDSTRING_PREDICATE [NSPredicate predicateWithBlock:^(id evaluatedObject, NSDictionary *bindings) {return (BOOL)ISVALIDSTRING(evaluatedObject);}]

 

ANDROID

One of the most common pitfalls in many programming languages, including Java, is that accessing a member of a null reference will result in a null reference exception. In Java this would be the equivalent of a NullPointerException or NPE for short.

An explicit call to throw NullPointerException();
Usage of the !! operator that is described below;

Attempts to access a member on a null reference of a platform type;

Generic types used for Java interoperation with incorrect nullability, e.g. a piece of Java code might add null into a Kotlin MutableList<String>, meaning that MutableList<String?> should be used for working with it;

Nullable types and Non-Null Types

if (userEmail.isNullOrEmpty())

if (userEmail.isNullOrBlank())