choosing to study the object-oriented course in summer is intended to pave the course for the sophomore semester's object-oriented curriculum and to get access to the introductory Java language. In the process of contact with Java , in terms of programming language learning methods, I have just entered the hours of the hands of the confusion around to seek help to now slowly develop their own constantly looking for difficult ways to solve the habit, feel oneself of another self-learning ability-- A computer engineering practice ability has been cultivated, this self-study ability and learning basic curriculum theory knowledge of the feeling is completely different, this need in practice and hands-on experience and knowledge of self-study methods and previously understood the concept of pre-existing abstract theory of self-study can be said to be completely different. As a preference theory study of science girls, hands-on ability is almost zero before, is a complete programming of small white, the University for me is a start, starting from scratch, in the pilot course to further develop a large number of short-term learning to master a large number of skills, I think the harvest is very large place. I sometimes feel difficult, but it will only remind me of the previous learning process, I always silently tell myself, "allthings is difficult before theyis easy", it's okay, all can not destroy my , will make me stronger.
in the first lesson of the pilot class, I learnedJavaof some basic programming ideas. Javais an object-oriented high-level programming language, in the first lesson, I felt the object-oriented thinking, in the later course, theJavathe senior had a deeper impression, one of which was manifested inJavaa rich library of classes and a friendly programming environment. Javaone of the features of object-oriented programming is embodied in the concept of class. This and the data structures that you've been familiar with beforeCthere is a big difference in language. In the previous learning process, useClanguage is mostly process-oriented programming, more focused on how to solve a problem in the process. and usingJavawhen you need to think about abstraction out of a class, thisclasscontains the abstract common attributes and methods, in which the process of abstracting out classes is often more difficult. It made me think of the first programming language of contact.PythonThe concept of class and instance, withJavavery similar. In the subsequent use of the class, it was learned that the previousStatica restricted function method can only be accessed through a direct call to a function, and cannot be invoked by establishing an instance. PublicA function of type can be accessed after instantiation,protectedtypes cannot be accessed directly by the outside world but can be inherited,PrivateIt is a function inside the class, it is safe to be accessed by the outside world. In theJavathe type of variable to use as much as possible during the use ofPrivateto improve security to prevent the values of local variables from being arbitrarily changed. If you want to get or change the value of a private variable, call the relevant Public, which is actually a way of encapsulation. such as:
1 Public classWordCount {2 PrivateString Word; 3 Private intcount;4 5 Public intGetCount () {6 returncount; 7 } 8 9 Public voidSetCount (intcount) { Ten This. Count =count; One } A - PublicString Getword () { - returnWord; the } - - Public voidSetword (String word) { - This. Word =Word; + } -}
And the first time I contacted JavaHas made two impressive mistakes, one is to write a statement in the class except for the variable declaration and function (in fact, these statements should be inside the function body), and the other is that there is no instantiation of the object directly called the method, I think these two errors for the customaryClanguage ofJavaIt is a small place for beginners to pay attention to. In the first class, the teacher took us toBoxclass as an example to learn someJavaBasic grammatical requirements, the important thing is to learn theJavathe constructor and inheritance in the. The construction method is equivalent toCThe initialization of the language, when there is no constructor,JavaThe variable is assigned a specific default initialization value. The constructor does not need to return a value type, the scope type is Public, Thisrepresents the current object (with.a variable or method that takes an object, similar toCthe pointer usage of the language, butJavaThere is no pointer in it), and then use the passed in parameter to the current object(need to instantiate when using)can be assigned. The variable declaration used in the constructor does not require a constructor, because all the content in the class is searched for when compiling to find the variable to copy. One of the most important features is that the name of the constructor is the same as the name of the class. In theNewwhen a class instantiates an object, it is equivalent to invoking the constructor of the class at the same time, which is the initialization assignment. The following is the use of the constructor functionDemo:
1 Public classBox1 {2 PublicBox1 (DoubleWidthDoubleHeightDoubledepth) {3 This. width =width;4 This. Height =height;5 This. depth =depth;6 }7 Private DoubleVol;8 Doublewidth;9 Doubleheight;Ten Doubledepth; One Public DoubleVolume () { Avol = width*height*depth; - returnVol; - } the}
Another important feature is inheritance. Inheritance can be deriving new classes from existing classes, new classes can absorb data properties and behaviors of existing classes, and can extend new capabilities. However, there is no selective inheritance. Subclasses can inherit all members of the parent class that are non-private. The inherited keyword is extends. Here is an example of an inherited use method:
1 Public classScaleboxextendsbox1{2 Private DoubleVolume//pay attention to develop a good habit of writing domain3 PublicScalebox (DoubleWidthDoubleHeightDoubleDepthDoublevolume) {4 Super(width, height, depth);//Call the parent class method with super, must be the first line to prevent the face value from being changed (otherwise the compiler will error)5Volume = 0;6 }7 Public DoubleSetscale (DoubleScale ) {8Volume = height * scale * Width * scale * depth *Scale ;9 returnvolume;Ten } One}
In addition,there are many similarities between Java syntax and C language, but some of the details are different. In Java, A Boolean value is determined to determine whether the if condition is true or false, such as "boolean flag = false; "This declares the variable, and the return value of the function can also be a Boolean value." It is also worth noting that the carriage return in Java consists of a carriage return (\ r) and a newline character (\ n) of two characters.
in the second lecture, we mainly introduced the package andJavaThe concept of an interface. JavaInterface (Interface) is a series of methods of the Declaration, is a collection of methods features, an interface only the method of the characteristics of the method is not implemented, so these methods can be implemented in different places by different classes, and these implementations can have different behaviors or functions. Javathe language does not support a class that has multiple direct parent classes (multiple inheritance), but can be implemented (Implements) multiple interfaces, which indirectly implement multiple inheritance. Javathe member variables in the interface are by default Public,Static,Finaltype (all can be omitted), must be displayed initialization, that is, the member variable in the interface is a constant (uppercase, between the words"_"separated). Javathe methods in the interface are, by default, Public,Abstracttype (all can be omitted), cannot be a static method, no method body, cannot be instantiated,the interface can contain only abstract methodsinstead of directly implementing the function body's content and function. Javathe interface can contain only Public,Static,Finaltype of member variable and Public,Abstractthe member method of the type. There is no constructor method in the interface, it cannot be instantiated, and the interface is abstract. An interface cannot implement another interface, but it can inherit multiple other interfaces, as well as usingextendsmethod is inherited, and the newly defined interface is called a composite interface. Javaan interface must implement its abstract methods through a class, such as "Public class Cylinder implements Geometry". Also, it is important to note that when a class implements aJavainterface, it must implement all the abstract methods in the interface, otherwise the class must be declared abstract. Creating an instance of an interface (instantiation) is not allowed, but it allows you to define a reference variable of the interface type that references an instance of the class that implements the interface .Such as:
Public class b implements a{} A A = new b (); // reference variable A is defined as the A interface type, referencing the B instance A = new A (); // error, interface does not allow instantiation
in the third and fourth classes, the teacher and the TA also led us to learn the debugging function of Java and how to perform performance analysis, further the performance of the program to improve the practice, two classes we use the word frequency statistics as a practice example, while practicing some string processing tips. The splitting of a string (thesplit method) can be useful for formatting processing strings. The use of regular expressions in the segmentation can greatly simplify the processing methods, such as the string "Ab-c,de." F,gab, cde,fgh,cde?f " when you split the string, you can split it with a bitwise or from the front, or you can use a non-alphabetic regular expression to split it, using the following:
String str1[]=s1.split ("[\ \?] +| [\\.] +| [\\-]+| [,| ] +"); // [^a-z]+
In order to improve the performance of the program, I use the variant of the hashing method to the text document Bug java scanner scanner trim method. The specific implementation of the code is as follows:
1 New BufferedReader (new InputStreamReader (system.in)); 2 String s = buffer.readline (); 3 if (S.trim (). IsEmpty ()) {4 System.out.println ("The string is empty!" ); 5 6 Else {... 7 }
after just two weeks of learning, I felt myselfJavawith a preliminary understanding, you can try to use it more in later code writingJavaWrite the program. In the course of learning, the individual is impressed by the inspiring and guided teaching method of Wu's teacher, which makes the authorJavaLearning has generated a strong interest, whether it is in class or under the class, one after another closely linked to the task of the authorJavahave a different feeling. There is also the author of the study process is the big help is the TA in the class and after-school careful answer, there are difficulties and problems can be timely resolved, deepened theJavathe understanding. These are the things I feel lucky to choose as a pilot course. From anxiety and worry to the enjoyment of solving problems, the authorCodinghave a different view. Another significant benefit is that the previous code was written to make every detail of each function pro-and, for example, a sort of function, but now finally realizeJavaThe class library is powerful, so the code written is higher and looks beautiful. As well as the author in gradually exercise their very lack of a ability to find information, Baidu orGoogleWell , the use of existing tools to solve problems, far more effective than their own fight to more efficient, to learn to use resources, known as 工欲善其事 its prerequisite. In the physics learning process in the past like self-study, seldom ask others also seldom seek help, as long as their own thinking can solve the problem will never ask others, now only realize that the use of Internet learning is a very powerful resource. In the course of learning, teachers and teaching assistants can beJavaSome concepts of guidance to help understand unfamiliar content and to complete the code together in class are the areas where I find this course most helpful. Because it was a code test on the first contact class, not similar to theOJon the direct after-class submission to see the test results, will be in the course of testing when the hands are confused and delay the progress of the course, I hope at the beginning of the time can send some test points to adapt to the class test. and make it clearer when you post your homework requirements.
Object-oriented curriculum is very important, not only in the subject of knowledge mastery. From the macroscopic point of view of human society, the object-oriented research method is in accord with the law of human society. The sci-fi film "Advent" introduces the theory of causality and teleology, the original "Your life story" overturned the premise of human unpredictable future, indirectly explained that if we know the future results, mankind will be toward this result to achieve the middle process, no longer exist cause and effect and choice. In the winter vacation, I read "Advent" of an afternoon, suddenly realized that the process-oriented programming is the product of teleology, and object-oriented programming is in line with the current human social causality problem solving method, this choice and uncertainty and the concept of class and object, is used to simulate the best choice of human society, in that moment, I suddenly realized the wonders of computer science, and felt that I knew little, how small. Just like when I was a beginner in physics, I felt that there were many problems to ask, there was restlessness and uneasiness, now think about, the experience of the novice computer was so similar to that of a child, and suddenly felt a wonderful connection. Let's end it with a limerick written by the editor of the Physics book.
"Xinian once saw this lake map, do not believe the world has this lake."
today, from the lake, painters still owe Kung Fu. "
may the future of their own see the present self, can always sigh a sound painters still owes his kung fu.
Java Getting Started experience sharing--a study of the object-oriented pilot course