Java Basic
- Which of the following is good coding practice to determine oddity?
i)public boolean Calc(int n)
{
return (n & 1)!= 0;
}
ii)public boolen Calc(int n)
{
return n % 2 == 1;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Arithmetic and logical operations are much faster than division and multiplication.
- What causes the program to exit abruptly and hence its usage should be minimalistic?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In case of exit, the program exits abruptly hence would never be able to debug the root cause of the issue.
- What causes the program to exit abruptly and hence its usage should be minimalistic?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In case of exit, the program exits abruptly hence would never be able to debug the root cause of the issue.
- What data structure should be used when number of elements is fixed?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Array list has variable size. Array is stored in contiguous memory. Hence, reading is faster. Also, array is memory efficient.
- What should the return type of method where there is no return value?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Returning Empty collection is a good practice. It eliminates chances of unhandled null pointer exceptions.