JVM Optimization
The comments and answers are correct, no need to worry about such efficiencies because the JVM compilers and runtimes are so amazingly good at optimizing. Keeping your code simple gives the most opportunities for such optimizations. In other words, write dumb code for the smart JVM.
Creating intermediate variables with wisely chosen names is generally encouraged:
- Makes your code more self-documenting.
- The modern JVMs are adept at efficiently handling and disposing of any such short-lived objects. And the compiler may have optimized away the extra variable anyways and inlined the value.
- Most importantly, debugging is so much easier. When tracing thorough code you can see each incremental change/operation as it occurs. The named variables make for a catalog of values for you to review in the debugger tool.
Readable Code
So focus on readability, making your code easy for humans to understand. To that end, I would:
- Change the order of your statements. Generally better to prepare your data before using it, so don't begin instantiating the
Date object until your milliseconds have been calculated.
- Take advantage of a
java.util.Date constructor to remove a line of code.
- Change the variable names to be self-documenting.
- Insert underscore in numeric literal to make number more readable.
- Append an uppercase
L to numeric literal. While appending may not be technically necessary in this particular case as the compiler can upsize the int to a long, the L reinforces to the reader that we are working to create a long instead of the more usual int.
Example code
long millisecondsSinceEpoch = ( secondsSinceEpoch * 1_000L ) ;
Date date = new Date( millisecondsSinceEpoch ) ;
java.time
Even better is to entirely avoid the old java.util.Date/.Calendar classes as they are notoriously troublesome. In Java 8 and later those classes have been supplanted by the new java.time package.
Instant instant = Instant.ofEpochSecond( secondsSinceEpoch ) ;
timestampis used somewhere else in the method. On the other hand, option 2 makes it easier to debug since I can look at or print the variable. So I vote "whatever".timestampis used it's a different issue--code's too long. Intermediate variables are a common technique, but in this case, it's not overly helpful. Of course, neither is a variable namedarg1:(