0% found this document useful (0 votes)
128 views

Computer Application 3

1. The document discusses various concepts related to values and data types in Java including character sets, tokens, keywords, identifiers, literals, operators, punctuators, data types, variables, and constants. 2. It explains that a character set defines recognizable characters, tokens are the smallest meaningful units, and keywords are reserved words with specific meanings. 3. It also defines the different types of literals, operators, punctuators, and data types that are used in the Java language.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views

Computer Application 3

1. The document discusses various concepts related to values and data types in Java including character sets, tokens, keywords, identifiers, literals, operators, punctuators, data types, variables, and constants. 2. It explains that a character set defines recognizable characters, tokens are the smallest meaningful units, and keywords are reserved words with specific meanings. 3. It also defines the different types of literals, operators, punctuators, and data types that are used in the Java language.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Values and data types

Character Set: A character set is a defined list of characters that a language can
recognize. Java too has a set of characters that it can recognize. The name of Java
character set is Unicode (16 bits character coding system) that is based on ASCII.
ASCII (8 bits) stands for American Standard Code for Information Interchange. It
supports maximum 256 unique characters (alphabets, numbers and special characters).
Unicode supports 65536 unique characters. The first 256 characters of the Unicode
set are identical to the standard ASCII character set. Unicode is used to represent all the
characters found in different languages such as English, Hindi, Chinese, French, etc.

Tokens: The smallest individual unit in a program that is meaningful to the compiler.
There are five categories of tokens in java. These are -
1. Keywords syntax are: curly braces for code block ,
semicolon for the end of statement
2. Identifiers parantheses for parameters , and infix
3. Literals notation for expressions.
4. Operators
5. Punctuators / separators because it uses the c- style
For example: int marks = 98 ; syntax . which is the nobs
of the most programming
| | | | | language.
Keyword Identifier Operator Literal Punctuator

Keywords: Reserved words that have a specific meaning for the java compiler. Java is a
case sensitive language, all keywords are defined in lower case (small letter).
For example - int, double, public, if, for etc.

Identifiers: Names given to different parts of a program such as variable, methods,


objects, etc. Identifiers should be always meaningful. There are some rules for Identifiers-
 An identifier can consist of any combination of alphabets (upper and lower case),
digits, the underscore ( _ ) and the dollar ( $ ).
 An identifier cannot begin with a digit.
 An identifier cannot be a reserve word of Java.

For example:
my marks  Invalid ( due to space)
my.marks  Invalid ( due to dot)
myMarks  Valid
my_marks  Valid
1Marks  Invalid (due to begin with digit)
marks1  Valid
else  Invalid (due to reserve word)
Computer Applications Notes Volume I (Class IX) for ICSE examinations 2022 by Hem Sir Page 7
Literals: It is a value that remains fixed during the execution of a program. It is also
known as constants. There are six types of Literals in Java-

1. Integer Literals (numbers without decimal point) Example


a. Decimal Integer https://youtu.be/04QUJNuw6WE? 12  12
b. Octal Integer si=Nx2FTrWs_IuBBh95 014  12
c. Hexadecimal Integer 0XC  12
d. Binary Integer(Introduced in latest version of java only) 0b1100  12
2. Real Literals (floating point numbers with a decimal point)
a. Fractional form (For example- 12.31)
b. Exponent form (For example- 0.1231E+2 (0.1231 x 102 ) )  In this
example the part before E is known as mantissa and the part after E is
known as exponent.
3. Character Literals: Single character enclosed inside single quotes. For example- ‘A’,
‘@’, ‘5’, ‘\n’, ‘\u03B8’, etc.
A character that is preceded by a backslash (\) is known as Escape Sequence
character. All escape sequences are single character that has a special meaning to
the Java compiler. There are some examples of escape sequences-
Escape Sequence  Description
\n  new line character
\t  tab character
\\  backslash character
\”  double quote character
\’  single quote character
\r  carriage return (enter key)
\u(4 digit Hexadecimal)  character of specified Unicode.
4. String Literals: Zero or more alphanumeric characters enclosed inside double
quotes. For example- “c”, “ “, “abc”, “@123”, “Baby\’s day out”, etc.
5. Boolean Literals: There are two Boolean values- true and false.
6. Null Literal: Special kind of literal that is represented by null or \u0000 and refers
nothing or empty.

