Saturday, 6 June 2015

strictfp in Java

strictfp is a keyword in Java that restricts floating-point calculations to ensure portability.
As different platforms can handle, different floating-point calculations precisions and greater range of values than the java specification requires, which may produce different output on different platforms.

Prior to JVM 1.2, floating-point calculations were strict; which meant, all intermediate floating-point results were represented as IEEE single or double precisions only. As a consequence, errors of calculation (round-off errors), overflows and underflows would occur with greater frequency than in architectures which did intermediate calculations in greater precision.

Since JVM 1.2, intermediate computations are not limited to the standard 32 bit and 64 bit precisions. On platforms that can handle other representations e.g. 80-bit double extended on x86 or x86-64 platforms, those representations can be used, helping to prevent round-off errors and overflows, thereby increasing precision.

Usage of strictfp

The strictfp command was introduced into Java with JVM 1.2 and is available for use on all currently updated Java VMs. strictfp is used, in case, where a programmer might need every platform to have precisely the same floating-point behaviour, even on platforms that could handle greater precision.

strictfp can be used with

Example

strictfp class StrictfpDemo {

    float f = 9.678f;
    
    strictfp public void displayValue()
    {
        System.out.println(f);
    }

 public static void main(String[] args) {
  StrictfpDemo strictfpDemo = new StrictfpDemo();
  strictfpDemo.displayValue();

 }
}

It can be seen in the program how strictfp modifier is used with the class and the method.

strictfp can not be used with

That's all for this topic strictfp in Java. If you have any doubt or any suggestions to make please drop a comment. Thanks!

Reference:http://en.wikipedia.org/wiki/Strictfp


Related Topics

  1. final in Java
  2. static in Java
  3. this in Java
  4. super in Java
  5. Core Java basics interview questions

You may also like -

>>>Go to Java Basics page

1 comment:

  1. Thanks for providing this informative information you may also refer.
    http://www.s4techno.com/blog/2016/07/31/interview-quetions-of-java/

    ReplyDelete