Java basic class library learning
I have interviewed some Java programmers, and I'm going to use which classes are often used in using Java, in which package. Few people can answer, and even some people have done a 2-year Java program without answering, they will use Java, but must rely on tools (refer to Java integration tool), I think they can write out programs, but can not write special So worker.
I think as a Java programmer must master the two packages of the Java class library: java.lang and java.util these two packages. The Java.LANG package is provided by the basic class package for Java programming. Java programmers are using it every day. It is nothing more than how others use it, but there are very few people to summarize, such as string and stringbuffer. What is the difference in class, there should be many Java programmers can't say it. In addition, the two classes of Vector and Hashmap are in use, how many people can make it clear which classes have inherited, which interfaces have been implemented?
Theoretical learning. Seriously read Java API: String, Stringbuff, Number, Double, Flong, Class, ClassLoad, CLONEABLE, CLASTEM, OBJECT, RUNEABLE, CLASSLOADER, Thread, ThreadGroup, Runnable, Package or Interface. java.util package Collection, list, Set, ArrayList, LinkedList, Hashset, TreeSet, Iterator, Map, SortedMap, HashMap, TreeMap, Comparator, Arrays, Enumeration, Vector, Stack, Dictionary, Hashtable, Properties, StringTokenizer, BitSet, Date, Calendar, Locale, Random, Observer, Observable class, and interface. The main reason for the inheritance relationship between these or interfaces, the main function. Deductive stage. These classes and interfaces are learned and applied by reading code, practice programming, learning and applying. In fact, most of these classes are often used, nothing more than these classes and interfaces are unclear. In these classes, the classes in java.lang and java.util are best exercised using each method. In the Java.util package, the class in the Collections Framework in the java.util package is best to clear the relationship between the various classes and interfaces. I don't specifically introduce the method of common class, I will take an example using Observer and Obserable (taken from "The Complete Reference Java 2). In Observer and Obserable, Java implements support for design mode OBServer.
Watcher.java code import java.util. *; Class Watcher Implements Observer {public void update (Observable Obj, Object Arg) {System.out.Println ("Update () Called, Count Is" (Integer). intValue ());}} BeingWatched.java codes import java.util *;. class BeingWatched extends Observable {void counter (int period) {for (; period> = 0; period--) {setChanged (); notifyObservers (new Integer (period)); try {Thread.sleep (100);} catch (InterruptedException e) {System.out.println ( "Sleep interrupeted");}}}}; ObserverDemo.java the code public class ObserverDemo {public static void Main (String [] args) {beingwatch observed = new beingwatch (); watcher observing = new watcher (); observed.addobserver (observed.counter (10);}}; execution result Update () Called, Count Is 10UPDATE () CALLED, Count Is 8update () Called, Count Is 6Update () Called, Count Is 6Update () Called, Count Is 5Update () Called, Count Is 4Update () Called Count IS 3UPDATE () Called, Count is 2Update () Called, Count is 1Update () Called, Count IS 0 induction phase. Summarize the use of experience, experience the inheritance relationship between these two packages, support for design patterns (such as the Iterator itself is design mode, and is also the application of factory method model), understand all functions provided by these classes, compare funatic Different. Remember these classes in the heart. While integrated development environment support method prompts, I personally think that the API of the two packages for java.lang and java.util should be familiar with the heart, and the Java's other class libraries can find the API. Of course, if you are engaged in different development, you should have a corresponding understanding of other class libraries. If you develop Swing, you should have a Javax.Swing package, you have to understand Javax.Servlet, according to your personal Application is developed.
(Fail)