A modifier called strictfp, which stands for strict floating-point, was added to Java version 1.2 as opposed to the base version. When executing operations on the floating-point variable, it is utilised in Java to restrict floating-point calculations and guarantee consistent outcomes across platforms.
Floating-point calculations are platform-dependent, which means that different output (floating-point values) are obtained when a class file is run on different platforms (16/32/64 bit processors). To address this issue, the strictfp keyword was introduced in JDK 1.2 by adhering to IEEE 754 standards for floating-point calculations.
strictfp class Main{ // Here, every concrete method is implicitly strictfp. }
strictfp interface Main{ // Here, every method becomes implicit. // Using strictfp during inheritance }
strictfp interface Main{ double add(); strictfp double divide(); // C.T Error }
class Main{ strictfp void Add(){ //strictfp applied on method } }
// Java example of strictfp keyword
class Main { public strictfp double add(){ double a = 5e+05; double b = 3e+08; return a + b; } public static void main(String[] args){ Main main = new Main(); System.out.println(main.add()); } }
Output:
3.005E8
The strictfp keyword cannot be used on constructors, variables, or abstract methods.
class Main{ strictfp abstract void Add(){ } //strictfp applied on method }
class Main{ strictfp int data=10; //Modifier strictfp is not permitted here }
class Main{ strictfp int add(){} //Modifier strictfp is not permitted here }
Post your comment