Results 1 to 3 of 3
Thread: static constant and performance
- 08-31-2010, 11:22 AM #1
Member
- Join Date
- Dec 2007
- Location
- Mumbai, India
- Posts
- 37
- Rep Power
- 0
static constant and performance
Hi,
We are having a web application. being a web application everyone knows that it is multithreaded. For each and every request n number of string constants will be created. whether is it a right way to put all those string constants in a class and access it in the other classes. For example, I have a class named FieldConstants which will have n number of constant variable(possibly around 5000)
public Class FieldConstants{
public static final String EMP_NAME = "Employe Name";
public static final String EMP_CODE = "Employe Code";
.
.
.
}
public class EmployeeDetails{
public List getEmployee(){
ResultSet rs ;
List employeeList = new ArrayList();
.
.
rs = pstmt.executeQuery();
while(rs.next()){
employeeList.add(FieldNameConstants.EMP_NAME);
}
return employeeList;
}
This is just a sample. Generally using this concept, nothing will be directly hard coded in the code rather it will come from the class FieldConstants class in the entire application.
Whether will it boost the performance if yes then how? There is no doubt that it will be a big problem when we go for debugging the code. One of my collegue suggests this idea. Your valuable suggestions are required.
Regards
Felix
- 08-31-2010, 11:41 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
That is still hard-coding, however. You also know that public static final variable values are compiled directly into the classes using them, right? So a change to one of those variables still means that you have to recompile and redploy your entire application.
Sounds more like something that you should be making a ResourceBundle for so that it can be easily "internationalised".
- 08-31-2010, 01:43 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
It will have no effect on performance.
This:
will take up exactly the same space as this:Java Code:employeeList.add(FieldNameConstants.EMP_NAME);
Actually, it will probably take up a tad more...Java Code:// Class static - provate static final String EMP_NAME = "Employe Name"; ... employeeList.add(EMP_NAME); ...
Constants for display on the front end should be held as some form of resource (see above post). Constants representing columns in a table (if you're using JDBC and not Hibernate or similar) should be held in whatever data access class is most relevant, since that'll be the only place they're needed.
Similar Threads
-
Apache POI Excel: How can we keep the column headers in the diaplay part constant
By sarwan in forum Advanced JavaReplies: 2Last Post: 06-08-2010, 01:21 PM -
non-static method getType cannot be referenced from a static contex
By Dekkon0 in forum New To JavaReplies: 4Last Post: 05-12-2010, 11:05 AM -
Constant size for JTextArea
By itaipee in forum AWT / SwingReplies: 1Last Post: 12-30-2008, 04:12 PM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks