Value and Types

Qus. What is Character Set?

Ans. A character set is a set of alphabets, letters and some special characters that are valid in Java language.

Qus. What are Tokens?

Token is the fundamental building block of a program that represents a single element of a programming language.

Qus. State the difference between token and identifier

Ans. Token is the fundamental building block of a program that represents a single element of a programming language. Identifier on the other hand is a token that is used to name different parts of a program.

Qus: What are keywords? Give an example.

Ans: A keyword is a reserved word that has a special significance to the compiler and cannot be used anywhere else other than what it is intended for. Example- for, if, else, while etc.

Qus. What are identifiers?

Ans. Identifiers are the names of variables, methods, classes, packages and interfaces.

Qus. What are Identifiers? State the rules while using Identifiers

Ans. Identifiers are the names of variables, methods, classes, packages and interfaces. While using identifiers the following set of rules are to be kept in mind.

1. It can have any alphabet (capital or small), digits, underscore and dollar sign characters. For example, a, b, cat, mat123, cost_price, Topaz$ are all example of valid identifier.

2. It should not begin with digits or should not contain any special character. For example 2ab, ab#c, top@, etc, are invalid identifiers as it either begins with a digit or contain special characters (like #, @).

3. It cannot have a space between it. For example, simple interest or selling price are invalid identifiers as it contains a space.

4. It must not be a keyword. For example, for, while, do are invalid identifiers as they are keywords and are assigned some special function for the language.

5. It can be of any length. Even though Java gives you the flexibility to provide a huge length for an identifier a very long name is impractical and difficult to manage.

Qus. What is a literal?

Ans. Literal is a constant value that can be assigned to a variable.

Qus. What is a literal? What are the different types of literals available in Java?

Ans. Literal is a constant value that can be assigned to a variable. The different types of literals in Java are:

1. Integer-literal or Fixed point-literal

2. Floating point-literal

3. Boolean-literal

4. Character-literal

5. String-literal

6. Null-literal

7. Class literal

Qus. State the difference between a boolean literal and a character literal. 

Ans. A boolean literal may be either true or false and character literal are always enclosed within single quotes.

Qus. How are Decimal, Octal and Hexadecimal integer literals represented in Java?

Ans. Decimal Integer Literals uses digits from 0 to 9 (i.e. 10 digits this is what you normally use to represent numbers in mathematics) but should not be prefixed with 0. + (or no symbol) or – may be used to represent positive or negative numbers respectively. Thus -12, 56, or +75 may be considered to be Decimal Integer Literal.

Octal Integer Literals uses digits from 0 to 7 (i.e. 8 digits) and should be prefixed with 0. + (or no symbol) or – may be used to represent positive or negative numbers respectively. Thus -012, 056, or +075 may be considered to be Octal Integer Literal.

Hexadecimal Integer Literals uses digits from 0 to 9 and alphabets from A (or a) to F (or f) representing 10 to 15 (i.e. 16 numbers) and should be prefixed with 0x or 0X. + (or no symbol) used to represent positive numbers or – may be used to represent negative numbers. Thus -0x12, 0X56, or +0A7F5 may be considered to be Hexadecimal Integer Literal.

Qus. What are the different punctuators available in Java?

Ans. There are 9 punctuators available in Java.

They are: ( ) { } [ ] ; , . 

Qus. What are separators?

Ans. Separators are special symbols used to separate statements, data elements or mark blocks in Java and is therefore also called separators. There are 9 punctuators available in Java. They are: ( ) { } [ ] ; , . 

Qus. What are the three types of integer literals that can be represented in Java?

Ans. Ans. Decimal Integer Literal, Octal Integer Literal and Hexadecimal Integer Literal.

Qus. What is an operator? How is the classification of operators based upon?

Ans. An operator is a specialised symbol that performs a specific kind of evaluation on one, two, or three operands, and produces a result. Operators in Java can be categorized based on two criteria: • Forms of operators • Types of operators