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-
- classes even abstract classes
- interfaces
- methods
strictfp can not be used with-
- abstract methods
- constructors
- variables
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
You may also like-
Thanks for providing this informative information you may also refer.
ReplyDeletehttp://www.s4techno.com/blog/2016/07/31/interview-quetions-of-java/