The strictfp keyword in java

Today while I was preparing for OCP, I’ve come to meet a new non access modifier keyword called strictfp. Simply the keyword Strictfp ensures that you retrieve the same results of the floating point calculations on every platform X86 or AMD64. in case of not utilizing the keyword strictfp, the JVM implementation you use will result in using extra precision where its feasible. This keyword is available in Java since version 1.2. Furthermore, you can declare with this keywords;

Interfaces 

public strictfp class MyClass {}

Classes

public strictfp interface MyInterface{}

Methods

public class MyCalculationClass(){
	public strictfp float calculation(float a, float b){
        return (a*b);
    }
}

References

http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.4

https://en.wikipedia.org/wiki/Strictfp

http://stackoverflow.com/questions/517915/when-should-i-use-the-strictfp-keyword-in-java

Leave a Reply

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