Recently done two Java EE small projects, around the wall to summarize a few experience, share a bit.
(A student, knowledge is limited, if there is a mistake, please correct, if you have a better experience of the great God, ask for advice)
1. Do not omit the necessary notes and be responsible for yourself and others
In team work, the problem may appear more, in the team project development (also includes the individual), the note is must write, must write, must write (important matter said three times), the note includes at least the following three comments:
Method Description, @auther, @param. Examples are as follows:
1 /**2 * This is a method to do addition, pass in two parameters, return two number of the sum3 * @parama addend4 * @paramb summand5 * @returnTwo sum of the numbers6 * @authorWreckbear7 */8 Public intAddintAintb) {9 returnA +b;Ten}
2. To maintain a non-trust of the external parameters of the heart
In the JAVA EE World, the famous MVC brings countless benefits to programmers, and the interface between layers becomes a problem-prone place.
For example: Just start to do the project like a savage, do not understand anything, only know I write this method when I know that it will not be null, directly call the object's method or property, this gives NullPointerException left a chance to take advantage of your carelessness, will take your life on a stormy sunny day.
Therefore, as a developer of a method, it is very necessary to keep the parameters passed in to be untrusted, reasonable verification of them, if not normal, you need to take appropriate means to avoid the error to occur.
3. Be good at using anomalies to make projects stronger
Just beginning to learn Java, unusual contact is not much, just around the area, and recently did the project only found that the abnormal program robustness of a powerful weapon, it is not difficult to find that the JDK excellent source in a large number of abnormal figure.
For example, a way to do division. Public floatDivfloatAfloatb) { floatresult = A/b; returnresult;} If this is written in the project, it will probably be an unforgettable memory! If I call a method div (10,0You know what's going to happen, and now you can a fall into your wit and do it. Public floatDivfloatAfloatb) { floatresult = 0; if(b!=0) result= A/b; returnresult;} It's a lot smarter than last time, at least not what you don't want to see happen, but there is still a problem, I passed a as a caller=10,b=0, I thought I passed two valid arguments, and also believe that your method returned the correct result, this time my mistake will not be wrong again, this is because your method did not tell me: "Your parameter is wrong!" "How can you tell me?" --Unusual! Public floatDivfloatAfloatbthrowsmyexception{if(b!=0) Throw NewMyException ("divisor is 0, cannot be calculated"); floatresult= A/C; returnresult;} Such It's better.
4. Good use of tasks (Eclipse) tools
As an open source IDE, Eclipse is widely acclaimed as a user, especially a novice user, and it's great to discover a variety of tools, such as the Tasks tool.
Development often encounter this situation, this place is not going to go down now, I have to remember, in case later forget, this time to put away your Notepad, with Eclipse's tasks. Here's how to use it:
In the place where you want to be reminded--"//TODO here Tomorrow" and then open the Tasks (markers) Panel, you can see the markup you've made. Such as:
More ...
So much for the time being, I will add it later ...
Project Learning Experience