Java strictfp Keyword
Example
Use strictfp on a method that does a floating-point calculation:
public class Main {
strictfp static double divide(double a, double b) {
return a / b;
}
public static void main(String[] args) {
System.out.println(divide(10.0, 4.0));
}
}
Definition and Usage
The strictfp keyword is a modifier for classes, interfaces and methods. It makes calculations with float and double values follow the same strict rules on all computers, so the result is always exactly the same.
Since Java 17, all floating-point calculations are strict, so strictfp is not needed any more, and the compiler gives a warning if you use it.
Related Pages
Read more about modifiers in our Java Modifiers Tutorial.