Thursday, February 3, 2022

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 And Answers

You may also like-

  1. Java Abstract Class and Abstract Method
  2. static Import in Java With Examples
  3. Java Automatic Numeric Type Promotion
  4. BigDecimal in Java With Examples
  5. Check Given Strings Anagram or Not Java Program
  6. TreeMap in Java With Examples
  7. Deadlock in Java Multi-Threading
  8. Java CountDownLatch With Examples

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