• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class declaration

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Saloon Keeper
Posts: 27883
197
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic