Starting with building the first Java project, building the first class, in the object-oriented tutorial class, from a layman in Java, to the gradual start of using Java to complete some small code, this process can be said to meet the new challenges, while feeling their own joy.
The first time Java gave me the feeling of a shock was to use the methods and constructors from multiple classes and classes at the outset to make the code more concise and effective. The difference between static and non-static methods in the first class practice, and the inheritance of constructor methods, and the considerations in inheriting subclasses, as well as the differences in the inheritance of data types in the parent class,
All give a novelty to the experience, perhaps the object-oriented thought is at this time slowly generated sprout.
Such as:
class a{publicstaticvoid A () {}publicvoid B () {}} Public class B () {publicstaticvoid Main ( String[] args) {a.a (); // Static New A (). b (); // non-static
The construction method in Java, when initializing a class with new, effectively uses the construction method, and if the new object does not define a constructor method, a constructor is added by default;
The shortcut to using a construction method is to initialize the object. Because the construction method is automatically created when creating the object, it is generally not possible to call the constructor explicitly, and when a class is inherited as a parent class, the constructor is not directly inherited and requires super:
Public Class Box () { public Box (double x,double y ,double z) { } } Public extends Box () { public scalebox (double X,doubley ,double z) { Super(A,b,c)}}
Learning programming inevitably encounters the manipulation of strings and string collections, and in Java, it is also possible to split a string and manipulate a collection of strings.
Java can rewrite the ToString method and the split method, but in many cases it is convenient to use Java's own methods of handling these characters.
At the same time, Java Learning also involves the reading and writing of the file and other operations. In the course of learning, the teacher encourages us to check the information on the Internet and all kinds of blogs by ourselves.
Learn a suitable file processing method, and then learn several other methods and compare the similarities and differences between.
String Fileinpath = "file Address"; New File (Fileinpath); New FileReader (Filein);
Java's traversal on several container and iterator iterator is extremely convenient, and the container itself acts as an extensible carrier, more flexible than arrays, without worrying about array overflow, It is also possible to avoid wasted space (although a large array does not occupy much memory) when the array is opened too large at once.
Not only is the container safe to use, but the flexible capacity can avoid the potential danger of array overflow. At the same time, the use of containers is also easy to protect the uniform nature of the data, in a homework, I look at the data found that the container ArrayList object can not only be a string type or an integer type, but also can create a class of their own, For example, in a class, if you save a string and an integer two different types of data, you can use the ArrayList to tie the associated information together is not easy to lose. For example, this tokenstring class appears as a data type for ArrayList:
protected Arraylist<tokenstring> List; protected int wordnum; /* The entire class is directly the object of the container, not just the string */ Public Tokenmanager () { thisnew arraylist<tokenstring>(); This This . List.size (); }
In the final course, we try to make our programs more efficient, think about a more streamlined approach, and think about how to increase the volume of files to be manipulated without having to consume too much memory for too long.
At the same time, learn to read other people's blogs, learn other people's experiences and knowledge, and accept new tools before the endless problems. For example, Java comes with a sort method and comes with an efficient data structure such as HashMap.
Often while using these tools, there are some new problems that need to be solved, such as how to traverse and sort out the hashmap stored data,
In the use of Java also encountered some I problems, such as when using Eclipse, due to the use of computer aging and small memory problems such as the existence of the use of eclips can sometimes be stuck in the extreme, this time to turn off some of the automatic compilation function, Search on the Internet similar to modify Eclipse.ini files and so on, the use of Java also become more fluent, at the same time, to produce some of their own problems can not solve when the experience of the Internet and the students around, often sometimes they can not figure out the problem is a enlightened feel.
There are many things that can be rewritten in Java, such as hashcode comparison methods, such as the CompareTo method, which can be efficiently manipulated with very little code volume.
Such as:
/*Comparator.sort Sort*/Collections.sort ( This. List,Newnamecomparator ()); Iterator<TokenString> Iter = This. List.iterator ();Importjava.util.Comparator; @SuppressWarnings ("Rawtypes") Public classNamecomparatorImplementscomparator{ Public intCompare (Object object1,object object2) {tokenstring word1=(tokenstring) Object1; Tokenstring Word2=(tokenstring) object2; intresult =Word1.word.compareTo (Word2.word); returnresult; }}
By rewriting the rules of CompareTo, you can sort complex data according to different rules.
For example, ArrayList in the five elements, ABCDE each includes the numbers, strings and other information, you can set up a variety of comparator interface according to the different types of information,
This way, when you change the sorting and comparison rules, you only need to replace a comparator, which guarantees very little code changes and ensures the robustness of the code.
The object-oriented concept is tantamount to making many people complete the same project coordination greatly enhanced, in order to better achieve collaboration, in the use of Java in the process of their own class name, method name, variable name use to be extremely careful, to form a good specification, but also facilitate the flow of code and reuse.
Packaged classes and methods do not even need to fully understand the working principle and data structure, as long as the specification of input and output can be used to properly use other people's classes and methods, which also includes the Java built-in HashMap and other data structures. It can be said that the idea of object-oriented programming makes maintenance and usage between code more smooth.
Java Learning experience