At the beginning of 2002, Java development project was applied because of the company's business needs and applied Java development projects. Due to the tight project time, there is no abundant time system to learn Java. For Java learning, it can only be used. What to learn, this kind of learning method is fast, but not solid, in the future work, because Java learned Not solid, have a lot of suffering. Now I have learned Java for a year and a half, and I have a certain experience for Java, write my experience, for users to share.
With my personal experience, learn Java should be divided into the following stages:
Java's grammatical learning to establish an object-oriented concept of the Java basic class library learning design mode application design mode After a lot of practice, you can design a mode
The above six phases, where the top three stages are for Java, but in Java, in many design patterns, there are many features support design patterns, so people who don't understand design patterns will not apply Java. Java Do develop. On the basis of study, learning, application, successful experience in the first three phases of learning. Thus, enter the sixth phase, playing in software design. I am limited by the ability, and the learning process in the 4th phase, so it will be explained in the first four stages. The fifth, six stages is just in the inferoration of my own knowledge, there is no experience that I have not explained.
I will talk about my learning method before explaining these learning phases. When learning new knowledge, I usually follow the following three phases.
Theoretical learning. Through the learning of theory, try to understand the concept of new knowledge; after learning, it is just a rough understanding of concept, can't be combined with practical. Deductive stage. According to the knowledge of theoretical learning, consider what this new knowledge can be applied, which places have applied this concept to establish the sensibility of new knowledge. The induction phase. Understand theory from a deeper level.
The following describes my experience according to Java's six learning phases, and every stage will be discussed in three small stages in accordance with theoretical learning, interpretation and summarization.
Java grammar learning
The theoretical learning phase of grammar learning is the easiest stage. It is the Java grammar, and it is possible to read it, mainly to understand the following: (1) Data type, mainly understood: (1) Data type, (2) Operators, (3) control flow, (4) class and classes, (5) packets and interfaces, (6) abnormal operations.
In theoretical learning phase, it is not necessary to pay too much attention to details. As long as there is a holistic understanding of Java's basic syntax, you can read the source code of the example.
The next step is the interpretation phase, the syntax knowledge learned, writing simple procedures. It is best to use your own memory to use the grammatical points (write code is best to use notepad), to re-read the syntax you are not familiar with, and use the compiler to check the syntax error. The goal of this phase is to detach the book and the Java API can write a simple program, and read a Java source code can tell the execution results.
Complete this stage of learning, participate in the SCJP exam, you should get a higher grade.
On the basis of the interpretation stage, according to the mistakes you have made, I summarize the difficulties of Java. Re-reading the grammar, reintegration of some of themselves not very clear, then your understanding of Java grammar is deeper than the first reading.
When I first started learning Java, just roughly see the syntax, I started the program. I met the grammar books, which, I can become a qualified programmer, but when I became Team Leader. In order to train the membership Java programming, they found that they were separated from the Java grammar book and the Java API, there would be no more (Java integrated development tool has a prompt function), for training, I re-learned Java syntax, very harvest . In fact, an excellent programmer must not only write a good program, but more importantly, it can be said to the procedure written: (1) Say the function of the program (2) to clear the structure of the program. And the basis of the structure of the program is to be familiar with the syntax of Java. I want to become an excellent programmer, be sure to practice, constantly, constantly summarize, and finally out of the syntax book, clear the Java grammar system.
Object-oriented concept
Java is an object-oriented development tool that must understand the concept of object-oriented programming when using Java development applications. After learning the Java syntax, the concept of OOP should be established.
Theoretical learning phase, first understand Class and Object, understand Class, Interface, Abstract Class, understand the inheritance of OOP, Public, Protected, Private, and Polymorphism. You should then be familiar with UML, you can read some simple information of UML, basically understand the class diagram, status map, and timing charts. Deductive stage, practice of OOP. The Successful example of OOP should be common 23 design patterns. This stage needs to be read and experience the design mode UML map and sample code. I recommend "Java and Mode" book, or I can access http://www.jdon.com/designpatterns/index.htm. Don't read the mode, just need to read the UML and code of each mode. Internation phase, through the study of the interpretation stage, the benefits of OOP - open open, close to modifications. At the same time, learn how to use the concept design of OOP in Java.
I have been using the Java programming, I have been using the process-oriented ideological programming, and I have not understood the existence of Class, Interface, Abstract Class, and Public, Protect, Private until I read the GOF design mode to understand the advantages of OOP. But the design mode of GOF is too embarrassing. I read it in the first time, just have an object-oriented concept, and I didn't understand the design model. Instead "Java and Mode" is easy to read, but "Java and Mode" has more nonsense, there are many contents that can not be read.
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. After the previous article issued a message, Cheng Meng's netizens pay attention, published a lot of comments, I feel that many people have misunderstandings about me, probably I express unclear reasons. This article is a supplement to the previous, and an example sets to the importance of understanding the Collection framework.
I have written a function Printall (Vector Vector) before half a year, and the specific code is as follows.
Import java.util. *;
public class UtilTool {public static void printAll (Vector vector) {System.out.println ( "the Collection is vector"); System.out.println (vector.getClass () toString ().); Iterator iterator = vector.iterator (); While (item.hasnext ()) {system.out.println (item (). Tostring ());}} public static void main (String [] arg) {Vector Vector = new vector (); Vector.add (New Integer (1)); Vector.Add (New Integer (2)); Vector.Add (New Integer (3)); UtilTool.Printall (Vector);}
}
Printall This function design is very bad - not universal, if you want to print the Hashset type data, you must overload the Printall function, the code is as follows
Public Static Void Printall (Hashset Hashset) {System.Out.println ("The Collection Is Hashset"; System.out.Println (Hashset.getClass (). Tostring ()); Iterator Iterator = HashSet.Iterator (); while (Iterator.HasNext ()) {system.out.println (item.next (). Tostring ());}}
The code reuse of the Printall function is low. In fact, Vector and HashSet are implemented by Collection, which can change the parameter type of Printall to Collection without being overloaded. code show as below
public static void printAll (Collection collection) {System.out.println ( "the Collection is collection"); System.out.println (collection.getClass () toString ().); Iterator iterator = collection.iterator (); while (Iterator.HasNext ()) {system.out.println (item.next (). toString ());}} This can delete the PrintAll (Vector Vector) and PrintAll (Hashset Hashset) functions.
When designing a function, you should use the interface, not a class. Of course, you must understand that vector is the implementation of Collection.
If the inheritance relationship to Collection is unclear, it is easy to abuse overload. The following code is a problematic code (taken from Effective Java Programming Language Guide)
Public class collectclassifier {
Public Static String Classify (Set S) {
Return "SET";
}
Public Static String Classify (List L) {
Return "List";
}
Public Static String Classify (Collection C) {Return "Unknow Collection";
}
Public static void main (string [] args)
Collection [] Tests = New Collection [] {
New hashset (),
New arriselist (),
New hashmap (). VALUES ()
}
For (int i = 0; i System.out.println (Classify (TEST [I])); } } The program output is three "Unknown Collection" instead of printing "set", "list", "Unknown Collection" you expect. The root of this program is unfamiliar with the Collection hierarchy, and overloading is caused. I used Java to develop more than a year, and I should be skilled. When I read "Design Mode" and "Effective Java", I re-learned the Java's basic class library, which has a new understanding of programming ideas. Java's basic class library is designed by experts, understanding basic class libraries, can increase their development efficiency, and on the other hand, they can design ideas for experts. In the basic class library of Java, a lot of design patterns are used, providing extension mechanisms in many ways to facilitate design mode. It can be said that the Java's basic class library will play an ultimate Open-Close PrinciPle (Software Entities Should Be Open for Extension, But Closed for Modification). In the Java's underlying class library, some types of design are to provide tools for Java developers, directly let developers, and some are specifically designed for inheritance. For the first type of class, it is easy to use the integrated development tool, and for the second type of class, it is difficult to learn its use. I will give an example. Java 2 provides support for Proxy mode. In the following example, it demonstrates how to use proxy mode (from "Java and Mode"). Mainly understand the usage of java.lang.reflect.invocationhandler Package com.javapatterns.proxy.reflect; Import java.lang.reflect.invocationHandler; import java.lang.reflect.Proxy; import java.lang.reflect.method; import java.util.vector; import java.util.list; Public Class VectorProxy Implements InvocationHandler {Private Object Proxyobj; / ** @Link Dependency * / / / * # proxy lnkProxy; * / Public VectorProxy (Object Obj) {proxyobj = Obj;} Public Static Object Factory (Object Obj) {Class CLS = Obj.getClass (); return Proxy.newProxyInstance (cls.getClassLoader (), cls.getInterfaces (), new VectorProxy (obj));} public Object invoke (Object proxy, Method method, Object [] args) throws Throwable {System.out.println ( " Before Calling " Method); IF (args! = null) {for (int i = 0; i Object o = method.invoke (proxyobj, args); System.out.println ("After Calling" Method; Return O; Public static void main (string [] args) {list v = null; V = (list) Factory (New Vector (10)); v.add ("new"); v.add ("york");}} The previous series of articles, just my personal experience, there is some tip of the article, I only hope to give some opinions outside the Java door. Learn, apply Java's direction, I recommend watching "talk about Java learning direction? ", This article writes well (see http://www.9cbs.net/develop/read_article.asp?id=21393) And the information I also read it (the difference I didn't read the book of Oreilly, "Java Programming Thoughts" and "The Complete Reference Java 2" two Java classic textbooks, and I also There is no study in specification. If you place yourself in the J2EE direction, the author's recommended information is no doubtful, and it is more comprehensive. But I think there is a little missing: I should learn the design patterns and reconstruction at a certain stage. After all, the design model and refactor are two classics for object development, and Java is a purely object-oriented language, here I only I want to recommend a few books. "Java Programming Thoughts" is a classic Java entry tutorial, and also introduces some ideas for object-oriented programming while introducing languages. This book is the first book I have learned from Java. I have now opened this book now, I can find some content that I have not deeply understood before, it is worthy of taste. "The Complete Reference Java 2" is both a Java's entry book, and Java's reference book. When Coding is now, I still have to refer to this book. "Java and Mode" is a book that introduces the design model to Java developers. When reading this book, let me go to the taste of the project, experience the success and failure of the previous project design, and also promote I re-read "Java Programming Thought" and "The Complete Reference Java 2" two books, after reading 3 times, deepened the understanding of OOP. "Reconstruction - Improve the design of existing code", once there is a project manager that makes me very admire, I will say that I will tell the source code, re-reading, cleaning, summing up this project, and summarizing the programming. One means of the horizontal, and I often clean up some of the garbage code of others and others in the future, I really have a lot of benefits to the improvement of programming levels. And "Reconstruction" books, explained more than 70 methods of cleaning, reconstructing code, in accordance with refactoring methods, can improve code quality, improve programming level, and a means of experience design model . UML After I was written in this series, I suddenly found that I miss the important content of the object-oriented design should be mastered - MLL, although I mentioned UML in the previous article, but the importance of UML for Java should be separate Lext description. UML's importance, I have no way to express it in their own language, thus referring to the "UML Design Core Technology" to express the importance of UML, out of reason and inner reasons. Foreign reasons: UML is a standard of international unified standards. It uses the products that it expressed in line with international standards, and the product can be widely recognized, which will increase the competitiveness of the product in the market; as international standards, international software and commercial sessions are generally supported by UML And thus adopting it will receive the most widely technical support and tool support. Intrinsic reason: UML uses the picture to describe the system's view, graphical easy to understand, facilitating communication between customers, field experts, system analysis, development and designers in different knowledge background, prompting them to understand each other; UML is a standard Representation method, any method or process can be used in UML, it is independent of specific methods and processes, with versatility; UML has good scalability, providing a mechanism such as plus tag value, constraint, version, etc., self-extension, Can be used in different areas, while having versatility, it also has the ability to make your own dedicated, and the UML is integrated with the best software practices. Although there is no way to describe any method or process, it requires the following characteristics: the structure is centered, with an example-driven, support iterative and incremental development, which reflects the successful experience of software development; UML to software design and Analysis of new ideas and new methods that emerged in practice provide good support, it supports concepts such as models, frameworks, and components, providing traceability from "conceptual mode to implement code". The above is a reference, indicating the important role of UML in OOA and OOD, I want to do some instructions in the following: