Hello,
my question is about two possible ways to access data:
(My question is about "real life usage" of java statements like below, accessing the data 2-10 times in a function. Not iterating over such statements with thousands of iterations/calls.)
System.out.println(request.getParameter("locale"));
System.out.println(request.getParameter("locale"));
System.out.println(request.getParameter("locale"));
System.out.println(request.getParameter("locale"));
System.out.println(request.getParameter("locale"));
versus
String localeString = request.getParameter("locale");
System.out.println(localeString);
System.out.println(localeString);
System.out.println(localeString);
System.out.println(localeString);
System.out.println(localeString);
Which example is the "fastest/most efficient" one? (Is the second one faster at all? As there is the variable assignment on top of the five println statements that will also consume CPU cycles...)
Does the Java Compiler optimize the code in example 1 so that it looks like the second example in the Bytecode? (=Doing any optimization by myself in the code is not necessary at all).
Is the navigation of the Object graph (as used in example 1) in terms of CPU cycle more costworthy compared to directly reading a variable (example 2)?
Thank you very much