Ans. ASCII is a 7-bit character set that can represent 27 = 128 characters.
false
and "false"
?Ans. false
is a boolean literal representing a false value, while "false"
is a string literal representing the text "false".
Ans. A character set is a defined list of characters that a language can recognize. It includes:
Ans. An escape sequence is a set of characters starting with a backslash (\
) that has a special meaning to the Java compiler. Examples include \n
for a new line, \'
for a single quote, and \t
for a tab.
Ans. The escape sequence for a horizontal tab is '\t'
, and for a new line, it is '\n'
.
int res = 'A';
What is the value of res
?Ans. The value of res
is 65, as 'A' corresponds to 65 in ASCII.
System.out.println("Incredible" + "\n" + "world");
Ans.
Incredible world
Ans. All characters in a Java program are grouped into symbols called tokens. A computer program consists of statements, each composed of various components. Each component of a programming statement is referred to as a token. Keywords, identifiers, and literals are examples of tokens in Java.
Ans. Keywords are reserved words that the Java compiler reserves for its own use, meaning they cannot be used as names for variables or methods. They have special meanings in the Java compiler. For example, void
and public
are keywords.
Ans. Identifiers are names used in a program to label different components such as variables, methods, classes, and objects.
Ans. Literals are sequences of characters that represent constant values in a program. They are stored in variables and can consist of digits, letters, and other characters.
Ans. Primitive data types are the fundamental data types of Java programming language. They are also called Intrinsic
or built-in
data types because they are the part of the language. There are 8 primitive data types in Java: byte
, short
, int
, long
, float
, double
, char
, and boolean
.
char
, double
, byte
.Ans. byte
, char
, double
.
Ans. The two basic kinds of data types in Java are primitive data types (e.g., int
and char
) and reference data types.
char
and int
data types.Ans. The char
data type occupies 2 bytes, and the int
data type occupies 4 bytes.
Ans. A boolean literal represents a value of either true
or false
, and it uses 1 byte of storage. A character literal, on the other hand, represents a single character enclosed in single quotes, such as 'G'
, and it uses 2 bytes of storage.
Ans. Primitive data types are the fundamental data types in Java, like int
and char
. In contrast, composite (or non-primitive) data types, such as arrays, are derived from primitive data types and can hold multiple values.
int
and float
?Ans. The default value of int
is 0, and the default value of float
is 0.0f.
Ans. The 64-bit integer data type in Java is long
, and the data type that represents a single 16-bit Unicode character is char
.
Ans. A floating point literal requires 4 bytes of storage, while a double literal requires 8 bytes of storage.
Ans.
_
), and dollar signs ($
).Total
and total
are different identifierschar
, arrays
, int
, classes
.Ans.
char
- Primitive data typearrays
- Non-primitive data typeint
- Primitive data typeclasses
- Non-primitive data typecounter
and Counter
?Ans. Yes, Java is case-sensitive, so counter
and Counter
would be recognized as two distinct identifiers.
Ans. Primitive data type: int
and long
. Composite data type: class
and array
.