Results 1 to 3 of 3
  1. #1
    sonny's Avatar
    sonny is offline Senior Member
    Join Date
    Feb 2010
    Location
    North West England
    Posts
    146
    Rep Power
    0

    Question some basic advice on using methods please

    to put it very simply,
    if i call getWidth(); and wish to use it 3, 4 or 50 times within a block or a class, is it better to call it once and assign it to variable, and then use the variable or call it every-time I need it?

    Similarly , if I have a method to calculate some complex expression, is it better to call it every-time I need it or call it once and assign it to a variable?

    Are there a cases for both?

    Discuss...

    thanks in advance..
    Sonny
    :p I still have my "L" plates on...... directions and explanations are far more help than blaring your Horn! :p Watching:CS106a on YouTube \Reading The Art & Science of Java by Eric S Roberts

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    Assign to variable.

    Why calculating every time if result is time same - waste of time

  3. #3
    sonny's Avatar
    sonny is offline Senior Member
    Join Date
    Feb 2010
    Location
    North West England
    Posts
    146
    Rep Power
    0

    Default

    straight to the point!

    many thanks
    :p I still have my "L" plates on...... directions and explanations are far more help than blaring your Horn! :p Watching:CS106a on YouTube \Reading The Art & Science of Java by Eric S Roberts

Similar Threads

  1. Replies: 8
    Last Post: 04-17-2012, 12:00 AM
  2. Im new n looking for an advice
    By azlynn in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 03:47 AM
  3. Need advice on JSP with bean
    By butterhero in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-18-2009, 12:40 PM
  4. Some advice please!
    By awebbtt in forum New To Java
    Replies: 3
    Last Post: 02-02-2009, 08:23 PM
  5. Advice needed
    By dineshjf in forum Advanced Java
    Replies: 18
    Last Post: 01-09-2009, 04:17 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •