Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2005

Tip: Looking for answers? Try searching our database.

Question about variable scope static/non-static

Thread view: 
Chris - 16 Apr 2005 16:17 GMT
I am working on my first program and I have a question about variable
scope and good programming practice.

I have an initial class where I have a 4 arrays of data.  From there I
have a couple dialogs and frames that are used to enter or manipulate
or use the arrays.

I only ever expect to instantiate one of the main classes in this
program.

Is it better practice to create static arrays in the main class and
have the dialogs/frames access or manipulate the array?

I initially had it setup so I passed the arrays to each dialog and
retrieved the array data from public textfields from the dialog.

As far as speed, memory management or good programming practice, which
method is ideal?  Thanks
HK - 16 Apr 2005 20:58 GMT
> I only ever expect to instantiate one of the main classes in this
> program.
>
> Is it better practice to create static arrays in the main class and
> have the dialogs/frames access or manipulate the array?

Even after three years of intensive Java programming I
sometimes run into this question: "hey, this class will
in a certain program only ever be instantiated once, so
why not make everything static."

I could not yet come up with a conclusive argument, except
that about half of the time I later realize that the
main class, after a bit of brushing up, could be
used as just a building block in another application.
Then typically some configuration parameters are added,
which go more naturally with a constructor than with
some init method to initialize the static stuff.

In the end I figured that it does not harm but may help
to build proper objects.

 Harald.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.