Modifier | Class | Interface | Inner Class | Inner Interface | Variable | Method | Constructor | Free-Floating Block |
public | yes | yes | yes | yes | yes | yes | yes | no |
protected | no | no | yes | yes | yes | yes | yes | no |
none or package or default | yes | yes | yes | yes | yes | yes | yes | yes |
private | no | no | yes | yes | yes | yes | yes | no |
final | yes | no | yes | no | yes | yes | no | no |
abstract | yes | yes/no | yes | yes/no | no | yes | no | no |
static | no | no | yes | yes | yes | yes | no | yes |
native | no | no | no | no | no | yes | no | no |
transient | no | no | no | no | yes | no | no | no |
volatile | no | no | no | no | yes | no | no | no |
synchronized | no | no | no | no | no | yes | no | yes |
strictfp | yes | yes | yes | yes | no | yes | yes | no |
Points:
- all access modifiers can be used to classes and members except for protected and private which cannot be used to outer classes and interfaces
- free-floating block cannot have access modifiers. it can only use static or synchronized
- constructors can only use access modifiers and strictfp
- native is only for methods
- transient and volatile are only for variables. Transient indicates that it is not serializable. Volatile indicates that it can be modified simultaneously by many threads.
- synchronized can only be used on methods or free-floating blocks
- strictfp can't be used on variables or free-floating blocks
Using strictfp ensures that you get the same result of floating-point expressions across multiple platforms. But it may also result to overflow or underflow hence the expression, "Write-Once-Get-Equally-Wrong-Results-Everywhere". If you don't use strictfp, JVM can calculate floating-point expressions however it want and thus could produce more accurate results.
Nice post. Very good write-up.
ReplyDelete
ReplyDeleteNice and Interesting Article.
Next Visit Our Website