The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by inaazlin, 2018-12-12 20:44:42

3.2(a) data type, operator & expression

data type, operator & expression

Keywords: data type, operator & expression

Tankertanker Tankertanker
Design Design

3.0 Java Language

3.2 Data Type, Operator & Expression

Tankertanker
Design

3.2 Data Type, Operator & Expression

Tankertanker
Design

a) Identify identifier, variables, constant

and reserved word.

Tankertanker
Design

3.2 Identifier

Tankertanker
Design

Identifier are the names that identify the

elements such as classes, methods and

variables in a program

(Y. Daniel Liang – Introduction to Java 10th edition)

Tankertanker
Design

3.2 Identifier

Tankertanker
Design

An identifier :

a) is a sequence of characters that consists of letters,
digits, underscores(_) and dollar sign ($)

b) Must start with a letter, an underscore(_), or a dollar
sign($). It cannot start with digit.

c) Cannot be a reserved words.

d) Cannot be true, false or null.

e) Blank space are not allow

f) Can be of any length

Tankertanker
Design

3.2 Identifier

Tankertanker
Design

• Examples of illegal identifier:

Examples Description

Employee Salary There can be no space between
employee and Salary

Hello! The exclamation mark cannot be used
in an identifier

one+two The symbol + cannot be used in an
identifier

2nd An identifier cannot begin with a digit

int An identifier cannot use reserved word

Tankertanker
Design

3.2 Identifier

Tankertanker
Design

• Examples of Correct identifier:

Examples of identifier
Employee_Salary

Hello

onetwo

Second
integer

Tankertanker
Design

3.2 Identifier

Tankertanker
Design

• Java identifiers are case-sensitive.

• Examples:

HOURLY_RATE 4 different identifiers
Hourly_Rate
Hourly_rate Identifiers - refer to
hourly_rate different memory location.

Tankertanker
Design

3.2 Variables

Tankertanker is a valid identifier that is used to hold a value

• VariablesDesign

(can be read, write or alter as needed).

• A memory location whose content may change during

program execution.

• A variable must be declared before using it in Java.

• Variables are for representing data of a certain type.

• Variable declaration tells the compiler to allocate

appropriate memory space for the variable based on its
data type.

Tankertanker
Design

3.2 Variables

Tankertanker of variable declaration:

• SyntaxDesign

data_type variable_list;

• Examples:

int number1, number2, total;

OR

int number1;
int number2;
int total;

Tankertanker
Design

3.2 Constant

Tankertanker
Design

• A named constant is an identifier that represents a

permanent value.
• Constants are values that do not change during

program execution.
• It can be any type of integer, character or floating-

point.

Tankertanker
Design

3.2 Constant -continue

Tankertanker
Design

• A constant must be declared and initialized in the

same statement.
• The word final is a Java keyword for declaring

constant. Example of declaring a constant:

final double PI = 3.142;

Data type Constant name Value

Tankertanker
Design

3.2 Reserved word

Tankertanker
Design

• A reserved word in Java is a special word that

gets recognized by the compiler.
• When the compiler sees a reserved word, it is

prompted to do a unique task.
• Reserved words cannot be used for any other

purpose in Java, besides their unique task.

Tankertanker
Design

3.2 Reserved words

Tankertanker

•Design List of reserved Java keywords :

abstract assert boolean break byte case
catch continue default
double char class const extends false
final goto if
implements do else enum interface long
native private protected
public finally float for strictfp super
switch throws transient
true import instanceof int while

new null package

return short static

synchronized this throw

try void volatile

Tankertanker
Design

3.2 Reserved words

Tankertanker

•Design Meaning to some of the reserved words :

Reserved Meaning
words
used for declaring a type Boolean
boolean a reserved word in java that will immediately break out of the
break loop
used for declaring a type char
char used for creating a new class
class a reserved word in java that declares a value in java to be a
final constant
a word in java used to return a value in a method
return used to declare something as static, or shared
static

Tankertanker
Design

3.2 Identifier, variable and reserved word

Tankertanker
Design

• Identify the possible identifier in the problem
statement below:

Problem 1 :
“Find the average of three numbers input by user .”

Problem 2:
“Calculate the area of a rectangle”

Tankertanker Tankertanker
Design Design

3.0 Java Language

To be continue


Click to View FlipBook Version