Java long keywordThe Java long keyword is a primitive data type. It is used to declare variables. It can also be used with methods. It can hold a 64-bit two's complement integer. Points to remember
Examples of Java long keywordExample 1Let's see an example to use long data type with positive and negative value. Output: num1: 10 num2: -10 Example 2Let's see an example to check whether the long data type holds decimal value. Output: error: incompatible types: possible lossy conversion from double to long Example 3Let's see an example to check whether the long data type holds float value. Output: error: incompatible types: possible lossy conversion from float to long Example 4Let's see an example to check whether the long data type holds char value. In such case, the compiler typecast the character implicitly to long type and returns the corresponding ASCII value. Output: num: 97 Example 5In this example, long data type holds the minimum and maximum value. Output: min: -9223372036854775808 max: 9223372036854775807 Example 6Let's create a method that returns a long type value. Output: 10
Next TopicJava Keywords
|