To create a thread in Java you create a Thread object and call its start method. This raises the question, how is the very first thread of an application started? If it’s created calling the start method, which thread calls it?
What is O(0)
If you have ever taken a course in algorithms or data structures you’ll have seen big-O notation. For example you’ll know that a bubble sort runs in O(n²) time and merge sort in O(n log n) time. Maybe you have been explained that with big-O adding and multiplying by constants doesn’t matter, so O(1000n+1000) is the same as O(n). What, then, is O(0)?
Continue reading “What is O(0)”Where Java system properties come from
The reference implementation of Java, OpenJDK, has been open source since a long time now, which means we can look under the covers and see the minute implementation details of anything we find interesting or the API doesn’t fully specify. For example, let’s have a look at how the system properties like file.encoding, os.name and java.io.tmpdir get their values.
Almost always, almost everywhere
There are two precise mathematical terms with names that sound delightfully imprecise: almost always, and almost everywhere.
Continue reading “Almost always, almost everywhere”When 0.3 is not 3/10
If you’ve taken a course in numerical computing you’ll be familiar with the various sources of numerical error. First you have representation error that arises when you have to represent a number with a finite number of digits. A common example: the decimal expansion for 1/3 = 0.3333… has a never-ending string of 3’s and at some point you just have to cut it. The same happens with 1/10 in binary. When you start adding (or subtracting) you may fall victim to loss of significance: when the two numbers have drastically different magnitude you lose least significant digits in the smaller one. You can also have cancellation: when two numbers have almost equal magnitude but opposite signs, you lose the most significant digits and produce a large relative error. You may also suffer from overflow and underflow when magnitude of intermediate or final results gets out of the representable range.
Continue reading “When 0.3 is not 3/10”