Constants of Short class in Java

Some of the constants of Short class.

1. Short.BYTES

Syntax:

int java.lang.Short.BYTES: 2

The number of bytes is used to represent a short value in two'scomplement binary form. 

Approach

Java

public class ShortBYTES {
    public static void main(String[] args) {

        System.out.println(Short.BYTES);
    }
}

Output:

2


2. Short.MAX_VALUE

Syntax:

short java.lang.Short.MAX_VALUE: 32767

A constant holding the maximum value a short can have, 2^15-1.

Approach

Java

public class ShortMAX_VALUE {
    public static void main(String[] args) {

        System.out.println(Short.MAX_VALUE);
    }
}

Output:

32767


3. Short.MIN_VALUE

Syntax:

short java.lang.Short.MIN_VALUE: -32768

A constant holding the minimum value a short can have, -2^15.

Approach

Java

public class ShortMIN_VALUE {
    public static void main(String[] args) {

        System.out.println(Short.MIN_VALUE);
    }
}

Output:

-32768


4. Short.SIZE

Syntax:

int java.lang.Short.SIZE: 16

The number of bits used to represent a short value in two'scomplement binary form.

Approach

Java

public class ShortSIZE {
    public static void main(String[] args) {

        System.out.println(Short.SIZE);
    }
}

Output:

16

No comments:

Post a Comment