Source: http://www.lcqb.upmc.fr/julianab/teaching/java/TD9_st.pdf