By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,538 Members | 1,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,538 IT Pros & Developers. It's quick & easy.

fastest and better coding

P: n/a
Hello.
As I just started, I wan't to know what's the best (fastest, easiest,
whatever just best) way to deal with instances of objects when creating
them. For example I use JFileChooser more times in application and should I:
1. every time I need a instance of JFileChooser I create a new one....
or....
2. create one instance at the begginig and when I need it just every time
change it's proparties

This is not just for this case but in general sense, what is the best way to
code and what are their advantages / disadvantages? Tnx.

--
Kova

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
reusing objects is always faster instead of creating new ones, but do
whatever looks clearest in your code unless you notice a big performance
hit!

Jul 17 '05 #2

P: n/a
What about storing the results of a method in a variable versus called
the method multiple times.

A simple example that comes to mind:

//two method calls
if(array.size()==5) System.out.println(array.size()) ;

or

//one method call and a variable
int i = array.size() ;
if(i==5) System.out.println(i) ;
Jul 17 '05 #3

P: n/a
why not just go...

if(array.size()==5) System.out.println("5") ;
"Fahd Shariff" <fa*********@yahoo.com> wrote in message
news:9b**************************@posting.google.c om...
What about storing the results of a method in a variable versus called
the method multiple times.

A simple example that comes to mind:

//two method calls
if(array.size()==5) System.out.println(array.size()) ;

or

//one method call and a variable
int i = array.size() ;
if(i==5) System.out.println(i) ;

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.