Java Basic


  1. 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;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Arithmetic and logical operations are much faster than division and multiplication.


  1. What causes the program to exit abruptly and hence its usage should be minimalistic?











  1. 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.



  1. What causes the program to exit abruptly and hence its usage should be minimalistic?











  1. 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.


  1. What data structure should be used when number of elements is fixed?











  1. 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.



  1. What should the return type of method where there is no return value?











  1. 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.