Java
  Home arrow Java arrow Conditionals, Expressions and Other 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

Conditionals, Expressions and Other Java Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2007-10-23


    Table of Contents:
  • Conditionals, Expressions and Other Java Operators
  • Expressions
  • Climbing the Old If Else If Ladder
  • The Switch Statement

  • 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


    Conditionals, Expressions and Other Java Operators
    ( Page 1 of 4 )

    In our last article we left off with Operators. Since then a strange time fluctuation has occurred, and that is exactly where we pick up. So keep reading to learn about exotic things like conditionals, expressions, and more.

    As I recall, by some fluke, you had ended up with more muscles than me (*cough* steroids *cough*) and I put a call into my buddy at the Steroid Usage is a No No Board. To determine if you were a liar, they would have to ask you a series of Boolean questions: True or False -- did you do steroids? Yes or No -- Are you Barry Bonds?

    Booleans are black and white; for them, there is no in between. It's either true or false, yes or no, on or off. We will get into how to use them in programming a bit later on. For now take comfort in the fact that they exist.

    Conditional Operators

    Sometimes you need to know if more than one criteria has been met, or if one of the two criteria has been met. To do that, use conditional operators.


    class IamBetter {


    public static void main(String[] args) {

    int my_muscles = 10;

    int your_muscles = 10;

    int my_looks = 10;

    int your_looks =10;

    if((my_muscle > your_muscle) && (my_looks > your_looks)) System.out.println("I really AM better than you in every way!");

    In the above example, we are asking the computer if my looks and muscles are better than yours. As you can see by the values, they are. Because both criteria are met, the program will print to the screen: I really AM better than you in every way!

    If only one criteria had been met, it would have printed nothing.

    Let's say again, that because of your heavy steroid use and because my Pilates exercise builds lean muscles instead of those stupid looking ones that you have, that you appear to have more muscles than me. It wouldn't matter; I can make the program say that I am still better than you.


    class IamBetter {


    public static void main(String[] args) {

    int my_muscles = 10;

    int your_muscles = 11;

    int my_looks = 10;

    int your_looks =10;

    if((my_muscle > your_muscle) || (my_looks > your_looks)) System.out.println("I really AM better than you in every way!");

    Now that I have changed the criteria so that only one match will suffice, it will still print that I really AM better than you in every way! Again, if neither criteria was true, it would have printed nothing.



     
     
    >>> 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 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek