5
Indian School Al Wadi Al Kabir Class X – Computer Science, Subject: Java Programming Handout-3 – Tokens, Data type, Text Interaction Methods and Operators Programming Fundamentals Token : The smallest individual unit in a program is known as Token. Java has the following types of tokens:eg keyword, Identifier, literal, punctuators and operators. Keywords: Keywords are words that have a specific predefined meaning in Java. They cannot be used as variable names. They are also known as reserve words. Eg: Identifier Identifiers:-All Java components require names. Names used for classes, variables and methods are called identifiers. In Java, there are several points to remember about identifiers. They are as follows: · All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). · After the first character identifiers can have any combination of characters. · A key word cannot be used as an identifier. 1| Class X/07-08-2017/ISWK/Comp. Sc

 · Web viewProgramming Fundamentals. Token: The smallest individual unit in a program is known as Token. ... In Java, all variables must be declared before they can be used

Embed Size (px)

Citation preview

Page 1:  · Web viewProgramming Fundamentals. Token: The smallest individual unit in a program is known as Token. ... In Java, all variables must be declared before they can be used

Indian School Al Wadi Al KabirClass X – Computer Science, Subject: Java Programming

Handout-3 – Tokens, Data type, Text Interaction Methods and OperatorsProgramming FundamentalsToken : The smallest individual unit in a program is known as Token. Java has the following types of tokens:eg keyword, Identifier, literal, punctuators and operators.Keywords: Keywords are words that have a specific predefined meaning in Java. They cannot be used as variable names. They are also known as reserve words. Eg:

Identifier

Identifiers:-All Java components require names. Names used for classes, variables and methods are called identifiers.

In Java, there are several points to remember about identifiers. They are as follows:· All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_).· After the first character identifiers can have any combination of characters.· A key word cannot be used as an identifier.· Most importantly identifiers are case sensitive.· Examples of legal identifiers: age, $salary, _value, __1_value· Examples of illegal identifiers: 123abc, -salaryLiterals:

Items having fixed data values are referred to as Literals. They are also known as Constants. Various types of literals available in Java are :

Integer literals Floating literals Boolean literals

1| Class X/07-08-2017/ISWK/Comp. Sc

Page 2:  · Web viewProgramming Fundamentals. Token: The smallest individual unit in a program is known as Token. ... In Java, all variables must be declared before they can be used

Character literals String literals Null literals

Punctuators: The following nine ASCII characters are the separators: ( ) { } [ ] : ; , ? .

Operators: Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result.

Arithmetic operators: Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following table lists the arithmetic operators:

Relational Operators :

The relational operators determine the relationship that one operand has to the other. Java provides six relational operators, which are listed in below table.

Logical Operators:

Sometimes, whether a statement is executed is determined by a combination of several conditions. You can use logical operators to combine these conditions. Logical operators are known as Boolean operators or bitwise logical operators.

2| Class X/07-08-2017/ISWK/Comp. Sc

Page 3:  · Web viewProgramming Fundamentals. Token: The smallest individual unit in a program is known as Token. ... In Java, all variables must be declared before they can be used

Data type: Data type states the way the values of that type are stored in memory, and the range for that type. There are two data types available in Java:

• Primitive Data Types• Reference/Object Data Types

Variable: Variable is a named storage location in computer memory whose contents can change during a program run. The characteristics of a variable are:(i) It has a valid name.(ii) It is capable of storing values.(iii) It provides temporary storage.(iv)It is capable of changing its value during program execution.(v) Each variable must declare before use along with its data type.

Variable Declaration:In Java, all variables must be declared before they can be used. The basic form of a variable declaration is:DataType identifier [ = value][, identifier [= value] ...] ;

3| Class X/07-08-2017/ISWK/Comp. Sc

Page 4:  · Web viewProgramming Fundamentals. Token: The smallest individual unit in a program is known as Token. ... In Java, all variables must be declared before they can be used

Here, The DateType is one of Java's data types. The identifier is the name of the variable.To declare more than one variable of the specified type, use a comma-separated list.Note: Java variable names are case sensitive, so MySum and mySum are not same variable.Example:int x, y, z; // declares three integers type (int) x, y, and z.int d = 3, e, f = 5; // declares three more integer with initialization byte z = 34; // initializes z.double pi = 3.14; // declares an approximation of pi.char ch = 'H'; // the variable x has the value 'x'.

parse methods: parse() methods helps to parse string into different numeric types. These are :

4| Class X/07-08-2017/ISWK/Comp. Sc