Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Kagiso

Thread: Parameters...

  1. #1
    hawk-dc is offline Member
    Join Date
    Nov 2013
    Posts
    22
    Rep Power
    0

    Default Parameters...

    Hey guys, I'm new to JAVA and my questions are:
    1) When do I have to use parameters?
    2) Why in some cases I have to create new objects in the very inside of methods?

    Thank you in advance!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Parameters...

    Quote Originally Posted by hawk-dc View Post
    Hey guys, I'm new to JAVA and my questions are:
    1) When do I have to use parameters?
    When the method you are calling needs them.
    2) Why in some cases I have to create new objects in the very inside of methods?
    Please clarify what you mean

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,767
    Rep Power
    5

    Default Re: Parameters...

    Sometimes questions are asked way too early in the learning cycle. These questions do not make much sense to ask because the answer to both is "when you need to". Keep studying, eventually you'll have enough base knowledge that it will click.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    Kagiso is offline Member
    Join Date
    Nov 2012
    Location
    Johannesburg, South Africa
    Posts
    92
    Rep Power
    0

    Default Re: Parameters...

    Quote Originally Posted by hawk-dc View Post
    2) Why in some cases I have to create new objects in the very inside of methods?
    I think you meant something like this

    Java Code:
    public class Java1
    {
    	public static void main(String[] args)
    	{	
    		Java1 j = new Java1(); //I assume you meant, why do we create an instance of Java1 inside this method?
                    //I created it because I wanted to call an instance method doSomething()
    		j.doSomething();
    	}
    	
    	public void doSomething()  // note you can't call a non-static method within a static one such as main()
    	{
    		// do all sorts of things
    	}
    }
    You would do that when you want to call an instance(non-static) method within a static method

    One more reason for creating an instance
    Imagine how painful it would be if we were gonna have to write our own code for creating Buttons, Menubars... etc

    now we can simply have a button by writing something as easy as this:
    Button okButton = new Button("ok"); // and we have a button by creating an istance of a class that was created by someone else
    Excuse my poor English... Inform us if this is what you meant
    Last edited by Kagiso; 11-14-2013 at 10:07 PM.
    hawk-dc likes this.

Similar Threads

  1. Replies: 10
    Last Post: 01-24-2012, 10:02 PM
  2. Replies: 5
    Last Post: 11-21-2010, 02:08 PM
  3. Parameters
    By MIA6 in forum New To Java
    Replies: 2
    Last Post: 12-22-2009, 01:25 PM
  4. How to add two other parameters?
    By albi_87m in forum Advanced Java
    Replies: 3
    Last Post: 05-18-2009, 01:25 PM
  5. get parameters in jsp
    By cecily in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-05-2007, 04:29 AM

Posting Permissions

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