When there are more than one method that can match a method call, the exact rules for determining precedence are a bit nasty. You can read part 220.127.116.11 of the Java Language Specification for the full details.
(Edit: posted before your second message)
But briefly, in the first example there's a rule that can be applied to decide that f(int, Integer) shoud be applied. It's more specific than f(long, Integer) because the first parameter is actually an int. The rules as defined don't give a way of deciding between the two methods in your second example.
This bit from the rules, roughly speaking, says that a method is more specific if all its parameters are at least as specific (and at least one is more specific). It doesn't try to cope with the situation where some are more specific and some less specific.