This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

class declaration  RSS feed

 
Maya Pillai
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Which one is correct type declaration in terms of performance




Thanks.

[Nitesh: Added code tags. Please UseCodeTags while posting code]
[ December 18, 2008: Message edited by: Nitesh Kant ]
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frankly, it does not really matter which one you use! You should just use what you think is more readable.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This one:

LoginAction loginAction = null;
loginAction = new LoginAction();
loginAction.checkAccess();

requires you to type another line of code. I reckon that will take a longer than just typing two lines. But you might be a far faster typer than me, so the differernce may be negligable.
[ December 18, 2008: Message edited by: Paul Sturrock ]
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
This one:

requires you to type another line of code. I reckon that will take a longer than just typing two lines. But you might be a far faster typer than me, so the differernce may be negligable.

[ December 18, 2008: Message edited by: Paul Sturrock ]


<In lighter spirit>
I never realized that it may be a question about the coder's performance and not only the program's performance
</In lighter spirit>
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, yes, but what about the program maintainer's performance?

As I mentioned in a recent message, the Java compiler does quite a bit of internal arranging of code, so there should be no effective difference in runtime execution speed unless you have debugging turned on.
 
Chris Blades
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They both essentially do the same thing. The process the JVM goes through when making a new object and assigning a reference to it is:
-allocate space for reference on stack or heap (depending on location); the variable will be null at this point
-initialize object on heap
-initialize reference with object's address

so wether you explicitly do:


or:



the jvm is doing the exact same number of steps in the exact same order, so use whichever you feel is most readable.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!