strictfp
?
strictfp
forces floating points to adhere to the IEEE 754 standard.
In Java, the strictfp keyword has one primary purpose:
strictfp
, some CPUs (e.g., x86) can use extended precision (80-bit registers), which may cause slightly different results on different platforms.strictfp
, you ensure consistency across all JVMs, regardless of underlying hardware.strictfp
eliminates those subtle differences, making your numeric output reproducible.strictfp
is used to guarantee repeatable results.Location | Can Use strictfp ? |
---|---|
Class/Interface | ✅ Yes |
Method | ✅ Yes |
Variable | ❌ No |
Constructor | ❌ No |
strictfp
modify?var-args
syntax?
var-args
is to allow you to create methods that can take a variable number of arguments.getSalary("name", age);
Employee getSalary (String name, int age) {}
static int sum (int ... numbers){ int total = 0; for (int i = 0; i &t; numbers.length; i++) total += numbers [i]; return total; }
void
, makes it a regular method, not a constructor.public class MyClass { // This is a constructor (no return type) public MyClass() { System.out.println("Constructor called"); } // This is a method (has a return type, so it's not a constructor) public void MyClass() { System.out.println("This is a method, not a constructor!"); } }
MyClass obj = new MyClass();
Constructor called⚠️ The method void MyClass() is not a constructor, even though it looks similar, it will never be called automatically during object creation.