+ All Categories
Home > Documents > Web viewProgramming Constructs Programming Fundamentals JAVA CHARACTER SET is a set of valid...

Web viewProgramming Constructs Programming Fundamentals JAVA CHARACTER SET is a set of valid...

Date post: 23-Oct-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
9
Indian School Al Wadi Al Kabir Class IX – Computer Science, Subject: Java Programming Handout-2 – Java Character Set,Tokens, Data types, Text Interaction Methods ,Operators and Programming Constructs Programming Fundamentals JAVA CHARACTER SET is a set of valid characters that a language can recognize. A character represents any letter, digit or any other sign. JAVA uses UNICODE character set. UNICODE is a two-byte character code that has characters representing almost all characters in all language. UNICODE is similar to ASCII character set. UNICODE character is represented by using escape sequence(\u) followed by a four digit hexadecimal number. for example: \u00AE The copyright symbol \u0022 The double quote \u0394 The capital Greek letter delta Token: The smallest individual unit in a program is known as Token. Java has the following types of tokens: 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. 1| Class X/17-10-2017/ISWK/Comp. Sc
Transcript

Indian School Al Wadi Al Kabir

Class IX – Computer Science, Subject: Java Programming

Handout-2 – Java Character Set,Tokens, Data types, Text Interaction Methods ,Operators and

Programming Constructs

Programming Fundamentals

JAVA CHARACTER SET is a set of valid characters that a language can recognize.

A character represents any letter, digit or any other sign.

JAVA uses UNICODE character set.

UNICODE is a two-byte character code that has characters representing almost all characters in all language.

UNICODE is similar to ASCII character set.

UNICODE character is represented by using escape sequence(\u) followed by a four digit hexadecimal number.

for example:

\u00AE The copyright symbol

\u0022 “ The double quote

\u0394 The capital Greek letter delta

Token: The smallest individual unit in a program is known as Token.

Java has the following types of tokens: 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.

Identifier

Identifiers are the fundamental building blocks of a program.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 valid identifiers: age, $salary, _value, __1_value

· Examples of invalid identifiers: 123abc, -salary

Literals:

Literals(often referred to as constants) are data items that never change their value during a program run.Various types of literals available in Java are :

· Integer literals

IL are the whole numbers without any fractional part.There are three types of integer literals:1) Decimal (base 10)2) Octal (base 8)3) Hexadecimal(base 16)

· Floating literals

Floating literals are called as real literals. Real literals are numbers having fractional part.

· Character literals

A character literal is one character enclosed in single quotes.Eg: ‘z’

· String literals

Multiple character constants are called as string literals.Eg: “ISWK”

Punctuators: The following nine ASCII characters are the separators: [ ] ( ) { } , ; : * = #

Operators: Operators are tokens that trigger some computation when applied to variables in

an expression.Different types of operators are:

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.

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] ...] ;

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 ch has the value 'H'.

Text Interaction Methods

setText() Method

This method is used to change the display text of a component (label, text field or button) during run time.

Syntax: component.setText("text")

The "text" is the display text to be shown for the mentioned component.

getText() Method

This is used to return the text contained in the referred text component. It is generally used to retrieve the value typed by the user in a textbox or label. The syntax for this method is given below

Syntax: jtextField1.getText()

This command is used to retrieve the value of the text Field named jtextField1

parse Method:

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

Programming Constructs:

The statements inside your source files are generally executed from top to bottom, in the order that they appear. Control flow statements, however, breakup the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code.

DIFFERENT TYPES OF PROGRAMMING CONSTRUCT:

1. SEQUENCE

2. SELECTION

SEQUENCE CONSTRUCT: Sequence construct means the statements are being executed sequentially. It is a default flow of statement from top to bottom.

SELECTION : A selection statement selects among a set of statements depending on the value of a controlling expression. They are also called as Decision Making Statements. They are:

6| Class X/17-10-2017/ISWK/Comp. Sc

1) if statements

2) if else statements

(1) if statements: The if statement allows selection (decision making) depending upon the outcome of a condition. If the condition evaluates to true then the statement immediately following if will be executed and otherwise the first set of code after the end of the if statement (after the closing curly brace)

Will be executed.

(i) Simple if:

The syntax of if statement is as shown below:

if (conditional expression)

{

Statement Block;

}

Example

int x = 10;

if( x < 20 )

{

System.out.print("This is if statement");

}

This would produce the following result: This is if statement.

The if...else Statement: An if statement can be followed by an optional else statement, which executes when the Boolean expression is false. syntax of if-else statement is as shown below:

Syntaxif (conditional expression){Statement Block;}else{Statement Block;}

Example: int x = 30; if( x < 20 ){System.out.print("This is if statement");}else{System.out.print("This is else statement");}This would produce the following result: This is else statement


Recommended