Você está na página 1de 14

1.

0
2.0

Introduction To OOP
Fundamentals Of Java Programming Language

3.0
4.0

Exception Handling

Classes, Inheritance And Polymorphism


1

1
2 3 4 5 6
7 8

Identify the use of variables Describe the four categories of Primitive Data Types Choose an appropriate data types to represent variables Illustrate local variables and constant stored in memory Declare variables and assign value to variable Identify the variable naming convention Assign a value to a variable Declare a constant
3

Is the name given to the memory location where a value is stored. The name given to the variable is called as identifier.

Integral

These are positive and negative whole numbers. Integers hold number values that cannot have a fractional part. There are four different types: byte short int long

Floating Point

Any number that has a fractional part. Unlike integers, floating point numbers like fractional parts. There are two different types: float double

Textual

a single character. There is only one primitive data type that deals with individual characters char

Logical

either true or false. As Java programs deal in logic there needs to be a way to determine when a condition is true and when it is false. The boolean data type can hold those two values
6

-----------------------------------------------------------------------------------------------------------------------------------------

noOfGoals; priceOfBall; averageAge; receivedStatus;

Local variable: Variables that are defined inside a method and are called local, automatic, temporary, or stack variables Variables that are created when the method is executed are destroyed when the method is exited only visible to the methods in which they are declared they are not accessible from the rest of the class

Constant: A constant is a name for a memory location that stores a value that cannot be changed from its initial assignment.
Syntax : final <type> <identifier> = <value>;
8

Represent with a rectangle. Place value (if present) inside the rectangle. Place type and name above or beside rectangle. Example : int sum=23; int 23 sum

int

sum

23

If the variable is a named constant (that is, declared with the modifier final), then the border of the rectangle is made thicker. This thicker border is meant to suggest that the value of the constant cannot be changed. Example : final double PI=14.5; double PI
9

14.5

When you declare a variable, Java reserves memory locations of sufficient size to store the variable type. The actual data values will be stored in these memory locations. a variable can store only one value at any one time int x; x = 5; x = 10; x x 5 x 10

the value of x is 10 because this was the last value assigned to x.


10

To initialize a variable we use an assignment statement. To give a variable a value, the left side is the name of the variable and the right side is the value: Example : numPlayers = 12; numPlayers = numPlayers + 2;

//numPlayers is assigned 12 //numPlayers is now 14

11

Rules:

Variable identifiers must start with either an uppercase or lowercase letter, an underscore (_), or a dollar sign ($).
Variable identifiers cannot contain punctuation ,spaces, or dashes. Java technology keywords cannot be used. Begin each variable with a lowercase letter; subsequent words should be capitalized, such as myVariable. Choose names that are mnemonic and that indicate to the casual observer the intent of the variable.

12

Example: double price = 12.99;


Example (boolean): boolean isOpen = false; Assigning literal values: int ID = 0; float pi = 3.14F; char myChar = G; boolean isOpen = false; Assigning the value of one variable to another variable: int ID = 0; int saleID = ID;
13

Variable (can change): double salesTax = 6.25; Constant (cannot change): final double SALES_TAX = 6.25; Constants should be capitalized with words separated by an underscore (_).

14

Você também pode gostar