Chapter     8

Exploring the Basic APIs, Part 2

There are more basic APIs in the java.lang package and also in java.lang.ref, java.lang.reflect, and java.util to consider for your Android apps. For example, you can add timers to your games.

Exploring Random

In Chapter 7, I formally introduced you to the java.lang.Math class’s random() method. If you were to investigate this method’s source code from the perspective of Java 7, you would encounter the following implementation:

private static Random randomNumberGenerator; private static synchronized Random initRNG() {   Random rnd = randomNumberGenerator;   return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;} public static double random() {   Random rnd = randomNumberGenerator; ...

Get Learn Java for Android Development, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.