0

Can someone explain me what null keyword does?

I serched for information on google but didn't find any good explanation.

27th Jun 2018, 7:28 AM
Dror Dahary
Dror Dahary - avatar
6 Answers
+ 5
What language? In SQL, for instance, it's a flag to tell that a field has no value. In C and C++, the NULL macro is equivalent to 0.
27th Jun 2018, 7:30 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
You can test it out for yourself: class Test {} public class Program { public static void main(String[] args) { Test one = null; Test two = new Test(); System.out.println(one); System.out.println(two); } }
27th Jun 2018, 7:43 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
For C# and Java, null refers to a null reference, the default value of all reference type. Objects which are null, cannot be used to invoke class methods (exceptions will be thrown). https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/null https://stackoverflow.com/questions/2707322/what-is-null-in-java Quoting Roman Cherepanov in the above article - "null is used to denote non-existence of an object".
27th Jun 2018, 7:37 AM
Hatsy Rei
Hatsy Rei - avatar
0
C# / Java
27th Jun 2018, 7:31 AM
Dror Dahary
Dror Dahary - avatar
0
Good explanation! Thanks alot!
27th Jun 2018, 7:42 AM
Dror Dahary
Dror Dahary - avatar
0
Another way to see it would be that NULL is a value that indicates the variable has no useful value assigned yet. You can see it similar to \0, which indicates the end of a string in C and C++, or ony othe control character, which are also values that indicate things
28th Jun 2018, 6:57 PM
Vicent
Vicent - avatar