10
Variables By Samuel T. C. Santos [email protected]

Variables

Embed Size (px)

Citation preview

Page 1: Variables

VariablesBy

Samuel T. C. Santos

[email protected]

Page 2: Variables

Variables

An object stores its state in fields; The terms “field” and “variable” are both

used.

Page 3: Variables

Variables

The Java programming language defines the following kinds of variables;

Instance Variables (Non-Static Fields) ; Class Variables (Static Fields); Local Variables; Parameters.

Page 4: Variables

Instance Variables (Non-Static Fields)

Objects store their individual states in “non-static fields”;

Fields declared without the static keyword; Instance variables because their values are

unique to each instance of a class;

Page 5: Variables

Class Variables (Static Fields)

A class variable is any field declared with the static modifier;

Fields declared without the static keyword; Instance variables because their values are

unique to each instance of a class; Tells the compiler that there is exactly one copy

of this variable ; The keyword final could be added to indicate

that this will never change.

Page 6: Variables

Local Variables

A method will often store its temporary state in local variables;

There is no special keyword designating a variable as local;

local variables are only visible to the methods in which they are declared;

They are not accessible from the rest of the class.

Page 7: Variables

Parameters

Are always classified as "variables" not "fields".;

Page 8: Variables

Naming

Variable names are case-sensitive; Subsequent characters may be letters, digits,

dollar signs, or underscore characters; Use full words instead of abbreviations. the name you choose must not be a keyword

or reserved word. If the name you choose consists of only one

word, spell that word in all lowercase letters.

Page 9: Variables

Naming

If your variable stores a constant value, capitalizing every letter and separating subsequent words with the underscore character.

DAY_OF_WEEK MATH_PI

Page 10: Variables

The End