Questions tagged [null]

Null means *nothing* or *unknown*, depending on context. Please use the "sql-null" tag for SQL specific questions.

"Null" has different meanings depending on context.

Set theory

Null is another name for the empty set, denoted by the symbol ∅. For this reason, some programming languages use null or nil for the empty list or empty tuple. Lisp uses nil to mean the empty list and the boolean value false.

Pointers and References

Null (or sometimes nil or None), in programming languages that support it, is the value of an uninitialized variable, a pointer that doesn't point to a meaningful memory address, or an object that fails to respond to any message.

Nullable references were invented by C.A.R. Hoare in 1965 as part of the Algol W language. Hoare later described his invention as a "billion-dollar mistake".

For more information, see Null pointer.

Agreeing with Hoare's sentiment, many languages don't have a special null value, choosing to use optional types instead.

Relational Databases

NULL as a special marker in SQL or a relational database stands in place of a value that is missing, or in a join means "no corresponding row." The operators IS NULL and IS NOT NULL are required for comparisons to a literal null: other comparisons between NULL and any value evaluate to "unknown."

For more information, see Null (SQL).

ASCII

Null or NUL is the name given to the character with ASCII code zero (0) - i.e. hex 00. In some languages, notably C, NUL is used to mark the end of a character string.

For more information, see Null character.

16208 questions
102
votes
7 answers

JavaScript String concatenation behavior with null or undefined values

As you may know, in JavaScript '' + null = "null" and '' + undefined = "undefined" (in most browsers I can test: Firefox, Chrome and IE). I would like to know the origin of this oddity (what the heck was in the head on Brendan Eich?!) and if there…
Doc Davluz
  • 4,154
  • 5
  • 30
  • 32
101
votes
4 answers

Difference between NULL and null in PHP

Is there a difference between NULL and null in PHP? Sometimes they seem to be interchangeable and sometimes not. edit: for some reason when I read the documentation linked to in the answer (before posting this question) I read it as "case sensitive"…
cmcculloh
  • 47,596
  • 40
  • 105
  • 130
101
votes
6 answers

What is the difference between null and System.DBNull.Value?

Is there any difference between null and System.DBNull.Value? If yes, what is it? I noticed this behavior now - while (rdr.Read()) { if (rdr["Id"] != null) //if (rdr["Id"] != System.DBNull.Value) { int x =…
pavanred
  • 12,717
  • 14
  • 53
  • 59
101
votes
9 answers

Best way to check if an PowerShell Object exist?

I am looking for the best way to check if a Com Object exists. Here is the code that I have; I'd like to improve the last line: $ie = New-Object -ComObject InternetExplorer.Application $ie.Navigate("http://www.stackoverflow.com") $ie.Visible =…
LaPhi
  • 5,675
  • 21
  • 56
  • 78
101
votes
3 answers

Is there a Java standard "both null or equal" static method?

To save some typing and clarify my code, is there a standard version of the following method? public static boolean bothNullOrEqual(Object x, Object y) { return ( x == null ? y == null : x.equals(y) ); }
Chris Conway
  • 55,321
  • 43
  • 129
  • 155
100
votes
2 answers

null vs empty string in Oracle

Possible Duplicate: Why does Oracle 9i treat an empty string as NULL? I have a table in Oracle 10g named TEMP_TABLE with only two columns - id and description just for the sake of demonstration. The column id is a sequence generated primary key…
Tiny
  • 27,221
  • 105
  • 339
  • 599
100
votes
5 answers

Should JSON include null values

I'm creating an API that returns results as JSON. Is there a current best practice for whether we should include keys in the result when the value is null? For example: { "title":"Foo Bar", "author":"Joe Blow", "isbn":null } or { …
jjathman
  • 12,536
  • 8
  • 29
  • 33
99
votes
10 answers

SQL Server String Concatenation with Null

I am creating a computed column across fields of which some are potentially null. The problem is that if any of those fields is null, the entire computed column will be null. I understand from the Microsoft documentation that this is expected and…
Alex
  • 75,813
  • 86
  • 255
  • 348
92
votes
3 answers

switch with var/null strange behavior

Given the following code: string someString = null; switch (someString) { case string s: Console.WriteLine("string s"); break; case var o: Console.WriteLine("var o"); break; default: …
budi
  • 6,351
  • 10
  • 55
  • 80
91
votes
10 answers

MySql Query Replace NULL with Empty String in Select

How do you replace a NULL value in the select with an empty string? It doesn't look very professional to output "NULL" values. This is very unusual and based on my syntax I would expect it to work. I'm hoping for an explanation why it…
user1188835
91
votes
10 answers

Null parameter checking in C#

In C#, are there any good reasons (other than a better error message) for adding parameter null checks to every function where null is not a valid value? Obviously, the code that uses s will throw an exception anyway. And such checks make code…
kaalus
  • 4,475
  • 3
  • 29
  • 39
91
votes
11 answers

Check chains of "get" calls for null

Let's say I'd like to perform the following command: house.getFloor(0).getWall(WEST).getDoor().getDoorknob(); To avoid a NullPointerException, I'd have to do the following if: if (house != null && house.getFloor(0) &&…
user321068
91
votes
7 answers

What is the use of adding a null key or value to a HashMap in Java?

HashMap allows one null key and any number of null values. What is the use of it?
subhashis
  • 4,629
  • 8
  • 37
  • 52
90
votes
9 answers

Should the hash code of null always be zero, in .NET

Given that collections like System.Collections.Generic.HashSet<> accept null as a set member, one can ask what the hash code of null should be. It looks like the framework uses 0: // nullable struct type int? i = null; i.GetHashCode(); // gives…
Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
89
votes
1 answer

Updating integer column with null values in postgres

I would like to update my column with other column in other table. Before doing so, I would like to nullify my column(integer) first. However, below code did not work. (column_a: bigint; column_b: text) UPDATE table1 SET column_a IS NULL WHERE…
no_name
  • 1,083
  • 1
  • 8
  • 12