Tokens and Values and Data Types
Tokens and Values and Data Types
Question 1
Answer
An escape sequence is a set of characters that has a special meaning to the Java compiler. In
the escape sequence, a character is preceded by a backslash (\). Some examples of escape
sequences are \n, \' and \t.
Question 2
Answer
(1 + 2 * 2) / 2 + 2 ⇒ (1 + 4) / 2 + 2
⇒ (5) / 2 + 2
⇒2+2
⇒4
Question 3
Answer
All characters in a Java program are grouped into symbols called Tokens. As you know, a
computer program consists of a set of instructions called statements. A statement is composed
of various components. Each individual component of a programming statement is referred to
as a token. Keywords, identifiers, Operators, Separators and literals are three tokens in
Java.
Question 4
1|Page
ISA – TOKENS & VALUES and DATA TYPES
Answer
Keywords are reserved words that have a special meaning to the Java compiler. As Java
compiler reserves these words for its own use so they are not available as names for variables
or methods.
Question 5
Answer
Question 6
Answer
Identifiers are used to name different parts of a program such as variables, methods, classes,
objects, etc. Three identifier formation rules are:
Question 7
Explain the following statement — "In Java, total, Total, ToTaL, and TOTAL are all
different identifiers."
Answer
2|Page
ISA – TOKENS & VALUES and DATA TYPES
Java is a case sensitive language. total, Total, ToTaL, and TOTAL have the same set of
letters but they differ in the case of these letters. Therefore, Java considers each of them as a
different identifier.
Question 8
How would you print characters like \, ' and " in Java?
Answer
We can print characters like \, ' and " using escape sequences i.e. preceding it with a
backslash (\) symbol.
Question 9
Answer
Token Identifier
Answer
3|Page
ISA – TOKENS & VALUES and DATA TYPES
Keyword Identifier
Answer
Answer
4|Page
ISA – TOKENS & VALUES and DATA TYPES
Question 10
Answer
"A" is a string literal of length 1 containing the letter A in uppercase whereas 'A' is a
character literal having value of A in uppercase.
Question 11
Answer
Primitive data types are fundamental data types that are an integral part of the Java language
and are used to declare a variable.
Question 12
Answer
byte 1
short 2
int 4
5|Page
ISA – TOKENS & VALUES and DATA TYPES
long 8
float 4
double 8
char 2
boolean 1
Question 13
Which integer and floating point data types take up the same number of bits in
computer's memory?
Answer
Both, int and float take up 32 bits in memory. Similarly, both long and double take up 64 bits
in memory.
Question 14
What is variable initialisation in Java? What are the default values of the following type
of variables:
short, int, long, float, double, and char.
Answer
Variable initialisation means assigning value to a variable for the first time. Below are the
default values of the different data types:
6|Page
ISA – TOKENS & VALUES and DATA TYPES
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
abstract Indicates the class or method that follows this keyword is abstract and
that will have to be implemented by a subclass.
7|Page
ISA – TOKENS & VALUES and DATA TYPES
continue It helps to take control outside the loop and continue to the next iteration.
default Defines the "block of code" that will execute by default in a Switch
statement.
final Defines a variable which will hold constant values or a method that
cannot be overridden.
finally Defines the finally block that executes after the try-catch block
irrespective of whether the exception was caught or not.
8|Page
ISA – TOKENS & VALUES and DATA TYPES
private Indicates private access specified which means a variable or method can
be accessed only by the class in which it is declared.
return Return is used to send back the value of a method to the calling method.
It also is used to return the control to the calling method.
static The static keyword indicates the method or a variable is static and cannot
9|Page
ISA – TOKENS & VALUES and DATA TYPES
be instantiated.
strictfp The keyword strictfp restricts the rounding and precision of floating point
values calculation. It ensures portability.
switch Indicates a Switch statement that tests a condition and executes multiple
cases depending on the test value.
transient Specifies transient variable that is not part of the persistent state of an
object.
try Try keywords start a block that contains code that might raise exceptions.
volatile Used to define variables that are not stored in Main Memory. They can
be changed asynchronously.
true, false and The words "true, false, null" are literals. Still, we cannot use them as
10 | P a g e
ISA – TOKENS & VALUES and DATA TYPES
11 | P a g e