Saturday, April 27, 2019

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 calculation precision and greater range of values than the Java specification requires, that may produce different output on different platforms. Using strictfp guarantees that results of floating-point calculations are identical on all platforms.

Usage of strictfp in Java

The strictfp modifier was introduced in Java with JVM 1.2 and is available for use on all currently updated Java Virtual Machines.

Floating-point calculations may vary on different platforms because of the precision used like the standard 32 bit precision, 64 bit precision, 80-bit double extended on x86 or x86-64 platforms. strictfp is used when a programmer might need every platform to have precisely the same floating-point behaviour, even on platforms that could handle greater precision.

strictfp modifier in Java can be used with-

strictfp can not be used with-

strictfp Java 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.

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

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

>>>Return to Java Basics Tutorial Page


Related Topics

  1. final Keyword in Java With Examples
  2. static Keyword in Java With Examples
  3. this Keyword in Java With Examples
  4. super Keyword in Java With Examples
  5. Core Java Basics Interview Questions

You may also like-

  1. abstract Class in Java
  2. static import in Java
  3. Automatic numeric type promotion in Java
  4. BigDecimal in Java
  5. Check if given strings are anagram or not
  6. Treemap in Java
  7. Deadlock in Java multi-threading
  8. CountDownLatch in Java concurrency

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