Chapter 4 - Chapter4 Variables,Expressionand Assignment...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
    Chapter 4 Variables, Expression and  Assignment
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
    Identifiers An  identifier  is a name that you give to  some thing or some value in your program. Things: Method names Class names Values: 42 “My name is Tiki Tiki Tembo. ..” Here, the value of the  variable is a string  of words. Here, the value is a number.
Background image of page 2
    Variables variable  is an  identifier  whose value can  change as the program runs Example: int x = 0; x = x + 1; System.out.println( " " + x); Prints: 1
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
    This is a  declaration,  it makes room in  memory for a single integer. int x; This is an  assignment , it gives a value to  x: x = 42; You can combine the two into one  command: int x = 42;
Background image of page 4
    Initializing Variables You must give a  variable  a value before  you try to use it. This is called  initialization. If you  declare  a variable, forget to  initialize   it, and then try to use it, Java will  hate  you: int x; System.out.println(" x: " + x); Exception in thread "main" java.lang.Error: Unresolved compilation problem: The local variable x may not have been initialized
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
    Local Variables Any variable that is created inside a method  (or function) is called a  local variable.  Local variables are created when the  method is called and discarded when the  method is done executing. .. so don’t count  on them being there forever.
Background image of page 6
    Parameter Variables Parameter variables are just like local  variables, except they get a value assigned  to them by whoever is calling the method.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 26

Chapter 4 - Chapter4 Variables,Expressionand Assignment...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online