Learning for Java basic class libraries

xiaoxiao2021-03-06  54

Learning for Java Basic Class Banks as a Java programmer must master two packages in 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? Learning phase. 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 10 Update () Called, Count Is 9 Update () Called, Count Is 8 Update () Called, Count Is 6 Update () Called, Count Is 5 Update () Called, Count Is 5 Update () Called, Count Is 5 Update () Called () Called, Count Is 3 Update () Called, Count IS 2 Update () called, count is 1 update () 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.

转载请注明原文地址:https://www.9cbs.com/read-115482.html

New Post(0)