Java
  Home arrow Java arrow Page 2 - Java Part 2: Syntax
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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? 
JAVA

Java Part 2: Syntax
By: Chris Noack
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2001-11-27

    Table of Contents:
  • Java Part 2: Syntax
  • Decleration and assignment
  • Making code more readable
  • Truth operations
  • Iterations and looping
  • The while loop
  • Putting it all together
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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 Part 2: Syntax - Decleration and assignment


    (Page 2 of 8 )

    Java variables are declared in exactly the same way as in both C and C++. Let's declare a variable of type int and then set it to a value:

    int val;

    val = 1;


    This decleration could be shorted to just one line of code, like this:

    int val = 1;

    Addition and Subtraction

    The standard C incremetor function ++, or -- for decrementing a variable still holds in Java. For example:

    int val = 1;

    val = val + 1; // val is now 2


    Further, we can simplify the second line even more:

    val++;

    This works the same for decrementing. These two operators for incrementing and decrementing are known as unary operators because they only require one argument.

    Multiplication and Division

    To multiply a variable by a numerical value, we use the * operator, like this:

    val = val * 10; // Multiply val by 10

    We can also multiply a variable by a number like this:

    val *= 10; // Same as val = val * 10

    Multiplying one variable by another is also simple:

    var = var * par;

    OR

    var *= par;

    Division follows exactly the same principles as addition, subtraction and multiply:

    val = val / 50;

    OR

    val /= 50;

    Also, dividing one value by another is easily accomplished:

    val = val / par; // Same as val = val / par

    OR

    val /= par; // Same as val = val / par

    More Java Articles
    More By Chris Noack


     

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







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