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.

14617 questions
4189
votes
65 answers

Avoiding NullPointerException in Java

I use object != null a lot to avoid NullPointerException. What is an alternative to: if (someobject != null) { someobject.doCalc(); }
Goran Martinic
  • 3,757
  • 4
  • 19
  • 14
3233
votes
54 answers

How can I check for an empty/undefined/null string in JavaScript?

I saw this question, but I didn't see a JavaScript specific example. Is there a simple string.Empty available in JavaScript, or is it just a case of checking for ""?
casademora
  • 60,192
  • 15
  • 66
  • 77
2567
votes
43 answers

Is there a standard function to check for null, undefined, or blank variables in JavaScript?

Is there a universal JavaScript function that checks that a variable has a value and ensures that it's not undefined or null? I've got this code, but I'm not sure if it covers all cases: function isEmpty(val){ return (val === undefined || val ==…
Alex
  • 29,612
  • 11
  • 60
  • 134
2320
votes
33 answers

How can I determine if a variable is 'undefined' or 'null'?

How do I determine if variable is undefined or null? My code is as follows: var EmpName = $("div#esd-names div#name").attr('class'); if(EmpName == 'undefined'){ // DO SOMETHING };
But if I do…
sadmicrowave
  • 35,768
  • 34
  • 99
  • 172
1874
votes
28 answers

What is a NullReferenceException, and how do I fix it?

I have some code and when it executes, it throws a NullReferenceException, saying: Object reference not set to an instance of an object. What does this mean, and what can I do to fix this error?
John Saunders
  • 157,405
  • 24
  • 229
  • 388
1440
votes
7 answers

Is null check needed before calling instanceof?

Will null instanceof SomeClass return false or throw a NullPointerException?
Johan Lübcke
  • 17,508
  • 8
  • 35
  • 34
1305
votes
7 answers

Referring to the null object in Python

How do I refer to the null object in Python?
Lizard
  • 39,504
  • 36
  • 102
  • 164
1272
votes
14 answers

Altering a column: null to not null

I have a table that has several nullable integer columns. This is undesirable for several reasons, so I am looking to update all nulls to 0 and then set these columns to NOT NULL. Aside from changing nulls to 0, data must be preserved. I am looking…
Karmic Coder
  • 16,622
  • 5
  • 29
  • 41
1271
votes
35 answers

What is the difference between null and undefined in JavaScript?

I want to know what the difference is between null and undefined in JavaScript.
user605334
1119
votes
22 answers

Which @NotNull Java annotation should I use?

I'm looking to make my code more readable as well as use tooling like IDE code inspection and/or static code analysis (FindBugs and Sonar) to avoid NullPointerExceptions. Many of the tools seem incompatible with each others'…
jaxzin
  • 11,591
  • 4
  • 16
  • 19
889
votes
22 answers

Why is null an object and what's the difference between null and undefined?

Why is null considered an object in JavaScript? Is checking if ( object == null ) Do something the same as if ( !object ) Do something ? And also: What is the difference between null and undefined?
rahul
  • 174,563
  • 47
  • 223
  • 254
671
votes
20 answers

How do I check for null values in JavaScript?

How can I check for null values in JavaScript? I wrote the code below but it didn't work. if (pass == null || cpass == null || email == null || cemail == null || user == null) { alert("fill all columns"); return false; } And…
Mahdi_Nine
  • 11,985
  • 25
  • 78
  • 112
654
votes
22 answers

Why is my Spring @Autowired field null?

Note: This is intended to be a canonical answer for a common problem. I have a Spring @Service class (MileageFeeCalculator) that has an @Autowired field (rateService), but the field is null when I try to use it. The logs show that both the…
chrylis -cautiouslyoptimistic-
  • 67,584
  • 19
  • 106
  • 140
595
votes
8 answers

JavaScript checking for null vs. undefined and difference between == and ===

How do I check a variable if it's null or undefined and what is the difference between the null and undefined? What is the difference between == and === (it's hard to search Google for "===" )?
MUG4N
  • 18,011
  • 10
  • 52
  • 81
558
votes
26 answers

IllegalArgumentException or NullPointerException for a null parameter?

I have a simple setter method for a property and null is not appropriate for this particular property. I have always been torn in this situation: should I throw an IllegalArgumentException, or a NullPointerException? From the javadocs, both seem…
Mike Stone
  • 42,897
  • 27
  • 110
  • 137
1
2 3
99 100