There’s a simple Java program FloatCalc.java:

public class FloatCalc {

    public static void main(String[] args) {
        System.out.println(1 - 0.56);


What will be the output of this program?

Bonus question: Does the computation occur in run-time or compile-time?

Good Answer: Does Windows carriage return \r\n consist of two characters or one character?

Recently I’ve earned silver badge:  Good Answer

This badge is awarded answers which have score of 25 or more. And my answer to question Does Windows carriage return \r\n consist of two characters or one character? has reached 25 upvotes.

Here’s my answer:

These are two characters:

  • \r is carriage return;
  • \n is line feed.

Two characters combined represent a new line on Windows. Whereas on Linux, \n represents new line. It moves cursor to the start of new line on Linux. On Windows, the cursor will stay at the same column in the console but on the next line.

\r on Linux has the same effect as on Windows: moves cursor to the start of the line. It is possible to print different information on the same line where \r is used instead of \n.

Copyright check

A simple script to check whether the year in Copyright header is updated:

hg st -q -n | xargs grep Copyright | grep -v 2014

Nothing fancy! Just to save it.

It would be awesome if such a script updated the year automatically.

Heartbleed Explanation

Heartbleed Explanation

Advanced “status” options

Two weeks ago I showed how to filter output of hg status with awk. That simple awk script removes unknown (untracked) files from output and also removes the file status: you get a simple list of modified/added files.

Actually, you can do this without using awk because Mercurial has advanced options for status command:

hg status --quiet --no-status

Or with short aliases:

hg st -q -n

The result is the same: you get the plain list of modified files, and files which are not under source control are ignored.

Java 8 Launch Event

Java logoLast week Oracle launched Java 8, a new release of Java platform which includes many new features, Lambdas and Streams to name a few. See Java 8 Central for more information, or go to Java 8 download page to download it and test-drive its new features.

Today, on March 25, 2014, there will be an online Java 8 launch event. The event starts at 10:00 AM PST, or 21:00 MSK.

Print modified/added files

When working with source control systems, sometimes you need to get a list of modified/added files ignoring generated files which are not under source control. You can use this simple awk script:

awk '{ if ($1 != "?") print $2; }'

With Mercurial, the full command looks this way:

hg status | awk '{ if ($1 != "?") print $2; }'

Replace hg with svn if you use Subversion.

Of course, you can redirect the output of the commands to a file.