Java
  Home arrow Java arrow Page 4 - 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 - Forming a Relationship with Operators
    ( Page 4 of 4 )

    Admit it, back in the old days when real people answered the phone, you often thought...I bet this operator is hot. Maybe you even flirted a little. Perhaps you even went as far as to try to make a date with the operator, and when she said she didn't know you, you took that as a sign that you should call her back every hour until she did know you. Nice try; you'll be glad to hear then that working with relational operators is quite different from trying to get a date from an operator.

    Relational operators compare data to one another. Below is a hot list of relational operators and what they do:


    Operator Symbol

    What It Does

    “==”

    Equal To

    !=

    Not Equal To

    >

    Is Greater Than

    <

    Is Less Than

    >=

    Greater Than or Equal To

    <=

    Less Than or Equal To

    Relational operators will come in handy when we take a look at Conditionals and Loops. For now, here is a sampling of what that relationals look like in code:


    class FlexOff {


    public static void man(String[] args) {

    int my_muscles = 10;

    int your_muscles = 1;


    if(my_muscles > your_muscles) System.out.println(“My muscles are larger than yours!”);


    if(my_muscles < your_muscles) System.out.println(You must be taking steroids.”);


      }

     }

    In the above code, we have to value: my_muscles and your_muscles. Each is assigned a numeric value from 1 to 10, with 10 being the greatest. We then have an If-statement (we will go over these in another tutorial) that states if my_muscles are greater than your_muscles, do this. In the above sample,  my_muscles are indeed greater than your_muscles (by a factor of ten no less; I'm practically Hercules) and so the program will print out:

      My muscles are larger than yours!

    Had your muscles been bigger than mine, two things would have occurred: 1) Hell would have frozen over and 2) the following text would be written to the screen:

      You must be taking steroids.

    Now let's imagine that you were stronger than me. When I had you called up for review by the Steroid Usage is a No No Board, they would ask you, Yes or No, True or False...have you used steroids?

    And with that little segue, it's time to introduce you to the Boolean Logical Operators.

    Unfortunately for you however, we have run out of time for this tutorial. But never fear; in our next tutorial we will cover the rest of the operators and delve into Statements.

    Until then however, feel free to study this table of our remaining Operators:


    Operator Symbol

    What it Does

    &

    And (Logical)

    |

    Or (Logical)

    ^

    XOR (exclusive OR)

    ||

    Or (short circuit)

    &&

    And (short circuit)

    !

    Not (logical unary)

    &=

    AND assignment

    |=

    OR assignment

    ^=

    XOR assignment

    “==”

    Equals

    !=

    Not Equal To

    ?:

    If-then-Else (ternary)

    Till next time (plays Batman theme song). POW! BLAM! BIFF! BOP!



     
     
    >>> 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