(FRONT) FRONT (2016)

Java Null

1. The Concept of "Nothing":

2. null in Java:

   1:      String myString = null; // myString is null
   2:      if (myString == null) {
   3:          System.out.println("myString is null");
   4:      }

3. null in C#:


   1:      string myString = null; // myString is null
   2:      if (myString == null) {
   3:          Console.WriteLine("myString is null");
   4:      }

4. null and undefined in JavaScript:


   1:  let myString = null; // myString is null 
   2:  let myOtherString; // myOtherString is undefined 
   3:  if (myString === null) {
   4:      console.log("myString is null");
   5:  }
   6:  if (myOtherString === undefined) {
   7:      console.log("myOtherString is undefined");
   8:  }

5. Optional Types in C#:

Nullable Value Types: C# has a feature called Nullable types. This allows you to have a value type that can also be null.


   1:  int? myInt = null; // myInt can be null

6. Optional Types in Java:

Optional Class: Java has a class called Optional that can be used to represent the absence of a value.


   1:      import java.util.Optional;
   2:   
   3:      public class Main {
   4:          public static void main(String[] args) {
   5:              Optional < String > myString = Optional.ofNullable(null);
   6:              System.out.println(myString.isPresent()); // false
   7:          }
   8:      }

7. Optional Chaining in JavaScript:

Optional Chaining: JavaScript has a feature called optional chaining that allows you to access a property of an object even if the object is null or undefined.


   1:  let myObject = null; console.log(myObject?.name); // undefined

8. Null-Coalescing Operator in C#:

Null-Coalescing Operator: C# has a feature called the null-coalescing operator (??) that allows you to provide a default value if a variable is null.


   1:  string myString = null;
   2:  string myOtherString = myString ?? "default"; // myOtherString is "default"

9. Null-Coalescing Operator in JavaScript:

Null-Coalescing Operator: JavaScript has a feature called the null-coalescing operator (??) that allows you to provide a default value if a variable is null or undefined.


   1:  let myString = null; let myOtherString = myString ?? "default"; // myOtherString is "default"

10. Null-Conditional Operator in C#:

Null-Conditional Operator: C# has a feature called the null-conditional operator (?.) that allows you to access a member of an object even if the object is null.


   1:  string myString = null;
   2:  int? length = myString?.Length; // length is null

11. Null-Conditional Operator in JavaScript:

Null-Conditional Operator: JavaScript has a feature called the null-conditional operator (?.) that allows you to access a member of an object even if the object is null or undefined.


   1:  let myObject = null; let length = myObject?.name; // length is undefined

12. Null-Conditional Operator in Java:

Null-Conditional Operator: Java does not have a direct equivalent to the null-conditional operator.

13. Summary:




Java context:



Comments ( )
Link to this page: http://www.vb-net.com/Java/Index11.htm
< THANKS ME>