Java_Syntax Flashcards

1
Q

What are the different data types supported in switch: case in Java?

A

int, char, byte, short, string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Operators precedence in Java.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the signed and unsigned shift of bits operators in Java?

A
// Unsigned shift operation >>>
        // it adds '0's to MSB instead of
        // 1's when a signed shift done >>
        int iii = -8;
        iii = iii >>> 1;

        System.out.println("Unsigned shift result of iii: " + iii);

        int jjj = -8;
        jjj = jjj >> 1;

        System.out.println("Signed shift result of jjj: " + jjj);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Provide an example of using a ternary operator in Java?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Provide an example of enum in Java.

A
  • enums provide compile-time check
  • enums in Java can be used in many ways, to fetch the name of the element, the value of the element.
  • Check below example:
// Enums
        Days today = Days.Monday;
        switch(today){
            case Monday:
                String theDay = Days.Monday.name();
                Days theUserDay = Days.valueOf("Monday");
                System.out.println("It's " + theDay + "!!");
                System.out.println("It's " + theUserDay + "!!");
                break;
            default:
                System.out.println("Default days");
        }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly