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
83
votes
2 answers

Why null cast a parameter?

When and why would somebody do the following: doSomething( (MyClass) null ); Have you ever done this? Could you please share your experience?
pek
  • 17,847
  • 28
  • 86
  • 99
83
votes
18 answers

What is the point of the class Option[T]?

I am not able to understand the point of Option[T] class in Scala. I mean, I am not able to see any advanages of None over null. For example, consider the code: object Main{ class Person(name: String, var age: int){ def display =…
missingfaktor
  • 90,905
  • 62
  • 285
  • 365
83
votes
6 answers

SQL query, if value is null then return 1

I have a query that is returning the exchange rate value set up in our system. Not every order will have an exchange rate (currate.currentrate) so it is returning null values. Can I get it to return 1 instead of null? Something like an if statement…
jenhil34
  • 1,451
  • 3
  • 17
  • 27
83
votes
13 answers

Can constructor return a null object?

While looking through some old code I came across this gem: MyObject o = new MyObject("parameter"); if (o == null) o = new MyObject("fallback parameter"); The second line is marked in Eclipse as dead code, and I understand why. No exception seems…
Jonathan Pitre
  • 2,355
  • 3
  • 22
  • 38
82
votes
3 answers

Why do I get null instead of empty string when receiving POST request in from Razor View?

I used to receive empty string when there was no value: [HttpPost] public ActionResult Add(string text) { // text is "" when there's no value provided by user } But now I'm passing a model [HttpPost] public ActionResult Add(SomeModel Model) { …
Alex
  • 34,581
  • 26
  • 91
  • 135
82
votes
10 answers

Java constructor style: check parameters aren't null

What are the best practices if you have a class which accepts some parameters but none of them are allowed to be null? The following is obvious but the exception is a little unspecific: public class SomeClass { public SomeClass(Object one,…
user130076
82
votes
8 answers

Delete a file named "NUL" on Windows

I ran a program on Windows 7 that was compiled under Cygwin and passed "NUL" as an output file name. Instead of suppressing output it actually created a file named "NUL" in the current directory. (Apparently it expects "/dev/null", even on Windows.)…
EM0
  • 5,369
  • 7
  • 51
  • 85
82
votes
33 answers

Are nulls in a relational database okay?

There's a school of thought that null values should not be allowed in a relational database. That is, a table's attribute (column) should not allow null values. Coming from a software development background, I really don't understand this. It seems…
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
82
votes
13 answers

Capturing output of find . -print0 into a bash array

Using find . -print0 seems to be the only safe way of obtaining a list of files in bash due to the possibility of filenames containing spaces, newlines, quotation marks etc. However, I'm having a hard time actually making find's output useful within…
Idris
  • 1,887
  • 1
  • 14
  • 9
81
votes
3 answers

Why are NULL pointers defined differently in C and C++?

In C, NULL is defined as (void *)0 whereas in C++ it is 0. Why is it so? In C I can understand that if NULL is not typecast to (void *) then compilers may/may not generate warning. Other than this, is there any reason?
mohit
  • 1,087
  • 1
  • 9
  • 18
81
votes
7 answers

Can I use NULL as substitution for the value of 0?

Am I allowed to use the NULL pointer as replacement for the value of 0? Or is there anything wrong about that doing? Like, for example: int i = NULL; as replacement for: int i = 0; As experiment I compiled the following code: #include…
81
votes
13 answers

Is NULL always false?

Is it safe to assume that NULL always translates to false in C? void *somePtr = NULL; if (!somePtr) { /* This will always be executed? */ } Or should an explicit check against the value of NULL be made?
Sydius
  • 13,567
  • 17
  • 59
  • 76
81
votes
5 answers

Does MySQL index NULL values?

I have a MySQL table where an indexed INT column is going to be 0 for 90% of the rows. If I change those rows to use NULL instead of 0, will they be left out of the index, making the index about 90% smaller?
too much php
  • 88,666
  • 34
  • 128
  • 138
80
votes
6 answers

javax.persistence.NoResultException: No entity found for query

Before I posted this question, I already looked this, but I couldn't get what I was looking for. I know that for the query I wrote there may exist only one row or none at all. So, there is not reason for me to use getResultList(). Here is my…
WowBow
  • 7,137
  • 17
  • 65
  • 103
80
votes
1 answer

Error if don't check if {{object.field}} exists

I have a question about checking if some field in object exists. I want to print all categories which user has so I'm doing something like this:
elzoy
  • 5,237
  • 11
  • 40
  • 65