Rules about String Buffers and Builders. It is
preferable to ensure the capacity of string buffers or
string builders either while initializing such objects
with the corresponding parameter or by calling the ap-
propriate method. Absolute and relative gains are so
close enough to corroborate the fact that such struc-
ture constructors ensure the capacity of strings. How-
ever, it is not recommended to set the length of string
buffers or string builders as it just modify an inter-
nal field of such structures without allocating mem-
ory space. Effectively, the ensureCapacity method is
used to allocate memory space of strings whereas the
setLiength method is for shorten the size of already
allocated strings.
Rules About Primitive Types and Wrappers. If it
is possible, it is preferable to manage primitive types
than wrappers. However, this rule should be com-
pleted with other ones. In fact, once codes deal with
collections, Java virtual machines automatically casts
primitives types into wrappers as collections require
wrappers. This is called auto-boxing and it also con-
sumes energy; furthermore much more energy than
directly using wrappers in collections.
7 CONCLUSION
This document investigates how to qualify energetic
relevance of Java best coding practices. This has been
achieved, firstly, using a formalism of best coding
practices which semantics consists in the comparison
between a model code of this best practice (the green
code) and another as the opposite of the model code.
Secondly, this has also been achieved using an orig-
inal and robust hybrid sensor system for estimating
time, memory and energy required by a code imple-
mentation. This has lead us to these silent conclu-
sions: there is no need to carry out numerous mea-
surement operations for to obtain a consistent mea-
sure set.
This work leads us to improve, firstly, our mea-
surement platform and, secondly, our measurement
protocol, these two perspectives with the aim to de-
velop an energy model programs. Our current plat-
form is the result of a bottom-up approach which
aims at producing measures by the means of a pre-
determined set of sensors. We plan to develop a new
platform from a top-down approach and focused on
analysis along these axis: the hardware architecture,
the operating system, the programming language , the
runtime environment, the type of measure, the type of
sensor and obviously the analyzed code. Such a plat-
form would make possible to elaborate energy mod-
els of programs in different programming languages,
in different runtime environneents. For example, the
energy model a FOR loop should depend on the num-
ber of iterated items, the type of these items and the
complexity of the loop body. Such a goal requires de-
signing much more sophisticated measure protocols
than simple comparisons as it is currently the case.
ACKNOWLEDGEMENTS
This work is partially funded by the Pays-de-la-Loire
Regional Council through the research project Code
Vert (http://www.code-vert.org) 2012-2014.
REFERENCES
Bloch, J. (2008). Effective Java. The Java series. Pearson
Education.
Boudon, A. (2013). Power API: Library API
to monitor energy spent at the process-level.
http://abourdon.github.io/powerapi-akka.
Douglas, D. H. and Peucker, T. K. (1973). Algorithms for
the reduction of the number of points required to rep-
resent a digitized line or its caricature. 10(2):112–122.
Fleiss, J. L. (1981). Statistical Methods for Rates and Pro-
portions. Wiley, John and Sons, Incorporated, New
York, N.Y.
Garrett, M. (2007). Powering down. ACM Queue, 5(7):16–
21.
Koskela, L. (2013). Effective Unit Testing: A Guide for Java
Developers. Running Series. Manning Publications
Company.
Lafond, S. and Lilius, J. (2006). An energy consumption
model for an embedded java virtual machine. In Ar-
chitecture of Computing Systems - ARCS 2006, 19th
International Conference, Frankfurt/Main, Germany,
March 13-16, 2006, Proceedings, volume 3894 of
Lecture Notes in Computer Science, pages 311–325.
Springer.
Noureddine, A., Bourdon, A., Rouvoy, R., and Seinturier,
L. (2012a). A preliminary study of the impact of soft-
ware engineering on greenit. In Green and Sustain-
able Software (GREENS), 2012 First International
Workshop on, pages 21–27. IEEE.
Noureddine, A., Bourdon, A., Rouvoy, R., and Seinturier,
L. (2012b). Runtime monitoring of software energy
hotspots. In Automated Software Engineering (ASE),
2012 Proceedings of the 27th IEEE/ACM Interna-
tional Conference on, pages 160–169. IEEE.
Poess, M. and Nambiar, R. O. (2008). Energy cost, the key
challenge of today’s data centers: a power consump-
tion analysis of tpc-c results. Proceedings of the Very
Large Ddata Bases endowment, 1(2):1229–1240.
Saxe, E. (2010). Power-efficient software. ACM Queue,
8(1):10.
HowGreenAreJavaBestCodingPractices?
245