Results 1 to 11 of 11
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: what do double parentheses do? ()?

  1. #1
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default what do double parentheses do? ()?

    Hey I'm new and I always see the double parentheses. What do they do? I write:
    Java Code:
     public static void main(String args[]){
    public helloworld(){
    I have two questions here: I understand the first statement here, but not the second. Can you guys explain everything in the second statement? Thanks!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: what do double parentheses do? ()?

    I understand the first statement
    If you can explain the use of () in the first statement, that same explanation should work for the second statement.
    Can you explain what your problem is?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: what do double parentheses do? ()?

    well like I dont understand that lol I dont know what string args[] does... sorry, my bad. Could you explain both?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: what do double parentheses do? ()?

    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: what do double parentheses do? ()?

    I still don't understand Norm?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: what do double parentheses do? ()?

    I can't improve on what is said in the tutorial. After having read the tutorial, what problems are you having?

    ()s are the syntactic way (instructions to the compiler) of delimiting the arguments passed to a method.
    Do you know what a method is?
    Do you know what arguments to a method are?

    Ask google about the above for lots of descriptions about them.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    107
    Rep Power
    0

    Default Re: what do double parentheses do? ()?

    The second call doesn't have a return type so that implies that it is a call to a constructor. Every time that you call a method or a constructor, you will have parentheses. If there are arguments, the argument list will be in the parentheses. If there are no arguments, you will still have the parentheses, with nothing inside of them.

    Edit: Here's a link to a tutorial on constructors.

  8. #8
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: what do double parentheses do? ()?

    First: Both are NO "calls", they are both declarations.
    Second: they are incomplete declarations as they are missing the closing block bracket { ... }
    Third: helloworld is a constructor declaration that does not keep to conventions as it should start with a capital letter!

    Whenever you use a method you need the normal brackets ().This is what defines that this IS a method you are using, even if there are no arguments.
    Whenever you define a block you need the block parentheses {}.
    When you declare a method you need to define its content within a block.

    Correct empty declarations would be
    Java Code:
    public static void main(String args[]) {}
    public helloworld() {}
    Calls would be:
    Java Code:
    ...
    main(myArgs);
    new helloworld(); // EDIT: Added new as it is a constructor call in this context ^^
    ...
    Still having problems?
    Last edited by Sierra; 01-06-2013 at 09:04 AM. Reason: "new" added
    I like likes!

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: what do double parentheses do? ()?

    Quote Originally Posted by Sierra View Post
    Calls would be:
    Java Code:
    ...
    main(myArgs);
    helloworld();
    ...
    Java Code:
    new helloworld();
    db
    Sierra likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: what do double parentheses do? ()?

    Sierra thank you now I understand it a bit better. One more question: There must always be a main method, I know. So why does it say String[] args within the parentheses? Does args stand for arguments? Thanks for the helpful explanation!

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: what do double parentheses do? ()?

    There must always be a main method
    Not true. The only class that needs a main() method is the one that will be used with the java command.
    The java command requires that the class it uses to start execution of a program have a main() method.
    When the java program calls the main() method it passes it a String array whose elements come from the command line:
    java TheClass arg0 arg1 arg2
    The Strings: arg0, arg1 and arg2 would be put into an array and that array passed to the main() method.

    To see this, write a small program that prints out the args that are passed to the main() method and execute the java command in a command prompt window as I showed above.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. representing trees within parentheses
    By Googol in forum New To Java
    Replies: 0
    Last Post: 10-20-2012, 01:12 AM
  2. It keeps trying to get me to close parentheses...
    By MrPosotive in forum New To Java
    Replies: 2
    Last Post: 09-24-2012, 07:54 AM
  3. The increment operator with parentheses
    By 357mag in forum New To Java
    Replies: 2
    Last Post: 07-03-2011, 07:58 PM
  4. matching parentheses stack
    By msa0127a in forum New To Java
    Replies: 9
    Last Post: 10-05-2010, 10:37 PM
  5. Using regex to retrieve all text inside parentheses
    By adhoc334 in forum Advanced Java
    Replies: 5
    Last Post: 08-18-2010, 08:05 PM

Posting Permissions

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