This has nothing to do with performance; in fact, both of your examples will most likely compile to the exact same byte code, so there is no difference between them at all.
Your question seems to be about something different than what you mention from the book. All that the book says, is that the value that is returned must be of the right type - for example, when the method returns an int, then what is returned in the method must be assignable to the type int. It does not matter if the return value comes from a variable (as in your first example) or if it is an integer literal (as in your second example).
Claire Chan wrote:However, it doesn't mean we can't return the value directly. Is it because of performance? or any other reason?
As already pointed out by Jesper, that's not what the book says. The book simply states that the value you want to return from a method must be assignable to the return type. It doesn't matter if it's directly or through a variable.
So given the method signature from your example int integer(), you can return a byte, char, short or int value (because all these can be assign to an int), but not a long, float or double value (because these values can't be assigned to an int). So these code snippets will not compileCan you figure out what's needed to make these code snippets compile successfully? And keep in mind that changing the return type of the method is not an option