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
120
votes
3 answers

Why does this string extension method not throw an exception?

I've got a C# string extension method that should return an IEnumerable of all the indexes of a substring within a string. It works perfectly for its intended purpose and the expected results are returned (as proven by one of my tests, although…
ArtOfCode
  • 5,702
  • 5
  • 37
  • 56
120
votes
9 answers

Identifying and removing null characters in UNIX

I have a text file containing unwanted null characters (ASCII NUL, \0). When I try to view it in vi I see ^@ symbols, interleaved in normal text. How can I: Identify which lines in the file contain null characters? I have tried grepping for \0 and…
dogbane
  • 266,786
  • 75
  • 396
  • 414
120
votes
10 answers

json_encode is returning NULL?

For some reason the item "description" returns NULL with the following code:
tarnfeld
  • 25,992
  • 41
  • 111
  • 146
118
votes
5 answers

Check if DataRow exists by column name in c#?

I want to do something like this: private User PopulateUsersList(DataRow row) { Users user = new Users(); user.Id = int.Parse(row["US_ID"].ToString()); if (row["US_OTHERFRIEND"] != null) { …
waqasahmed
  • 3,555
  • 6
  • 32
  • 52
117
votes
7 answers

Removing "NUL" characters

I have got characters like that in my notepad++ When i am trying to copy whole line, i am actually copying everything until "NUL": File:1 What i want to do, is replace those null, to be nothing, so i can copy my whole line. Maybe there is any…
user2618929
  • 1,591
  • 4
  • 13
  • 14
114
votes
16 answers

Java "?." operator for checking null - What is it? (Not Ternary!)

I was reading an InfoWorld article (link to Wayback machine since the excerpt was since removed), and came across this little tidbit: Take the latest version of Java, which tries to make null-pointer checking easier by offering shorthand syntax for…
Erty Seidohl
  • 4,487
  • 3
  • 33
  • 45
114
votes
6 answers

Mark parameters as NOT nullable in C#/.NET?

Is there a simple attribute or data contract that I can assign to a function parameter that prevents null from being passed in C#/.NET? Ideally this would also check at compile time to make sure the literal null isn't being used anywhere for it and…
Neil C. Obremski
  • 18,696
  • 24
  • 83
  • 112
114
votes
11 answers

object==null or null==object?

I heard from somebody that null == object is better than object == null check eg : void m1(Object obj ) { if(null == obj) // Is this better than object == null ? Why ? return ; // Else blah blah } Is there any reasons or this is…
Jijoy
  • 12,386
  • 14
  • 41
  • 48
114
votes
11 answers

Using Thymeleaf when the value is null

I have some values in my database which can be null if they have not already been entered. But when I use Thymeleaf in my html, it gives an error when parsing null values. Is there any way to handle this?
serkan
  • 1,237
  • 2
  • 12
  • 14
114
votes
7 answers

Why is there a difference in checking null against a value in VB.NET and C#?

In VB.NET this happens: Dim x As System.Nullable(Of Decimal) = Nothing Dim y As System.Nullable(Of Decimal) = Nothing y = 5 If x <> y Then Console.WriteLine("true") Else Console.WriteLine("false") '' <-- I got this. Why? End If But in C#…
blindmeis
  • 22,175
  • 7
  • 55
  • 74
113
votes
19 answers

Best way to check for null values in Java?

Before calling a function of an object, I need to check if the object is null, to avoid throwing a NullPointerException. What is the best way to go about this? I've considered these methods. Which one is the best programming practice for Java? //…
JamieGL
  • 1,392
  • 2
  • 9
  • 13
113
votes
11 answers

Why I am getting Cannot pass parameter 2 by reference error when I am using bindParam with a constant value?

I'm using this code and I'm beyond frustration: try { $dbh = new PDO('mysql:dbname=' . DB . ';host=' . HOST, USER, PASS); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND,…
Ignacio
  • 7,947
  • 15
  • 63
  • 74
112
votes
2 answers

Is it still safe to delete nullptr in c++0x?

In c++03 it is pretty clear that deleting a null pointer has no effect. Indeed, it is explicitly stated in §5.3.5/2 that: In either alternative, if the value of the operand of delete is the null pointer the operation has no effect. However, in the…
Mankarse
  • 39,818
  • 11
  • 97
  • 141
112
votes
7 answers

How is null + true a string?

Since true is not a string type, how is null + true a string ? string s = true; //Cannot implicitly convert type 'bool' to 'string' bool b = null + true; //Cannot implicitly convert type 'string' to 'bool' What is the reason behind this?
Javed Akram
  • 15,024
  • 26
  • 81
  • 118
110
votes
13 answers

Nullable types: better way to check for null or zero in c#

I'm working on a project where i find i'm checking for the following in many, many places: if(item.Rate == 0 || item.Rate == null) { } more as a curiousity than anything, what's the best way to check for both cases? I've added a helper method which…
nailitdown
  • 7,868
  • 11
  • 36
  • 37