strictfp Keyword In Java

In this tutorial, we will be studying the “strictfp” keyword in Java. Also, we will be looking forward to where is it basically used.

We will be further understanding of how it gets implemented and also we will be seeing an example based on it.

strictfp Keyword In Java

First of all, strictfp keyword is basically used for restricting decimal points calculations in Java.

Also, Ensuring the production of the same output in different systems.

It should be noted that when a class is declared with the above keyword, then all the methods and types declared in the class are implicitly strictfp.

If you don’t use strictfp, the Java virtual machine would be having no bounds and it would take extra precision available.

Without that modifier, floating points used in the functions might behave unordered mannerly in other platform-dependent systems.

With it, you can predict how your floating points will behave regardless of the underlying platform the java virtual machine is running.

If repeatability is essential to be in the program, the strictfp modifier can be used to ensure that overflow condition.

Without the strictfp modifier, intermediate results may use a larger exponent range wherever it is possible.

Example Java program of strictfp Keyword

public class Sfc 
{ 
    public strictfp double sum() 
    { 
  	      double num1 = 10e+10; 
  
 	       double num2 = 6e+08; 
  
 	       return (num1+num2); 
  
    } 
  
    public static strictfp void main(String[] args) 
    { 
        Sfc s = new Sfc(); 
  
        System.out.println(s.sum()); 
    } 
}

After the successful compilation of the above Program, we will be getting the output as below:

Strictfp Keyword In Java

Also, read:

Leave a Reply

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