Java Strictfp Keyword

 

We use the strictfp keyword to make sure that same results will be obtained when an operation is performed on the floating point variable on every platform. As the precision of a floating point number may differ from platform to platform therefore, the strictfp keyword is introduced by Java so that same results will be obtained whenever an operation is performed on floating point number.

 

Legal code for strictfp keyword:

In Java programming language we can apply the strictfp keyword to classes, interfaces and methods. Consider the following statements in which we applied the strictfp keyword to class first then to interface and then to method:

  1. strictfp class Q {}
  2. strictfp interface W {}
  3. class Q {strictfp void s () {}}

 

Illegal code for strictfp keyword:

In java programming language we cannot apply the strict keyword to abstract methods, variables and constructors. The following statements are hence illegal to write for strictfp in Java programming language:

  1. class S { strictfp abstract void a (); }
  2. class S { strictfp int id = 23; }
  3. class S { strictfp S () {} }