Basic Datatypes
- What is the output of this program?
public class increment {
public static void main(String args[]) {
int a = 5;
System.out.print(++a * 6);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Operator ++ has more preference than *, thus a becomes 6 and when multiplied by 6 gives 36.
output: 36
- What will be the output of these statement?
class output {
public static void main(String args[])
{
double p, q, r;
p = 3.0/0;
q = 0/4.0;
r = 0/0.0;
System.out.println(p);
System.out.println(q);
System.out.println(r);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
For floating point literals, we have constant value to represent (10/0.0) infinity either positive or negative and also have NaN (not a number for undefined like 0/0.0), but for the integral type, we don’t have any constant that’s why we get an arithmetic exception.
- Which of these literals can be contained in float data type variable?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Range of float data type is -(3.4e38) To +(3.4e38)
- How is Date stored in database?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
java.sql.Date is the datatype of Date stored in database.
- What is the range of byte data type in Java?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Byte occupies 8 bits in memory. We use the formula - 2(bits-1) to calculate the negative range, and we use 2(bits-1)–1 for the positive range.
So byte range is from - 2(8-1) to 2(8-1) -1 which is -128 to 127.