"Try to write unit tests."
There are many other different test frameworks for Android, which uses JUnit in general.
See the importance of unit testing: http://www.csdn.net/article/2012-04-10/2804366
"" It is strongly recommended to use UTF-8 encoding
"" Performance considerations, arrays are preferred
"" Thread-safe Singleton mode
public final class doublecheckedsingleton { private static DoubleCheckedSingletonsingObj = null; private doublecheckedsingleton () { } public static Doublecheckedsingleton getsingleinstance () { if (null == singobj ) { synchronized (Doublecheckedsingleton.class) { if (null = = singobj) &nbsP; singobj = new doublecheckedsingleton (); } } return singObj; } }
Another way: http://www.it165.net/pro/html/201403/11212.html
Package com.troy.young.thread;/*** Thread-Safe Singleton class * * @author Administrator**/public class SingleTon {/*** defines his method of construction, There is no way outside to construct the object with new */private SingleTon () {}/*** defines an inner class to instantiate the Singleton. * First the inner class is static, guaranteeing that the class has only one copy in memory, and that his member variable is final static, again guaranteeing his uniqueness. * At the same time because the JLS will guarantee the thread safety of the class. * @author administrator**/private Static class Singletonholder {Public final static SingleTon instance = new SingleTon ();} /*** provides a way to get an instance of * @return */public static SingleTon getinstance () {//Get the variables of the inner class directly return singletonholder.instance;}}
"" Multithreading using vectors or HashTable
"" using enumerations to implement factory method patterns is more concise
UML diagrams show Fordcar and Buickcar:
DEMO:
public class test { enum carfactory { fordcar { public car create () { return new fordcar (); } }, buickcar { public car create () { return new buickcar (); } }; Public car create1 () { switch (this) { case Fordcar: return new fordcar (); case ... ... default: throw new assertionerror ("Invalid parameter"); } } public abstract car create (); } public void Test () { carfactory.buickcar.create (); carfactory.buickcar.create1 (); } }
Java High-quality code notes