CIS283: Introduction to Application Programming with Java - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

CIS283: Introduction to Application Programming with Java

Description:

'concatenate ' 'this' A block of statements is delimited by. and. Look for. statemements ... String concatenation 'append ' 'number ' 7 ' here' ... – PowerPoint PPT presentation

Number of Views:63
Avg rating:3.0/5.0
Slides: 39
Provided by: jpC3
Category:

less

Transcript and Presenter's Notes

Title: CIS283: Introduction to Application Programming with Java


1
CIS283 Introduction to Application Programming
with Java
  • Jose perez-carballo

2
  • The ABCs of programming

3
  • Statements and expressions
  • A statement does something
  • int A
  • A 3

4
  • An expression is a statement (or part of a
    statement) that produces a value
  • 2 3
  • 2 gt 3
  • concatenate this

5
  • A block of statements is delimited by
  • and

6
  • Look for
  • statemements
  • Expressions
  • And blocks
  • In http//www.calstatela.edu/faculty/jperezc/cours
    es/CIS283/examples/chapter1/VolcanoApplication.jav
    a
  • And
  • http//www.calstatela.edu/faculty/jperezc/courses/
    CIS283/examples/chapter1/VolcanoRobot.java

7
  • Variables
  • Place to store values
  • A variable has
  • Name
  • type

8
  • Before a variable can be used it must be declared
  • int a

9
  • Values can be assigned to variables
  • A 3

10
  • The value of an expression can be stored in a
    variable
  • A 3 4/2

11
  • The value stored in a variable can be changed
    while the program is running
  • A 3
  • A 5

12
  • A variable can be given an initial value
    (initialized) when it is declared
  • int A 3

13
  • Look for
  • variables
  • Declarations
  • Initial values in
  • http//www.calstatela.edu/faculty/jperezc/courses/
    CIS283/examples/chapter1/VolcanoApplication.java
  • And
  • http//www.calstatela.edu/faculty/jperezc/courses/
    CIS283/examples/chapter1/VolcanoRobot.java

14
  • Instance variables store object attributes
  • Examples?
  • Class variables store for all objects of a class
  • Examples?
  • Local variables exist only inside a block, when
    the block is finished executing its local
    variables are destroyed

15
  • Look for instance, class and local variables in
  • http//www.calstatela.edu/faculty/jperezc/courses
    /CIS283/examples/chapter1/VolcanoApplication.java
  • And
  • http//www.calstatela.edu/faculty/jperezc/courses/
    CIS283/examples/chapter1/VolcanoRobot.java

16
  • If not given an initial value Java intializes
  • Numeric variables to 0
  • characters to \0
  • Booleans to false
  • Objects to null

17
  • Naming variables
  • A variable can be
  • Any sequence of numbers, letters (upper/lower
    case), _, and
  • They cannot start with a number
  • Java uses Unicode characters

18
  • Which are valid variables
  • 1JavaVariable
  • One_Java
  • javac
  • _javac
  • JavaVariable
  • JavaVariable
  • java123Variable
  • café

19
  • Conventions
  • thisIsAGoodName
  • thisisnotsogood

20
  • Variable types
  • One of the eight primitive types
  • A class or an interface
  • An array

21
  • Primitive types
  • Integers (positive and negative)
  • byte 8 bits
  • short 16
  • int 32
  • long 64. E.g. 111111L
  • Non integer numbers (positive and negative)
  • double e.g. 2.2E2d
  • float e.g 3.3E3f
  • Characters
  • char e.g. a
  • Booleans
  • boolean true or false

22
  • A class can be used as a type
  • VolcanoRobot dante new VolcanoRobot()

23
  • If Animal is superclass of Elephant then
  • Elephant clyde
  • Animal aa
  • aa clyde

24
  • Assignment statements
  • Variable expression
  • A 3 4

25
  • Constants
  • final float PI 3.1416

26
  • Comments
  • // this is a comment
  • / this is a comment /
  • / this is a comment /

27
  • Literals represent values directly
  • 2008
  • 2d
  • 3f
  • 0xFF
  • 010
  • 12e22

28
  • Java character escape codes
  • \n New line
  • \t Tab
  • \b Backspace
  • \r Carriage return
  • \f Formfeed
  • \\ Backslash
  • \' Single quotation mark
  • \" Double quotation mark
  • \d Octal
  • \xd Hexadecimal
  • \ud Unicode character

29
  • String literals
  • Real objects
  • String Hello World!

30
  • Expressions
  • x 3
  • y x
  • int z x 3

31
  • Artihmetic operators
  • -
  • /

32
  • Assignment operators
  • -
  • /

33
  • Incrementing and decrementing
  • x
  • x

34
  • Comparison operators
  • !
  • lt
  • gt
  • lt
  • gt

35
  • Logical operators
  • (shortcircuiting)
  • (XOR)
  • !

36
  • Operator precedence
  • X 6 4 / 2
  • (see table 2.6)

37
  • String concatenation
  • append number 7 here

38
  • Downloading and installing Java
  • https//jdk6.dev.java.net/ download Windows
    Offline Installation, Multi-language JDK file
  • See installation instructions http//java.sun.com
    /javase/6/webnotes/install/index.html
  • See also Appendix A
Write a Comment
User Comments (0)
About PowerShow.com