Saturday, January 26, 2013

Singleton in Java

Singletion , usage , example, how to use.Enum Singleton

New features of Java 1.5


Enum in Java


How does a map work in java


Memory in Java

Stack memory
object itself : encapsulation

Heap Memory
variables of objects : encapsulation

Context Memory

static variables are placed in seperate memory called context memory hence no need to create variables/instances or objects to access static variables

Monday, January 21, 2013

Static in Java

Static in Java

Static variables and their use


Static methods and their use


Static Class and their use


Static Block

Final in Java

Final means immutable. Final classes cannot be inherited or instantiated. Final methods cannot be overriden and final variables cannot be changed

Final Classes and use
Final classes is a perfect class where nothing needs to be modified , changed , anything need not be added or deleted from the class. for e.g String class in java is final. We cannot override any methods from string class or instantiate the class.

Final Variables and use
Final variable can be used to declare constants which cannot be modified ever. To declare constants like PI. Final variables are read only.

Final methods and use

Final methods cannot be overriden. If you think you have written perfect method or if u dont want to change the method functionality and it should remain same for all the subclasses method should be made Final

Advantages
1) Final methods, variables are faster as they are cached by JVM at compile time
2) In multithreaded environment they are safe and overhead is avoided w/o using synchronization.