Project Management Professional: Core Java Interview Questions!

Tuesday, July 21, 2020

Core Java Interview Questions!


12.Difference between final and effectively final ? Why is effectively final even required ?

Ans. Final variable means a variable that has been declared final and hence cannot be de referenced after initialization. Effective final means a variable that has not been declared final but haven't been reassigned the value after initialization.


First is the regulation that restricts the reassignment and will raise a compilation error if we try to do so. Second is the outcome without the restriction.


Effective Final is the eventual treatment of the variable that is required for many features. For eq - Java 8 requires that local variables referenced from a lambda expression must be final or effectively final.It means all local referenced from lambda expressions must be such that their value shouldn't be changed after initialization whether declared final or not.

13.How does making string as immutable helps with securing information ? How does String Pool pose a security threat ?

String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment or hacker over internet.


Once a String constant is created in Java , it stays in string constant pool until garbage collected and hence stays there much longer than what's needed. Any unauthorized access to string Pool pose a threat of exposing these values.




No comments: