The learning of a Junior and the learning of a junior
Maybe you (Student Party) have almost the same experience as me: after three years of hard work in high school, you have spent countless night-time reading tasks, I finally got admitted to the University (this is not to say that I got admitted to the ideal university. After all, the reality is cruel ). So after entering the university, you will find yourself getting lazy. Why? That's because the university is not as orderly as in high school. Teachers often urge you around and go to college. You will find that most of the time is determined by you, in this way, you will gradually become lazy, and you will not be able to do anything. Of course, this does not include your "repeat three" status during the final exam. However, do you think that in the past few years, you have to provide the necessary skills for your future value realization.
I am a software engineering student and I am studying Java. As a Code Editor (I dare not claim to be a programmer. After all, not everyone who learns programming is a programmer ), the following is my opinion on Java programming. If you are a beginner, let's take a look at this article with a questioning attitude and a review of my views in future practices. If you are a Java programmer (real programmer ), you are welcome to make a brick.
I think that the most important thing to learn about a field is to have a direction, know what it includes, what problems it can solve, and what we should learn.
The following uses Java as an example.
1 public class Hello {2 public void static void main (String [] args) {3 int I = 10; 4 Test t = new Test (); 5 t. setName (new String ("xiao"); // This is to illustrate another knowledge point, so a new object 6 System is created. out. println (t. getName (); 7 8} 9} 10 11 class Test {12 String name; 13 14 public void setName (String name) {15 this. name = name; 16} 17 18 public String getName () {19 return this. name; 20} 21 22}
Okay, let's talk about how to execute this code from the memory structure. First, we need to establish the following memory model in our consciousness. When a program is loaded into the memory, the memory can be divided into four parts, stack, stack, constant pool, and code zone. For the moment, you can understand the new objects in the program. It features a large space and is not as orderly as the stack. Once you create an object, it will find a space in the heap to store your new object. Then you may ask, how does the system call it? This will be explained later. The heap is the place where Java's GC collects objects. Here, GC divides objects into three "generations": the new generation, the old generation, and the permanent generation, there are two main types of GC: minor GC and Full GC. In general, minor GC is very active and acts on the new generation, the "copy" method is used to work in the new generation of eden and two replica vor. The disadvantage is that the "copy" algorithm requires double area (double space ), however, the advantage is that the cleaning speed is fast and there is no memory fragmentation. Full GC acts on the entire heap, including the new generation, the old generation, and the permanent generation. Its Trigger condition may be that the permanent generation space is insufficient, or, when the objects that remain alive after several cleanups in the same vor are advanced to the old generation, the old generation has insufficient space, or because of the System. gc () is displayed for calling and other reasons, it will trigger Full GC. After Full GC occurs, if it is a single-processor system, your running program will be suspended, because GC is working at this time, or your system processor can be concurrent or parallel, but if the heap garbage object Too many, and Full GC uses the "mark-clear" algorithm. The cleanup speed is slow and memory fragments are generated, and the program will be suspended for a certain period of time, this uncontrollable pause is a weakness of the Java language, which is also a bottleneck for projects where Java is applied to a large scale and cannot tolerate long pauses when running programs. Of course, g1 was proposed for large-scale application. It draws on the advantages of incremental collection and is helpful to provide some references for Java GC improvement, I will write an article later to introduce it (I suddenly found that there are a lot of extensions !!! In shame ...). Stack, where the Jvm and the operating system are jointly managed, you can understand the member variables and local variables defined by the program. Here, when we talk about a new object, its memory model is that the system opens up a space in the stack, and then opens a space in the heap to store new objects, then the starting address of the heap space corresponding to this object will be placed in the space you just created in the stack by the system. For a constant pool, you can think of it as storing some constants, such as string constants. The Code zone is undoubtedly the place where your code is stored and is conducive to dynamic loading.
Okay! As shown in the figure, when the program starts running from the main function, it will first allocate space to args. Note that args is a reference object at this time, therefore, -------> execute 3rd statements -----> execute 4th statements ------> execute 5th statements (NOTE: When we create a new String object, because the String is final, the system will first check the constant pool to see if there is any "xiao" String. If not, it will create one in the constant pool so that it will be referenced by other String variables next time, in addition, it will create a "xiao" object and point it to it. here we can explain the reasons in the supplementary example. For example, see the following ") ------> execute six statements (an anonymous variable in the stack) ------> after the program ends, the variables in the stack will be cleared.
Supplementary example:
1 public class TestString {2 3 public static void main (String [] args) {4 5 String s1 = new String ("xiao "); // create an object in the constant pool and create an object 6 String s2 = new String ("xiao") pointing to by yourself "); // This object is available in the constant pool and does not need to be created any more. You only need to create a 7 String s3 = "xiao" object pointing to by yourself "; // with this object in the constant pool, direct to it 8 String s4 = "xiao"; // with this object in the constant pool, direct to it 9 10 System. out. println (s1 = s2); // false 11 System. out. println (s3 = s4); // true 12 13} 14 15}View Code
2. no matter what language, you must practice it. Instead of reading or not practicing it, Do not memorize all the methods. Instead, you must learn to query APIs, methods and attributes of classes and classes that you don't know have them.
3. in case of exceptions or bugs, you must learn to read the exceptions and debug bugs first. Various IDE tools generally have the debug function and cannot solve the problem, for example, google, baidu, and various forums (such as the blog Park and csdn) must learn Unit Tests in addition to comments in normal project exercises, jUnit is quite good. Of course there are many other tools.
4. finally, I will reference my thinking on objects: the object-oriented approach is that when you consider a problem, the first thing you think about is in this project, what objects are there, what properties and methods are there for these objects, and the relationship between these objects (inheritance, combination, aggregation, implementation, etc)