• Post Reply Bookmark Topic Watch Topic
  • New Topic

Efficiency question about using static final objects

 
Clive Backham
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm new to these forums, and am a fairly unsophisticated JSP user. I have what I think is a simple question...

I have a class whose constructor takes a complicated specification expressed in a string, parses it, and returns a fairly complex structured object. I have need to create such an object for use in a JSP page.

Skeleton of the code:

Now, since the "complicated string" is known at compile time, I believe this should be more efficient:

I've tried both ways of coding it and they both seem to work OK.

My belief is that the (relatively expensive) parsing of "complicated string" and creation of the ComplexObject will happen just once, when the JSP page is compiled (and presumably be stored in the .class file), rather than every time the page is used.

Have I got that right, or am I suffering from wishful thinking?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will act just like any other Java class -- the JSP is translated into a servlet.

However, this way of writing JSPs -- placing java code into scriptlets and declarations -- has been discredited for over 8 years now. You'd be better served to learn modern practices and move all Java code out to beans and controllers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!