Why we use increment or decrement operator

Hi. I want to know that is there any advantage of using the increment or the decrement operator. Does it makes the code a bit faster to run, etc.
Actually i find these operators to be a bit confusing. so want to ask why should we use them and when.
Thanks.

baftos wrote:
I am not kidding. It's a personal opinion that may be wrong.
I'll tell you why I think what I think and I would be glad to change my opinion if someone shows me the light.
Those operators are just syntactic sugar.So is a bunch of other stuff in Java (imports and the foreach loop, for example). Syntactic sugar is a good thing when it makes common idioms more compact, or stand out as what they are, as opposed to just another instance of a more general case. (Although I don't really consider these syntactic sugar.)
Everything they do can be done otherwise more clearly.I disagree. "Increment" is an all-pervasive operation in programming. Sure, it can be done as just another case of x = x + something, where in this case something happens to be one, but in my opinion, that's not as descriptive. x++ is compact, concise, easy to read, and stands out clearly as "increment x".
Without them the language would be just simpler.
No more riddles about i=i++, Any language feature can be abused or misunderstood. That in itself is not a valid argument against including it. This misunderstanding is very easy to correct. It's on the same scale with redeclaring a member as a local and then wondering why you're getting NPE when trying to use the member elsewhere. It's not even in the same league as things like operator overloading or MI of implementation.
why n=i+1 requires cast, but not n=++i, the relation between boxing and the ternary etc.Again, these are little quirks, corner cases that cause some minor confusion but not major problems. To me this kind of stuff is no different than stuff like using compile-time constants for case conditions or to assign a wider integer type to a narrow one without a cast. It's stuff that makes the language easier to read and write for a lot of common use cases, at the cost of some minor complexity in the corners.
They were retained from C, while other things were discardedWhich is neither an argument for nor against them.
Edited by: jverd on Oct 31, 2009 9:37 AM

Similar Messages

  • Is Increment and Decrement Operators Atomic?

    Is there a need to synchronize increment and decrement operations, or they are atomic? If so, how about pre and post variations?

    raychen wrote:
    jverd wrote:
    Simple rule: If multiple threads are accessing a variable, all access to that variable must be synchronized. There are exceptions, but you'll seldom go wrong by following that rule.I don't synchronize data member accesses in simple setters and getters, as JVM guarantees my read and write are atomic at the memory level. Am I making bad assumptions?Yup, you are. For a couple of reasons.
    1. Reading and writing of non-volatile longs and doubles is not guaranteed atomic.
    2. It also does NOT guarantee that one thread will ever even see a value written by another thread, however, unless either a) the variable is volatile, in which case threads don't have local copies all reads and writes go against the main copy, or b) access is synchronized and therefore the writing thread's local copy is flushed to main memory upon exiting exiting the sync block and the reading thread gets its first read after entering the sync block from the main copy.
    Edited by: jverd on Jul 21, 2009 10:33 AM

  • Why not use "new" operator  with strings

    why we not use new when declaring a String .because in java String are treated as objects. we use new operator for creating an object in java .
    and same problem wiht array when we declare array as well as initialize .here we are alse not using new for array
    why

    Strings aren't just treated as objects, Strings are Objects.
    As for why not using new for Strings, you can, if you want.:
    String str = "this is a string";
    and
    String str = new String("this is a string");
    do the same thing (nitty-gritty low level details about literals aside). Use whatever you like, but isn't it simpler not to type new String(...) since you still need to type the actual string?
    As for arrays, you can use new:
    int[] ints = new int[10];
    or
    int[] ints = { 0, 1, 2, 3, ..., 9 };
    But the difference here is you are creating an empty array in the first one, the second creates and fills the array with the specified values. But which to you often depends on what you are doing.

  • Why we are using FILLPV and GENTPB operations?

    Hi Experts,
    Please Explain Why we are using "FILLPV0" ,"FILLPV1","FILLPVT","FILLPV6'.
    and 'GENTPB 0", "GENTPB * ", "GENTPB 01R", "GENTPE B".
    I have a scenorio,
    hrs?16
    -<
    hrs=dxxxx
    hrs-16
    adddbyyyyz
    GENTPE L
    COLOP*
    -=
    FILLPVL
    COLOP*
    ->
    FILLPVL
    colop*
    I confusing about what is "L"
    and where it stored?.
    why the need we fill procesing type L when =,> ?
    by using that Fillpv what is the further process.?
    where XXXX is a time type which have 17.
    YYYY is also timetype which stores 1.
    so my question is when we add that 1 to timetype yyyy what is the need to call "GENTPB L"
    and what process will done when we cal that "gentpb l"
    and when xxxx = 16
    we are filling "FILLPV L"
    L is assigned with some wagetype 4xxx.
    what process is done when when we use this "FILLPV L' operation.
    Thanks in Advance,
    Mahesh.

    Hi Harish,
    Thanks for your reply,
    so
    When we use FILLPVM operation any specific wage type related to overtime  will be populated from table "t510s" ?
    according to your help i assume this rule
    hrs=s
    _hrs?8
    ---<
    ---hrs=s
    ---adddbxxxx
    ---=
    hrs=s
    adddbxxxx
       |--->
            |---hrs=s
            |---adddbxxxx
            |---hrs-8
            |---gentpe   m
            |---adddbyyyy
            |---fillpvm
        here that 2 hours will split into overtime and stored into yyyy timetype.?
    and  that fillpvm will cal the specific wagetype related to overtime?
    please let me know if i am wrong. 
    Thankyou,
    Mahesh.

  • Increment and decrement buttons on a ring control are greyed out

    Hello,
      The check box for showing the increment and decrement buttons on a ring control are greyed out. Does anyone know why? I have verified that the ring is a control as opposed to a indicator.
    Regards,
    Kaspar
    Regards,
    Kaspar

    "the controls are greyed out because they do not exist on the Menu ring control."
    Errr... yes, I believe that's exactly what I said in my last response.
    "This is different from what I saw in another part of this forum about using event structures on a Menu ring."
    Don't know what you could be referring to, as there is no event specific to the increment/decrement controls. All that they would do (if they existed) is to change the value of the control, and the applicable event would be the "Value changed" event. Where exactly did you read this?

  • Decrement operator precedence confusion

    Here is the snippet from a book:
    int y = 5;
    int result = y-- * 3 / --y;
    System.out.println("y = " + y);
    System.out.println("result = " + result);Assuming increment and decrement have highest precedence, I don't get the explanation:
    Order of operations dictates that the multiplication is evaluated first(WHY???). The valueof y is 5, so 5 * 3 is 15. The multiplication is done, so the post - decrement occurs and y
    becomes 4. Now the division is evaluated and y is pre - decremented to 3 before the division,
    resulting in 15 / 3 , which is 5. The output of this code is:
    y = 3
    result = 5
    Any comments would be appreciated.

    AntShay wrote:
    Oh, no!
    There's something more I don't get :)
    Why is 5 *** 3 takes place instead of 4 *** 3? Pre-decrement has higher precedence, hasn't it?
    So, from my point of view this should work as follow (please correct me where I'm wrong):
    int y = 5;
    int result = y-- *** 3 / --y;
    1) y-- gets evaluated (y=4 now)
    2) --y gets evaluated (y=3)
    3) 3 *** 3 = 9
    4) 9/3 = 3I don't know if pre-dec has higher precedence than mult, but even if it does, that doesn't matter. That's not what precedence means. It doesn't mean you jump around and do those operations first. I just means "This is where the implied parentheses go." The only affect it has on order of evaluation is when you have to evaluate something inside the implied parens first to get an operand for the next operation.
    3 + 4 * 5In the above, mult has higher precedence than add, so it's equivalent to
    3 + (4 * 5)It doesn't mean "first do all multiplications, then all adds." It means the implied parens are as above.
    So:
    1. evaluate 3
    2. evaluate the RH operand of +++
    2.1 evaluate 4
    2.2 valuate 5
    2.3 multiply 4 *** 5 --> 20
    3. evaluate 3 +++ 20
    So we did the mult before the add because we had to in order to get the value of the RHS operand of the plus. Indirectly it's because mult has higher precedence, but that's just a consequence of the implied parens, and we still evaluated the 3 before doing the mult. We did NOT do "all mults first, then all adds."
    Similarly, if it had been
    2 + 3 + 4 * 5we would eval 2, then eval 3, then add, then eval the RHS of the second plus operator, which means we'd have to eval 4 *** 5. Note that we do NOT eval 4 *** 5 as the very first step before all adds.
    Now, say pre-dec has higher precedence than mult. It may, it may not, I don't know and I don't care. It doesn't matter here, but let's say it does.
    y-- * 3 / --yis the same as
    (y--) * 3 / (--y)Operands are still evaluated L to R. We don't just jump around.
    1. Evaluate y--
    1.1 value of expression is 5
    1.2 decrement y to 4
    2. Evaluate 3.
    3. Multiply #1 *** #2 --> 5 *** 3 = 15
    4. Evaluate --y
    4.1 decrement y
    4.2 valueof expression is 3
    5. evaluate #3 / #4 --> 15 / 3 = 5
    Edited by: jverd on Feb 12, 2010 11:54 AM
    Edited by: jverd on Feb 12, 2010 11:56 AM

  • The plus(+) and minus(-) keys to increment or decrement the date

    Hi All,
    I have a date field in which I would like to have the + and - keys to increment or decrement the date as in some windows programs.
    Thank you, Bill

    Hi Chad, Yes I know the Date Picker... that is what it has now.
    My users are keyboard users... hitting the plus or minus sign in the Num Pad is much quicker if the date is only 2-3 day plus or minus...
    We desire to have the Date Picker and have maybe a onkey event call. I was hoping to find someone that has used "onkey" for a specific element/field so it doesn't look at every key stroke in the document but just the one date element onkeyup etc......
    Thanks for the response.
    Bill

  • Use of scope resolution operator in PHP development example

    I am relatively new to OOP in general so this question may sound dumb but
    In this documentation:  Query Performance and Prefetching
    To quote that text, "
    The $db->setPrefetch() call is used to set the prefetch value. The microtime() calls are used to show how long the report took to generate.
    A new Db::fetchRow() method is used to get one row at a time. It is called in a loop after the query has been run"
    Why the does it use the scope resolution operator? Isn't it used for just static methods and overridden methods.
    I do not see any static declaration when this method is entered into class.
    To quote the method declaration:
      /** * Fetch a row of data. Call this in a loop after calling Db::execute() * * @return array An array of data for one row of the query */
    public function fetchRow() {
    $row = oci_fetch_array($this->stid, OCI_ASSOC + OCI_RETURN_NULLS);
    return($row);
    Am I missing something really trivial thing about this concept?
    Thank you.

    It's shorthand documentation for "A new fetchRow() method in the DB class is used to get..."

  • Using the match/merge operator

    Hi guys,
    I have created a simple table with 4 columns:
    EMPLOYEES
    - employee_id
    - emp_firstname
    - emp_lastname
    - emp_telephone
    I have placed 5 entries in the table:
    11, jane, doe, 80980980
    12, william, gates,6876876868
    13, john, anderson, 545646546
    14, michelle, millo, 340580334
    15, john, anderson, 545646546
    Row 13 and 15 are duplicates, except for the employee_id. I'm trying to use the match-merge operator to check for matches on emp_firstname, emp_lastname and emp_telephone. I would like to merge the rows matching on firstname, lastname and telephone number, and would like to keep the lowest employee_id as PK.
    I have tried to use the match-merge operator with the following settings;
    Input connections:
    - employee_id
    - emp_firstname
    - emp_lastname
    - emp_telephone
    Merge output
    - employee_id
    - emp_firstname
    - emp_lastname
    - emp_telephone
    Xref output
    none
    Match bins:
    - emp_firstname
    - emp_lastname
    - emp_telephone
    Match rules:
    MA_0, all_match
    Merge rules:
    emp_firstname: all match
    emp_lastname: all match
    emp_telephone: all match
    When I debug the match merge operator I get " 4 in, 4 out", but I expected to have "5 in, 4 out". Am I using this match/merge operator the right way?
    thx for you help!
    michiel
    null

    Hi Robert,
    I tried on 3 database installations (all 10.2). there is no parameter DB_BLOCK_BUFFERS set. And i do not assume that there is a reasn for increasing the db_cache_size - means: why i did not get any error for that presumed case?
    btw: can you explain why i should increase db_cache_size?
    thanks,
    Andreas

  • Problem using pre-mapping process operator in owb 9i

    Hi,
    I was trying to use the pre-mapping process operator in owb 9i. Problem is that the manual does not specify how the inputs need to be connected to this operator. Following is what I went through -
    I created a mapping table operator and a mapping dimension operator and connected these two. Then i created a pre-mapping process operator selecting the LTRIM function. Further I connected one of the table attributes to this pre-mapping operator as input and connected the output of this pre-mapping operator to the appropriate dimension operator attribute. On performing Validate, following error message was flashed -
    VLD-2451 : Illegal connection to pre-mapping process operator
    I am trying to learn how to use OWB 9i from the manual. So my interpretation of the use of the pre-mapping process operator may be wrong.
    In any case kindly help,
    Thanks
    Saju

    Pre-mapping process is use to perform some operations preceding to mapping operation itself.
    For example, if your mapping is designed to incrementally append data to table for the definite time interval (witch is a parameter of the map operation) you might want to perform the table data cleanup for that period. That will allow for reload data number of time.
    In this case you have to define the procedure witch perform cleanup and than include the call to that procedure as a pre-mapping process.
    Other examples of pre- and post mapping process is disabling referential integrity before loading and re-enabling them after loading.
    Anyway, OWB documentation has clear definition for pre- and post-mapping processes.

  • The Increment and Decrement Operators (++ and - - )

    Hi all !
    Even if i do understand how ++ and -- operators works fine (as a pre-modifers and post-modifers) but i can't understand how do they got the HIGHTEST precedence (unary operators) over than other operators , consider the follwing examples :
    Ex(1):
    ======
    initially : x = 5 & y = 0;
    y = x++ ;
    i know the process goes like this :
    - Evaluation : Left-to-Right (y is 0 and x is 5)
    - Operation : assignement of x to y , then increment x by 1.
    Q(1) is : why do assignment first then increment even if operator ++ has higher precendence than "=" operator.
    (i understand that that is true if y=++x, but why? ).
    Ex(2):
    ======
    initially : x=5 & y =0;
    y = x++ + 5;
    y now is 10 , x now is 6
    Q(2) is : even if the ++ operator is higher in precedence ,the arithmetic operator "+" is evaluated first, why?
    (same applies to the -- operator)
    Thanks ...

    Q(1) is : why do assignment first then increment even
    if operator ++ has higher precendence than "="
    operator.
    (i understand that that is true if y=++x, but why? ).The assignment is not performed first:
    (1) Memory is reserved to store the result of the expression on the right hand side.
    (2) The expression evaluates to the current value of x, which is 5. This value is stored away.
    (3) x is incremented, and is now equal to 6.
    (4) The value previously stored away is assigned to y. y is now 5.
    Q(2) is : even if the ++ operator is higher in
    precedence ,the arithmetic operator "+" is evaluated
    first, why?The + operator is not evaluated first:
    (1) Memory is reserved to store the result of the expression on the right hand side.
    (2) The current value of x is stored in that reserved memory. The value is 5.
    (3) x is incremented to 6.
    (4) 5 is added to the expression result, and the result is now 10.
    (5) The expression result is assigned to y. y is now 10.
    Note that the implementation is free to perform the calculation however it wishes, so long as it is done such that the user/programmer can not tell the difference.

  • Why nokia uses very cheap plastic for N79?

    I bought a Nokia N79 for 350 € one month ago. Although my ultimate care and even I used a special protecting case for the phone, there were little scratches all over the front plastic cover. I wonder why nokia used very cheap plastic on the front cover for a very expensive mobile phone?

    Volume increases in 10 steps and last step, from 90 to 100% is like someone that suddenly turn a 1000w speaker right in your ear. :-) This is not normal and it was so easy to fix before to sell this phone. Maybe no-one tryed the phone before to sell it.
    Album Art search is an automatic procedure from iTunes to Winamp. I don't have to use pcsuite, don't have to download from phone. Btw it doesn't appear, better than an error.
    Let me say, about the clock alarm. I'm a doctor. To have something complete to make quick photos to wounds, procedures and so on or make videos, I thought this could be a great phone. I used the phone alarm of this phone only two times and never use it again. I lost a morning appointment and to awake for the night turn. It sound funny now, but let's try to imagine my anger when for years I used a cheaper phone, never getting late. I don't sell nuts, with all of my respect for nuts seller.
    Why do I have to use another piece of software when the included one should function? It is like to harvest an arbor because it doesn't give you fruits without trying to think why and look for a solution. Did I give too much water? Is it infested by some bugs?
    Symbian UIQ, rest in piece, decided to use Opera Mini as defalt browser. That is a cure. If Symbian OS doen't want to use it has to solve its bugs quickly or send an advice through that stupid My Nokia service saying that browsing experience will not be so easy.
    You buy a phone because you don't want a Ferrari. You buy a phone for the specifications write on the box. In Florence, you can't try the phone before, sorry man. It would be really nice but you can't. You buy for radio and radio doesn't work, you buy for camera and shoot button doesn't do auto-focus, (now repaired), you buy for a simple mp3 player and you are going to lose audition, you buy for a phone and thanks God it works . You give every single cents hoping for a positive experience and you change manufactuer because this one gives you - now - what you are looking for. I'm not a SE, Motorola or Nokia fan. I read reviews and compare trying to have an idea. That's what we do, all of us.
    I respect your point of view about S60, I am excited about wonderful programs to watch divx - by the way tv-out is choppy, ugly and something to not try if you have an n79; I thought it could be wonderful for my presentation... let's forget it - to do sport and to buy some useful cheap, read the humour, map for Nokia Maps. No, really I know this is a great software, I love open source and hope that will arrive more and better apps when it will be open, but you buy a phone for what's on. Not for what it could do in future with bug fixes. Tomorrow I will sell it and maybe never see that bug fixed.
    An example: Apple. IMHO is getting worst that before. I'm not an Apple fan but I have to admit that it knows how to work with software and hardware. It prefeared not to put mms and other functions on its iphone because...
    ...who knows. The point is: less software to fix means better experience for end-user and quality of firmware releases. With three, or something similar, releases Apple covered many of what the users cryed for in less than two years. Remember, every basic function was at best. Nokia sold n79 and 5800 quite in the same time. Firmware release of n79 was ridicolous, 14 pages of fw after four months? What did you sell it for Nokia? Wait four months more. 5800 is an interesting phone, different from the iphone, full of great features and great bugs.
    At the end, I respect your idea of evolution of a phone and its getting better day by day, while I need that a phone is ready to go since first start even with some bug, because noone has no bug, but not ridicolous bugs. That's why Nokia pi22ed me off with this n79.

  • Why Oracle10g uses System Rollback Segment....????

    Hi ,
    Just a wonder....!!!!
    Why Oracle10g uses System Rollback Segment....and not System undo tablespace... since rollback segment as a method to rollback transactions has been depreciated.....?????
    Thanks.....
    Sim

    System Rollback Segment is reserved for Oracle internal operation.
    I believe it is used only by SYS and programs invoked using SYS authorization manipulating dictionary tables. In which case the complexity has been understood and managed over several generations of Oracle.
    I suspect the system (manual) roillback segment will be very useful when creating a new database, which includes creating whole bunches of tables and views (updating whole bunches of internal tables), at which time no undo segment (or background process for automating that management?) exists.
    Please point to the document or link that says rollback segments are deprecated.
    Even now, manual rollback segments may be of benefit to specific programs and environments that run batch jobs managed by DBA whoy has studied them for a long time under specific circumstances.
    But, just like the various SGA pools should be evaluated and potentially resized when workload changes, the rollback segment configuration needs to be evaluated and potentially resized when workload changes. Few DBAs have the knowledge or skill or time to do so - the automatic adjustments may be the best generic compromise.

  • Why when using Adobe Bridge,  I apply a star rating,  the rating does not show up in Photoshop Elements? [tags]

    Why when using Adobe Bridge,  I apply a star rating,   the rating does not show up in Photoshop Elements.  I use Elements as my organizer and Bridge to view as it is much more user friendly.  Anyone any solutions??

    Most likely you have set the wrong file as the external editor. You don't want the obvious one; that's just a link to the welcome screen. Go back and choose this one, which is hidden away inside the folder Support Files:

  • I want to ask something about firefox. why firefox use very much memory? can you develop to reduce memory comsume? this problem is very distrub in my PC with low memory.

    I want to ask something about firefox.
    why firefox use very much memory?
    can you develop to reduce memory comsume?
    this problem is very distrub in my PC with low memory.
    == This happened ==
    Every time Firefox opened

    How much memory is Firefox using right now?
    # Press '''CTRL+SHIFT+ESC''' to load the Task Manager window
    # Click the Processes tab at the top. (Click once near the top of the window if you don't see tab
    # Find firefox.exe, and see how many kilobytes of memory it's using.
    Showing around 80MB when Firefox first starts is normal. Right now, I have 75 tabs open and it's using 500MB - this varies a lot depending on what you have in the tabs.
    Other than high memory usage, what other problems are you experiencing? (Examples include slowness, high CPU usage, and failure to load certain sites)
    Many of these issues, including high memory usage, can be caused by misbehaving add-ons. To see if this is the case, try the steps at [[Troubleshooting extensions and themes]]. Outdated plugins are another cause of this issue - you can check for this at http://www.mozilla.com/plugincheck

Maybe you are looking for

  • How to use Derby database in embedded mode in WebLogic 12c?

    I have a JavaEE-6 application that uses Derby database in embedded mode. It uses JPA for persistence. Everything works fine in Glassfish but now I am trying to port it to WebLogic 12c and having issues setting up Derby database in WLS in embedded mod

  • [SOLVED] How to get ibus to work in xterm

    Can anyone help me get ibus working in xterm? Ibus is working in all my other applications except xterm. In my pre-Arch days I had the same problem in Debian. In Debian I fixed the problem by editing /etc/X11/xinit/xinput.d/default so that it looked

  • Hangs on Mac

    SQL Developer hangs on my mac with the following specs.  See error below OS X 10.9.1 java version "1.7.0_45" Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode) from the terminal sh /Ap

  • WAR file not getting generated

    I am in the development of a web application with jsf2 ,and I am almost done with that and pretty much happy with the outcome , but now comes the problem , I am trying to get the project as WAR file but after the war creation wizard I am not seeing a

  • Using DVDSP just to encode a DVD

    Something strange is going on with my iDVD on my mac and I do not know where the install disk is and I need to simply take some video from FCP and compress and burn it to a DVD in DVDSP. Can anyone give me the steps for using DVDSP just for this purp