Recently, I think that I am a middle-level programmer or a senior programmer, has been working for four years, has not had a clear positioning of their own. After all, programmers
The level of work alone should not be the only measure of time.
Stay in a company for a while, no matter how good or bad you are, you can always adapt to the company's business, framework, and work environment. All a lot of programmers, packages
My own. To be able to deliver on time the results of their work, they feel very great, very proud. It technology updates quickly, only by continuous learning, can progress.
Moreover, I found myself working for four years, but I was still at my wits ' end when I met some basic knowledge occasionally. This makes me reflect on the pursuit of new
Technology, new ideas at the same time, is not the occasional stop, solid basic knowledge? What do you think? Please advise us.
Needless to say, the following is a Java basics point: the static keyword. First look at the characteristics of static:
(1) A static variable isalso called a statics variable: a static variable is shared by all objects and has only one copy in memory, which is initialized only when the class is first loaded.
(2) The method or variable modified by the static keyword does not need to be accessed by the object, the class is loaded and can be accessed through the class name.
(3)The Static keyword also serves to form static blocks of code to optimize program performance. A static block can be placed anywhere in the class and can have more than one static block in the class. When the class is first loaded, each static block is executed in the order of the static blocks and is executed only once.
Let's look at an example:
public class Student {private static int sid = 0;private string name;private int age;public Student (String name) {This.nam E = Name;age = sid++;} public static int GetSID () {return SID;} public static void Setsid (int sid) {student.sid = SID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} public int getage () {return age;} public void Setage (int.) {this.age = age;} public static void Main (string[] args) {student.sid = 100; Student S1 = new Student ("lyl"); System.out.println (S1.getage ()); System.out.println (S1.SID);}}
The following is a memory analysis diagram:
Output Result:
100
101
Knowledge Points:
(1) static member variable, which exists in the data seg memory segment, the int basic data type, which occupies only this piece of memory .
(2) Student.sid = 100 is the value of the SID in the data segment modified to 100
(3) When new Studnet ("Lyl") is called, the constructor is invoked, and the string "lyl" is initialized in the data segment. The parameter name of the constructor method executes "lyl" in the data segment
THIS.name is the Name property of student, which assigns the parameter name to the Name property of student. The name attribute equivalent to student also points to the "lyl" of the data segment
(4) Age = sid++; the principle of this operation is: to first assign value, then Gaga . That is, age = 101.
(5) After executing the construction method, the stack space of the parameter name disappears automatically.
Talk about Java Fundamentals by the static keyword