Java Syntax Part I - PowerPoint PPT Presentation

About This Presentation
Title:

Java Syntax Part I

Description:

at the beginning of a big block. on the same line of certain statements ... including _ (underscore) or $ (dollar sign) Followed by letters or digits ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 10
Provided by: meng9
Category:
Tags: dollar | java | part | sign | syntax

less

Transcript and Presenter's Notes

Title: Java Syntax Part I


1
Java Syntax Part I
  • Comments
  • Identifiers
  • Primitive Data Types
  • Assignment

2
Java Syntax - Comments
  • Type 1
  • begins with /
  • continues till the next /
  • Type 2
  • begins with //
  • continues till the end of the line
  • Type 3
  • begins with /, and continues till the next /

3
Java Syntax -- comments (style)
  • Good programming practice
  • Put helpful comments
  • at the beginning of a big block
  • on the same line of certain statements
  • Good internal documentation is very important

4
Java Syntax -- comments (example)
  • //--------------------------------------------
    -------------------------------
  • // withdraw withdraw money from
    banking_account
  • // Input amount the
    amount of money to withdraw
  • //--------------------------------------------
    --------------------------------
  • void withdraw(float amount)
  • //----------- if not enough money in
    the account ----

  • //----------- else, we have enough
    money in the account ----
  • ...

5
Java Syntax -- Identifiers
  • Names of declared entities
  • variables, constans, labels
  • Must start with a letter A..Za..z
  • including _ (underscore) or (dollar sign)
  • Followed by letters or digits
  • Java language keywords can not be used as
    identifiers.

6
Java Syntax -- Identifiers (example)
  • accountNumber
  • length1
  • length_2

7
Java Syntax -- Primitive Data Types
  • boolean takes only 2 values true or false
  • Example boolean done false
  • char contains a character
  • Example char ch
  • byte, short, int and long Integral Types
  • Example int num 3
  • float, double Floating-Point Types
  • Example float temperature 37.6

8
Java Syntax -- Assignment
  • Example using integers
  • int i 2 // create an integer
    variable
  • i 5 // change i to 5
  • int j 6 // create an integer
    variable j
  • i j3 // multifply the value of
    j by 3
  • // now i 18
  • i i 4 // NOT AN EQUATION!
  • // i was 18, i422
    new i22.
  • Calculate the value on the RIGHT HAND SIDE
  • Assign the result to the variable on the LEFT
    HAND SIDE

9
Java Syntax -- Assignment (Abbreviations)
  • Examples
  • j j 1 // as before
  • j 1 // same as j j 1
  • j 5 // same as j j 5
  • j // same as j j 1
Write a Comment
User Comments (0)
About PowerShow.com