Original Post
Im pretty new to Java programming and Im trying to think up of more efficient programming techniques. What Id like to know is what is actually going on behind something such as this:
int total, numb1;
numb1 = 3*3;
total = numb1 * 2;
total = numb1 * 4;
as opposed to this:
int total;
total = 3*3*2;
total = 3*3*4;
What Im assuming is that in the first example, 9 is calculated once and stored in main memory for repeated use. In the second example, 9 is calculated multiple times. So that the first example will use up more RAM and the second will use up more processor power.
Am I correct in those assumptions? If I am not can someone explain to me what is actually going on and which would be better to use for efficiency?
Thanks to all who reply =)