3

someone explain what does the keyword strictfp mean in the class below?

public strictfp class Demo {
        public static void main(String[] args) {
                double d = 8e+307;
                /** affiche 4 * d /2 donc 2 * d */
                System.out.println(4 * d / 2);
                /** affiche 2 * d */
                System.out.println(2 * d);
        } 
}
hulk
  • 39
  • 1
  • 5
  • @Karthikeyan Vaithilingam I also find this [What is the strictfp modifier for? When would I consider using it?](http://www.jguru.com/faq/view.jsp?EID=17544) – hulk Jan 24 '16 at 08:09

1 Answers1

5

Java strictfp keyword ensures that you will get the same result on every platform if you perform operations in the floating-point variable.The strictfp keyword can be applied on methods, classes and interfaces.

strictfp class A{}//strictfp applied on class  
strictfp interface M{}//strictfp applied on interface  
class A{  
strictfp void m(){}//strictfp applied on method  
}  

The strictfp keyword cannot be applied on abstract methods, variables or constructors.

class B{  
strictfp abstract void m();//Illegal combination of modifiers  
}  
class B{  
strictfp int data=10;//modifier strictfp not allowed here  
}  
class B{  
strictfp B(){}//modifier strictfp not allowed here  
} 
gihan-maduranga
  • 4,381
  • 5
  • 41
  • 74
  • thnx but what does floating-point variable mean ? – hulk Jan 24 '16 at 08:08
  • 2
    @hulk, a floating point variable is a variable which can store numbers lik 2.6, 8.430, 0.086, and so on. Basically, it can store numbers which have decimals in them. – Box Box Box Box Jan 24 '16 at 08:22