CHAPTER 2 - Values and Data Types - NEW - PDF PDF
CHAPTER 2 - Values and Data Types - NEW - PDF PDF
For example,
2) Multiple line comment: To create a multiple line comment place ‘/* ‘ at the beginning of the
line and place ‘*/’ after one or more than one lines. For example,
/* Write a description of class xyz here. Enter time and print in words @author (xyz)
@version (a version number or a date) */
3) Documentary comment:- These are long comments given on top of program which starts
with ‘\**’ symbol and ends with ‘*/’ and every statement will start with a ‘*’ symbol
between first and last statement.
For eg:
/** Write a program to check
*whether the number is
*even or odd */
Q6. Explain escape sequences in Java.
Ans: Escape sequences are used to control printed output. The characters preceded by a
backslash(\) are called escape sequences .
Character Escape
Sequence
Backslash \\
Backspace \b
Carriage return \r
Double quote \”
Horizontal tab \t
Newline \n
EXAMPLE : System.out.println(“The school will remain close for tomorrow.\n Students are
suppose to come by next week.”);
Q7. Define constants or literals. Give example for all the primitive data types.
Ans: Constants are data values that never change their values during program execution.
Examples: ( )
{}
[]
;
,
.
Q9. What are operators? Explain in detail.
Ans: Operators are special symbols that perform a particular function on operands.
Example:
a = b+c;
In above expression ‘+’ is the operator and (a , b ,c) are operands.
3. Instance variable: The variables are declared inside a class but not within a function.
They are created when a number of objects are created from the same class. Each object
has its own copy of instance variable.
4. Static variable: Variable that have ‘static’ modifiers in their declaration are called static
variable. Static variables are associated with the class rather than any object. That is, all
the objects share the single copy of the variable.
Q14. What are the default values and size of data types in Java ?
short 0 2 byte
int 0 4 byte
long 0L 8 byte
DATA TYPES
STRING
ARRAY
Numeric
BOOLEAN
Character
float double
Integer