Tips to make your program better
1. Don't make any class file larger than 1000 lines
2. Avoid Using Global Static function, if not possible then put that all function in a separate class.
3. Before starting the project Check out the proper decomposition of classes, interface and function. Practice of making structure then start coding.
e.g All Nouns is the probable candidate for classes and All Verbs are probable candidate for functions. User Interface wherever possible.
4. Always try to features given by java, don't try to write your own code if java provide such thing like StringBuffer, HashMap, ArrayList etc.
5. Always use the System properties handled by java for example. Don't use "\n" u can use
System.getProperty("line.separator");
6. Always Use Java coding convention(if you don't have company specified) and one popular IDE(eclipse/NETBeans etc) for programming.
7. Properly handle exception and their preferred treatment and if possible create a separate Exception Handling class where After Error message that thrown exception will be caught.
8. Avoid use of public data types for any class.
9. Don't use static function for breaking up the code instead use default functions like
-----
------- public abc(StringBuffer[] arg)
----YOUR CODE
----------(AFTER 50 LINES)
Partition can be done by two ways.
arg=doRemainingOperation(arg);
or
doRemainingOperation();
(by using default scope).
10. Convert all reusable components into class/widgets etc. To make them useful for other projects.
12. Do proper documentation for more information check out COMMENTS ON JAVA
it will help in future updation of code, also use fullname for variable don't use i,j,k,a,b,c etc.
e.g. customerCareServiceNumber, customerCareAddress,customerId,
13. In case of database connectivity, use the same name of variables for storing the value of that field i.e FIELD_NAME should be the variable name which contain value of that FIELD_NAME. It will help you to cover out all the errors by mismatch naming.
14. Always break up complex calculation by declaring new variables, it will be really helpful in removing small problems.
e.g.
x=-b+Math.sqrt((b*b-4*a*c))/(2*a) ...(COMMON MISTAKE)
can be solved by using variable
descriminent= (b*b*-4*a*c)
(-b+Math.sqrt(descriminent))/(2*a)
One more thing Always use brackets extra bracket don't create any problem. e.g. the above one without bracket will be quite complex
x= -b/2.0/a + Math.sqrt(b*b-4*a*c)/2.0/a
which seems quite complex
15. Take proper benefit of the scope variables e.g. if the variable maintain different index in a loop declare it at loop .
16. to help Garbage Collector Always unassign unused variables at Finally. and by marking null
e.g String source;
---source work over----
source=null;
Garbage Collector automatically free the space of source!!
16. properly put comments on the programmer I believe that comments are more important then the program because it helps in future reference and quick Accessing and understanding codes and the complete flow. Always use the tags to check out what can be do to update it, it helps in searching e.g. @TODO or @UPDATE xyz by using Hashmap.. etc..
with information why this updation needed
17 Expert Programmers can found tips on JAVA TIPS AND TRICKS BLOG
18. always try to use functions instead of procedures..
More Tips and tricks on "Threading,Database Connectivity, Session Management, Swings, JFrame,STRUTS,EJB" will be posted soon.
****PAGE IS BEING UPDATED REFRESH AFTER 2 Min****
I request you to please leave the comment for further improvement of the blog.
Free Blog Service Network
Sunday, December 10, 2006
JAVA TIPS AND TRICKS
Posted by Free Blog Service at 5:07 AM
Labels: improving code, Java, Java tips, Java tips and tricks
Subscribe to:
Post Comments (Atom)
1 comment:
KAHE NA KAHE WO MOHABBAT RAHEGI
DIL SE UNKO MILNE KI CHAHAT RAHEGI
WO KYA JANE KITNA MARTE HAIN UNPAR
HAMARI ROOH KO B UNKI ADAT RAHEGI''Y''
hindi sms
Post a Comment