Results 1 to 7 of 7
  1. #1
    jmohandos304 is offline Member
    Join Date
    Apr 2014
    Posts
    90
    Rep Power
    0

    Default Clarification needed

    Referring the original documentation on the topic of operators

    Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

    In the table in the above link it is shown that:
    1. postfix operation is a binary operation
    2. prefix operation is a unary operation.

    I thought postfix and prefix are both unary operation. Pls throw some light.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Clarification needed

    A binary operator would be between its operands, as in 'X+Y'; a postfix operator follows its operand, as in 'X++' ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    jmohandos304 is offline Member
    Join Date
    Apr 2014
    Posts
    90
    Rep Power
    0

    Default Re: Clarification needed

    I know that. Please refer to the first two rows of the table in the link I mentioned. It claims

    1. postfix operation is a binary operation
    2. prefix operation is a unary operation.

    Or is the document wrong?

  4. #4
    jmohandos304 is offline Member
    Join Date
    Apr 2014
    Posts
    90
    Rep Power
    0

    Default Re: Clarification needed

    Also if you refer the second row, +expr is mentioned as unary operator.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Clarification needed

    The table only shows that the operand follows the unary operator (it's a 'prefix operator'); to tell you the truth, I had forgotten that '+' also is a unary opertor (it doesn't do anything).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    jmohandos304 is offline Member
    Join Date
    Apr 2014
    Posts
    90
    Rep Power
    0

    Default Re: Clarification needed

    I had forgotten that '+' also is a unary opertor (it doesn't do anything).

    Ok. But why is the post fix operator mentioned separately? Just to show higher priority in order of preference?

    Also the line in the link:
    All binary operators except for the assignment operators are evaluated from left to right;

    So should postfix operator is right-associative or left-associative? Some examples would help.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Clarification needed

    Quote Originally Posted by jmohandos304 View Post
    I had forgotten that '+' also is a unary opertor (it doesn't do anything).

    Ok. But why is the post fix operator mentioned separately? Just to show higher priority in order of preference?

    Also the line in the link:
    All binary operators except for the assignment operators are evaluated from left to right;

    So should postfix operator is right-associative or left-associative? Some examples would help.
    Associativity doesn't meaan much for unary and postfix operators, i.e. the postfix operators bind more tightly to their operand, as in ~x++ == ~(x++); but also semantic restrictions rear their ugly head, while ++x-- is sysntacticlly perfectly valid, semantically its a nono, because both the ++ and -- operators need an lvalue but their result is an rvalue.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Need a bit of clarification on JNI
    By FlyNn in forum Advanced Java
    Replies: 9
    Last Post: 03-11-2012, 10:38 PM
  2. Need clarification..New to java
    By Anveshan in forum New To Java
    Replies: 3
    Last Post: 09-08-2011, 08:55 AM
  3. Clarification of FileOutputStream
    By rogi85 in forum New To Java
    Replies: 4
    Last Post: 08-03-2011, 12:02 PM
  4. Struts Clarification
    By vinothkumarrvk in forum Web Frameworks
    Replies: 0
    Last Post: 02-26-2010, 02:24 PM
  5. HELP! need clarification
    By ptsofathrty in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 08:02 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
  •