Chapter – 3.
Values and Types
1. ASCII value of alphabets :
A–Z 65 – 90
a–z 97 – 122
blank space 32
2. What are escape sequences?
These are some non-graphic characters which are used as commands to direct the cursor
while printing.
eg : \ t – to leave a tab space horizontally
\ n – to start a new line
\ \ – to print backslash
\ ‟ – to print single quote
\ ” – to print double quote
3. What are Tokens? Explain briefly.
A token is defined as each individual component of a java program. The various types of
tokens are:
(i) Literals
(ii) Identifiers
(iii) Assignments
(iv) Punctuators
(v) Separators
(vi) Operators
(vii) Keywords
(i) Literals – These are constants which remain fixed throughout the execution of the program.
Types of literals are :
a) Integer literal – numbers without decimal point. eg: 14, 5
b) Real literal – numbers with decimal point. eg: 14.5, 5.6
c) Character literal – Single character enclosed within single quotes. eg: „a‟, „8‟, „$‟
d) String literal – Single character or a group of characters enclosed within double quotes.
eg: “abc”, “345”, “$”
e) Boolean literal – Special literals which are represented by true or false. They are never
enclosed within quotes. eg: true, false
f) Null literal – it is represented as null, and is used to initialise an object or reference
variable.
(ii) Identifiers - These are used to represent a function name, class name or a variable. A variable
is represented by its data type.
int a = 10 Literal
Assignment operator
Identifier
Data type
(iii) Assignment - refers to storing a value in a variables using „ = ‟ symbol. Here, the symbol „ = ‟
acts as an assignment operator.
(iv) Punctuators – They are the punctuation signs used as special characters in java.
eg - ? . ;
(v) Separators – They are the special characters in java which are used to separate the variables
or the characters.
eg - , [ ] { } ( )
(vi) Operators – These are the symbols or signs used to specify the operations to be performed in
a java expression or statement.
eg – Arithmetical operators – + , - , / , *
Relational operators – < , > , == , !=
Logical operators – && , || , !
(vii) Keywords – They are reserved words that carry special meaning for the system compiler.
eg – class, public
4. What is a data type ?
Data types are the types of data assigned to a variable for storage, to ensure optimum
utilisation of memory space.
eg – int, char
5. Difference between Primitive and Non-primitive data types ?
Primitive Non-primitive
1. These are built-in data types 1. These are collection of primitive
data types
2. These are independent 2. These are dependent on primitive
data types
3. eg – int, char, double 3. eg – class, array, interface
6. Memory allocation of data types.
Data type In Bits In Bytes
byte 8 1
short 16 2
int 32 4
long 64 8
float 32 4
double 64 8
char 16 2
String > 16 >2
7. Difference between Declaration and Initialization ?
Declaration Initialization
1. declares the type of a variable 1. assigns or stores a specific value
to a variable
2. eg – int a; 2. eg – a = 5;
8. Difference between Static initialization and Dynamic initialization ?
Static initialization Dynamic initialization
1. A value is directly stored into 1. A variable is initialised during run
a variable time
2. eg – a = 10 ; 2. eg – c=a+b;
9. Difference between Arithmetic expression and Arithmetic statement ?
Arithmetic expression Arithmetic statement
1. A set of variables, constants 1. An arithmetic expression assigned
and arithmetic operators to a variable
2. eg – a*b+8 2. eg – m=a*b+8;
10. Difference between Pure expression and Impure expression ?
Pure expression Impure expression
1. where all the variables and 1. where the variables and constants
constants are of the same data are of different data type
type
2. eg – int a + int b 2. eg – int a + double b
11. What is Type Conversion ? Explain the two types of conversion with example.
(Refer to the solved Q&A in the text book exercise)
______________________