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

How do I test for an empty string in a Bash case statement?

I have a Bash script that performs actions based on the value of a variable. The general syntax of the case statement is: case ${command} in start) do_start ;; stop) do_stop ;; config) do_config ;; *) do_help ;; esac I'd like to…
Singlestone
  • 2,019
  • 3
  • 16
  • 18
109
votes
6 answers

Calling Java varargs method with single null argument?

If I have a vararg Java method foo(Object ...arg) and I call foo(null, null), I have both arg[0] and arg[1] as nulls. But if I call foo(null), arg itself is null. Why is this happening? How should I call foo such that foo.length == 1 && foo[0] ==…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
108
votes
10 answers

MySQL and PHP - insert NULL rather than empty string

I have a MySQL statement that inserts some variables into the database. I recently added 2 fields which are optional ($intLat, $intLng). Right now, if these values are not entered I pass along an empty string as a value. How do I pass an explicit…
user547794
  • 14,263
  • 36
  • 103
  • 152
108
votes
11 answers

How do you construct a std::string with an embedded null?

If I want to construct a std::string with a line like: std::string my_string("a\0b"); Where i want to have three characters in the resulting string (a, null, b), I only get one. What is the proper syntax?
Bill
  • 1,343
  • 4
  • 13
  • 19
107
votes
11 answers

Check if value isset and null

I need to check if value is defined as anything, including null. isset treats null values as undefined and returns false. Take the following as an example: $foo = null; if(isset($foo)) // returns false if(isset($bar)) // returns…
Tatu Ulmanen
  • 123,288
  • 34
  • 187
  • 185
107
votes
9 answers

Check if returned value is not null and if so assign it, in one line, with one method call

Java is littered with statements like: if(cage.getChicken() != null) { dinner = cage.getChicken(); } else { dinner = getFreeRangeChicken(); } Which takes two calls to getChicken() before the returned object can be assigned to dinner. This…
Continuity8
  • 2,403
  • 4
  • 19
  • 34
107
votes
8 answers

Checking for an empty field with MySQL

I've wrote a query to check for users with certain criteria, one being they have an email address. Our site will allow a user to have or not have an email address. $aUsers=$this->readToArray(' SELECT `userID` FROM `users` WHERE `userID` …
user275074
107
votes
6 answers

How should we manage jdk8 stream for null values

I know the subject may be a bit in advance as the JDK8 is not yet released (and not for now anyway..) but I was reading some articles about the Lambda expressions and particularly the part related to the new collection API known as Stream. Here is…
clement
  • 1,491
  • 2
  • 10
  • 11
106
votes
2 answers

Uninitialized Object vs Object Initialized to NULL

I'm working in Java. I commonly setup some objects as such: public class Foo { private SomeObject someName; // do stuff public void someMethod() { if (this.someName != null) { // do some stuff } } } The…
SnakeDoc
  • 13,611
  • 17
  • 65
  • 97
104
votes
12 answers

Rails: Order with nulls last

In my Rails app I've run into an issue a couple times that I'd like to know how other people solve: I have certain records where a value is optional, so some records have a value and some are null for that column. If I order by that column on some…
Andrew
  • 42,517
  • 51
  • 181
  • 281
104
votes
5 answers

How to check if an array is empty in Postgres

I have a Postgres function: CREATE OR REPLACE FUNCTION get_stats( _start_date timestamp with time zone, _stop_date timestamp with time zone, id_clients integer[], OUT date timestamp with time zone, OUT profit, OUT…
joni jones
  • 2,865
  • 3
  • 23
  • 28
103
votes
30 answers

Testing pointers for validity (C/C++)

Is there any way to determine (programatically, of course) if a given pointer is "valid"? Checking for NULL is easy, but what about things like 0x00001234? When trying to dereference this kind of pointer an exception/crash occurs. A cross-platform…
noamtm
  • 12,435
  • 15
  • 71
  • 107
103
votes
19 answers

How to check a string against null in java?

How can I check a string against null in java? I am using stringname.equalsignorecase(null) but it's not working.
user351809
  • 1,257
  • 3
  • 10
  • 7
102
votes
7 answers

Best way to check if a Data Table has a null value in it

what is the best way to check if a Data Table has a null value in it ? Most of the time in our scenario, one column will have all null values. (This datatable is returned by a 3rd party application - we are trying to put a valiadation before our…
Ananth
  • 10,330
  • 24
  • 82
  • 109
102
votes
7 answers

Is there a Ruby, or Ruby-ism for not_nil? opposite of nil? method?

I am not experienced in Ruby, so my code feels "ugly" and not idiomatic: def logged_in? !user.nil? end I'd rather have something like def logged_in? user.not_nil? end But cannot find such a method that opposites nil?
berkes
  • 26,996
  • 27
  • 115
  • 206