Java Strictfp Keyword

Posted By : Surbhi Gupta | 31-Oct-2017

Introduction of Strictfp Keyword

1. Strictfp is a keyword in java utilized for limiting coasting point computations and guaranteeing same results on each stage while performing operations in the drifting point variable.

2.Floating point figurings are stage subordinate i.e. diverse output(floating-point esteems) is accomplished when a class document is keep running on various platforms(16/32/64 bit processors). To settle this sorts of issue, strictfp watchword was presented in JDK 1.2 form by following IEEE 754 measures for gliding point counts.

 

Important points:

1.strictfp modifier is used with classes, interfaces and methods only.

strictfp class Test
{   
    // all concrete methods here are
    // implicitly strictfp.    
}
strictfp interface Test
{   
    // all  methods here becomes implicitly 
    // strictfp when used during inheritance.    
}
class Car
{  
    // strictfp applied on a concrete method 
    strictfp void calculateSpeed(){}
}  

2. At the point when a class or an interface is proclaimed with strictfp modifier, at that point all strategies announced in the class/interface, and all settled sorts pronounced in the class, are verifiably strictfp.

3. strictfp cannot be used with abstract methods. However, it can be used with abstract classes/interfaces.

4. Since methods of an interface are implicitly abstract, strictfp cannot be used with any method inside an interface.

strictfp interface Test 
{
    double sum();
    strictfp double mul(); // compile-time error here
}

 

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  
}        
 

About Author

Author Image
Surbhi Gupta

Surbhi is a Java Developer and a simple ,straightforward, friendly person. She loves to work in a challenging job.

Request for Proposal

Name is required

Comment is required

Sending message..