question about accessors and constants and variable declaration locations

Discussion in 'Java' started by Flip, May 21, 2004.

  1. Flip

    Flip Guest

    I'm having a discussion with someone at work and would like to know if
    there are some links I can use. I remember reading, but unfortunately don't
    know
    any links :< of bean usage and variable declarations.

    When you want to create a hard coded value, there are two ways AFAIK to get
    the value.
    1- create a constant with hard coded value, create an accessor and return
    the constant
    2-create the accessor and return the hard coded value right in the accessor

    Which way do you coders do it and can you suggest any links for references?

    Also, where "should" variables be declared? At the top of method or as you
    use them? Java lets you do both, but what is the preferred way? I know the
    VB way is you HAVE to declare them at the top before any code, but I seem to
    remember reading on some Sun site they suggest declaring vars as you use
    them. Which do you do in real life?


    Thanks.
    Flip, May 21, 2004
    #1
    1. Advertising

  2. "Flip" <[remove]> schreef in bericht
    news:L0qrc.4864$...
    > I'm having a discussion with someone at work and would like to know if
    > there are some links I can use. I remember reading, but unfortunately

    don't
    > know
    > any links :< of bean usage and variable declarations.
    >
    > When you want to create a hard coded value, there are two ways AFAIK to

    get
    > the value.
    > 1- create a constant with hard coded value, create an accessor and return
    > the constant
    > 2-create the accessor and return the hard coded value right in the

    accessor

    3-create a constant, make it public static final and if it's an object, also
    immutable

    1 is better than 2 if you want to use the constant in the declaring class
    (or in the subclasses, or classes in the same package), it avoids the need
    for a method call.

    > Which way do you coders do it and can you suggest any links for

    references?
    >
    > Also, where "should" variables be declared? At the top of method or as

    you
    > use them? Java lets you do both, but what is the preferred way? I know

    the
    > VB way is you HAVE to declare them at the top before any code, but I seem

    to
    > remember reading on some Sun site they suggest declaring vars as you use
    > them. Which do you do in real life?


    I usually declare constants in the top, and variables as I use them.
    Boudewijn Dijkstra, May 21, 2004
    #2
    1. Advertising

  3. Flip

    Flip Guest

    > I usually declare constants in the top, and variables as I use them.
    Thanks for your input! :> Much appreciated.
    Flip, May 25, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benjamin Todd

    constants declaration

    Benjamin Todd, Feb 12, 2004, in forum: VHDL
    Replies:
    2
    Views:
    6,093
    Benjamin Todd
    Feb 15, 2004
  2. Ben Pope
    Replies:
    8
    Views:
    358
    Martin Eisenberg
    Jul 26, 2005
  3. Bolin
    Replies:
    4
    Views:
    401
  4. Austin McDonald

    Virtual instance-variable accessors

    Austin McDonald, Jun 10, 2004, in forum: Ruby
    Replies:
    2
    Views:
    82
    Austin McDonald
    Jun 11, 2004
  5. John Wilger
    Replies:
    3
    Views:
    162
    Dave Thomas
    Nov 13, 2004
Loading...

Share This Page