Tag Archives: Android

Android devices sometimes use wrong DNS server

Android devices sometimes use wrong DNS server. My assumption is, that it happens when device finds friendly WiFi access point, disconnects from mobile provider/ISP and is just finished connecting to it (WiFi using DHCP). It has setup DNS servers from WiFi, however, it still sends requests to DNS from mobile ISP via WiFi network.
It seems that some caching is going on, and it feels wrong… because mobile ISP may be blocking DNS requests from other networks.

Tested on Galaxy Tab 8.9″ with Android 3.2 and Galaxy Note 10.1″ with Android 4.0.4.

String.format in Java has weird rounding by default

I was participating in one of our Android projects, and while testing I discovered, that our program acted weird — app displayed one value, but acted like the value was different. The value was 1.45, and our Java Android app displayed 1.4 instead of 1.5.

The source looked something like:
double d = 1.45;
String val = String.format(Locale.US, "%.1f", d) + "%";

I am still a beginner in Java, and at first I believed, that String.format rounds down by default. This was till I saw, that value 1.55 is rounded up by default.

Digging into Java documentation I found, that String.format uses RoundingMode HALF_EVEN by default:

Rounding mode to round towards the “nearest neighbor” unless both neighbors are equidistant, in which case, round towards the even neighbor. Behaves as for RoundingMode.HALF_UP if the digit to the left of the discarded fraction is odd; behaves as for RoundingMode.HALF_DOWN if it’s even. Note that this is the rounding mode that statistically minimizes cumulative error when applied repeatedly over a sequence of calculations. It is sometimes known as “Banker’s rounding,” and is chiefly used in the USA. This rounding mode is analogous to the rounding policy used for float and double arithmetic in Java.

http://docs.oracle.com/javase/6/docs/api/java/math/RoundingMode.html

Of course other beginners are also discovering this Java Rounding.

Unfortunately Android does not support setRoundingMode, so currently using the following workaround:
double d = (double)Math.round(((double)percents) * 10f) / 10f;
String val = String.format(Locale.US, "%.1f", d) + "%";

2011 links no. 3

Interview With Sacha Barber in The Code Project.

The ABA problem occurs during synchronization, when a location is read twice, has the same value for both reads, and “value is the same” is used to indicate “nothing has changed”. However, another thread can execute between the two reads and change the value, do other work, then change the value back, thus fooling the first thread in to thinking “nothing has changed” even though the second thread did work that violates that assumption.

An Idiot’s Guide to C++ Templates by Ajay Vijayvargiya from The Code Project.

C++0x Finally Becomes a Standard discussed in Slashdot.

What is Cloud Programming and why should we care By GanesanSenthilvel at The Code Project.

Interesting discussion in StackOverflow about Creating a memory leak with Java.

Why is subtracting two times (in 1927) is giving a strange result? or in Shanghai at midnight at the end of 1927, the clocks went back 5 minutes and 52 seconds. From StackOverflow.

$300M To Save 6 Milliseconds in high frequency trading discussed at Slashdot.

Age bias in IT: Some consider it IT’s dirty little secret, or even IT’s big open secret – from computerworld.com by Tam Harbert.

Am I Too Old To Learn New Programming Languages? from Slashdot and Become a Good Programmer in Six Really Hard Steps from ApochPiQ in GameDev.net.

InfoWorld writes about The nine circles of IT hell by Dan Tynan.

Biggest Mistakes in Web Design 1995-2015 from webpagesthatsuck.com.

From glyph recognition to augmented reality with video demos and source code By Andrew Kirillov in The Code Project.

Introduction to Google App Inventor by VinayakIyer from The Code Project.

Guide to Image Composition with Win32 MsImg32.dll By Paul Watt from The Code Project.

JavaScript Jargon (Coming to JavaScript from C#) By Jonathan Cardy.

Learn to code: Codecademy is the easiest way to learn how to code. It’s interactive, fun, and you can do it with your friends.

Minimalist Coding Guidelines By gggustafson.

Penrose Tiling in Obfuscated Python or Who says you can’t write obfuscated Python? from Jeff Preshing.

Learn Perl in about 2 hours 30 minutes By Sam Hughes.

PowerShell is powerful but can it handle gaming? PowerShell Falling Blocks By Lasse W.

Sudoku solver via a webcam: A nice computer vision application with source code from Bojan Banko.

Windows API: Slim Reader/Writer (SRW) Locks from MSDN (available from Vista and Server 2008).

The Five Levels of ISP Evil from Dane Jasper.

spin.js – cool open source JavaScript spinner hosted in GitHub.

Starting up inside the box (Vista and above) from Raymond Chen.

Stuxnet Malware Analysis Paper By AmrThabet. This article will focus on Stuxnet’s windows infection methods and spreading methods.

The Power of Rooting on Android By David Magnotti.

The Principles of Good Programming by Christopher Diggins.

.NET ThreadPool vs. Tasks by Paul Stovell.

Why does creating a shortcut to a file change its last-modified time… sometimes? from Raymond Chen.

Writing a Multiplayer Game (in WPF) By Paulo Zemek. This article will explain some concepts of game development and how to apply and adapt them for multiplayer development.