• 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

Possible optimization

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One can build a button with text in 2 ways:
1) JButton example= new JButton("w/text");
2) JButton example2= new JButton();
example2.setText("w/moretext");
[not like you guys needed to know that ]
I know that in C++ doing it the first way is the preferred, supposedly for optimization purposes. Besides the obvious reduction of 1 function call, is there any extra benefit to setting text or anything else this way in java.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that in any non-trivial application the creation of a JButton, no matter how inefficiently done, would pale in comparison to the overhead of file IO, network communications, database access, custom graphic painting. . . Pretty much everything else a program does. That said, if your application does not display a GUI within a reasonable amount of time, the user may interpret that as a failure and attempt to resolve it. In this case, the Standard Operating Procedure is to display a splash screen and construct the GUI in the background. So to answer your question: Don't Matter.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMO either way is acceptable. The first reduces the number of lines which is sometimes nice for lengthy classes. Essentially the first way does what the second does, but abstracts the setText() away from the code and calls it internally. However you could try testing this with Junit or some other testing framework to see which is more efficient, but i doubt it makes that big of a deal.
Regards,
Dave
 
reply
    Bookmark Topic Watch Topic
  • New Topic