Hello. This is more a question of curiousity than actually needing a
performance increase.
I was wondering if the Java compiler (I am using Sun's j2sdk 1.4.2_10) will
change Math.PI * 2.0 into a constant in bytecode, or should I make a final
double above my function call?

Signature
LTP
:)
Stefan Ram - 31 Dec 2005 20:41 GMT
>I was wondering if the Java compiler (I am using Sun's j2sdk 1.4.2_10) will
>change Math.PI * 2.0 into a constant in bytecode, or should I make a final
>double above my function call?
You can use
javap -c <classname>
to see the bytecode.
NullBock - 31 Dec 2005 21:22 GMT
Equations solely consisting of compile-time constants are typically
solved before being compiled to byte code. This is also true of
strings, so :
String s = "I want " + ((23 + 7) / 3) + " big macs";
would be stored in byte code as "I want 10 big macs".
Walter Gildersleeve
Freiburg, Germany
______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.
Luc The Perverse - 31 Dec 2005 23:11 GMT
> Equations solely consisting of compile-time constants are typically
> solved before being compiled to byte code. This is also true of
[quoted text clipped - 3 lines]
>
> would be stored in byte code as "I want 10 big macs".
Oh that is even smarter than I thought :)
Alright cool thanks.

Signature
LTP
:)
Thomas Hawtin - 01 Jan 2006 17:20 GMT
> Hello. This is more a question of curiousity than actually needing a
> performance increase.
>
> I was wondering if the Java compiler (I am using Sun's j2sdk 1.4.2_10) will
> change Math.PI * 2.0 into a constant in bytecode, or should I make a final
> double above my function call?
Should the value of PI change, then you will need to recompile your code.
Looking at the bytecode is not a particularly good way of determining
performance. The real optimisations happen at runtime, once your code
has been run 10,000 times. So when performance counts, benchmark your
actual code in a close to real life situation.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/