Java
  Home arrow Java arrow Page 3 - Java Operators
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
JAVA

Java Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 12
    2007-10-22


    Table of Contents:
  • Java Operators
  • Assignment Operators
  • Doing More Math with Assignment Operators
  • Forming a Relationship with Operators

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Java Operators - Doing More Math with Assignment Operators
    ( Page 3 of 4 )

    Below is a list of Assignment and Arithmetic Assignment Operators and what they do:


    Operator

    What it Does

    +

    For addition

    -

    For subtraction

    *

    For multiplication

    /

    For division

    %

    For modulation

    ++

    For incrementing

    --

    For decrementing

    +=

    For addition assignments

    -=

    For subtraction assignments

    *=

    For multiplication assignments

    /=

    For divisional assignments

    %=

    For modulus assignments


    If you want to incrementally increase a number, you can do so this way:


    my_weight = 4000;

    my_weight++;

    This would increase my weight from 4000 to 4001. If I stood up, lifting my enormous body, I could adjust my weight this way:


    my_weight = 4001;

    my_weight--;

    Now my weight is back down to a fearsome 4000. Soon you won't be able to see me when I turn sideways. Dealing with increments/decrements can get tricky for some people, but not us with our enormous brains. The reason they can become tricky is because of operator precedence. Observe the following two coding samples:


    my_weight = 4000;

    my_new_weight = ++my_weight;

    The above would result in my weight being 4001. This is because the ++ takes precedence, adding 1 to my weight before adding my_weight to my_new_weight. If I had placed the ++ on the opposite side of my_weight I would have received a different result.


    my_weight = 4000;

    my_new_weight = my_weight++;

    This would result in my_new_weight carrying the value 4000. This is because it adds the value of my_weight to my_new_weight prior to adding 1 to the value of my_weight.



     
     
    >>> More Java Articles          >>> More By James Payne
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek