Have a Question?

If you have any question you can ask below or enter what you are looking for!

What is Strictfp modifier in Java?

What is Strictfp modifier in Java?
What is Strictfp modifier in Java?

What is Strictfp modifier in Java?

What is Strictfp modifier in Java?
  • Introduce in 1.2 version.
  • We can declare Strictfp for classes and methods but not for variables.
  • By using the strictfp keyword, we can ensure that floating point operations take place precisely.
  • Usually, the result of floating point arithmetic is varied from platform to platform. If we want platform independent result for floating point arithmetic then we should go for strictfp modifiers.
  • If a method declared as strictfp all floating point calculation in that method has to follow IEEE754 standard. So that we will get platform independent result.
  • Abstract modifier never talks about implementation whereas strictfp method always talks about implementation hence abstract-strictfp combination is illegal for methods.
  • If a class declared as strictfp then every floating point calculation present in every concrete method has to follow IEEE 754 standard so that we will platform independent result.
  • We can declare abstract-strictfp combination for classes i.e. Abstract-strictfp combination is legal for classes but illegal for the method.
  • Strictfp ensures that you get exactly the same results from your floating point calculations on every platform. If you don’t use strictfp, the JVM implementation is free to use extra precision where available.
  • strictfp cannot be applied for constructors.
  • If an interface or class is declared with strictfp, then all methods and nested types within that interface or class are implicitly strictfp.
  • strictfp cannot be applied for interface methods.
  • The precision may differ from platform to platform that is why java programming language has provided the strictfp keyword so that you get the same result on every platform. So, now you have better control over the floating-point arithmetic.

Leave a Reply

Your email address will not be published. Required fields are marked *