Operators: Predefined symbols that perform specific operations on its operands.

Operands are the variables or literals on which operator works. For example- in
the statement n = n + 5; =, + are operators and n, 5 are operands.
(We shall discuss operators in detail in chapter-5)

Computer Applications Notes Volume I (Class IX) for ICSE examinations 2022 by Hem Sir Page 8
Punctuators: Predefined Symbols which are used for grouping and separating the code.
Punctuators are-

Symbol Name Description / Uses


() Parenthesis Used with methods, grouping of expression, in
control structures- such as if(), switch(), etc.
{} Braces(curley brackets) To define a block of code, to initialize the arrays.
[] Square brackets Used with arrays.
; Semicolon Used to terminate the statements.
, Comma To separate variables or literals.
. Period (Member Used to access members of class /object /package.
operator)

Data Types: Data types are means to identify the type of data and associated operations of
handling it. The size of a variable and a constant are determined by data types.

Data types can be classified into two categories-

 Primitive data types: These are fundamental or built in data types and available
as an integral part of Java Programming language. There are following eight
primitive data types-
Type  Size  Description
byte 1 byte(8 bits) Integer in the range of -128 to 127
short 2 bytes(16 bits) Integer in the range of -32768 to 32767
int 4 bytes(32 bits) Integer in the range of -231 to 231-1
long 8 bytes(64 bits)  Integer in the range of -263 to 263-1
float 4 bytes(32 bits) Single-precision (up to 7 significant
decimal digits) floating point
double 8 bytes(64 bits)  Double-precision (up to 15 significant
decimal digits) floating point
char 2 bytes(16 bits) Single character, range of Unicode 0 – 65536
boolean 1 byte(8 bits) To represent true(1) or false(0)

 Non Primitive data types: These are derived from the primitive data types. So,
these are also called derived types, reference types or composite data types. Classes,
arrays etc. are the examples of reference data types.

Variable: A named location of memory to store data value. The value stored in a
variable can be changed any time.

Computer Applications Notes Volume I (Class IX) for ICSE examinations 2022 by Hem Sir Page 9
Declaring variables: A variable can be used in a java program only if it has been
declared. Syntax to declare variable-
data_type variable_name ;
For example- int marks ;
float principal, rate, time ;
Initialising variable: It means to assign (store) a value to the variable at the time of its
declaration. For example- int marks = 94 ;
float p = 5000.0f, r = 7.5f, t = 5.0f ;
Initialization at run time is known as dynamic initialization. Such as-
float perimeter = 2 * 3.14 * 6;
If we do not initialize the member variables, compiler automatically initializes using
default value. Default value for various type of variables are-
Data Type  Default value
byte  0
short  0
int  0
long  0L
float  0.0f
double  0.0d
char  ‘\u0000’
boolean  false
reference data type  ‘\u0000’ (null)
Constants: In Java, the keyword final can be used in a variable declaration to make a
variable as a constant (It means we cannot change the value of a variable once it has
been initialized).
Constant makes the code easier to understand, prevents any unintentional changes,
a change at one place reflects all automatically.
For identification, constants are generally declared in capital letter.
A complete example using variables and constant-
public class Circle
{
public static void main (String args[])
{
final double PI = 3.14 ; // constant
float radius = 6.5f ; // variable
double area = PI * radius * radius ; // calculating and initializing
System.out.println(“Area of Circle =” + area); // displaying area
}
}
Note : In same way you can practice for more programs with the help of your book.
Computer Applications Notes Volume I (Class IX) for ICSE examinations 2022 by Hem Sir Page 10

You might also like