Posts

Showing posts from December, 2017

Stack vs Heap - Java

Image
STACK Stack is a memory space , reserved by operating system for our process. Size of stack memory is fixed, it is determined in the compiler phase based on variables declaration and other compiler options. When memory is full, then java runtime throws java.lang.StackOverflowError We can use –Xss to define the size of stack memory. Method invocation and local variables lives in stack memory Stack memory used for execution of a thread Remember that Stack memory is always referenced in LIFO (Last-In-First-Out) order, It does means when we call a method, it will be on top of call stack. Method stack exists only till life of method, from the calling until the return. Local variables are also known as slack variables , because they are on the method stack, they exist as long as the method is executed. If the local variable is a reference to an object, only the variable goes on the stack. main method is a special method (the process starts and ends with main) its loc

Abstract class vs Interface

Abstract class An abstract class is a class that is declared with 'abstract' keyword  It may or may not include abstract methods An abstract class cannot be instantiated.  An abstract class can implement interface without even providing the implementation of interface methods.   Syntax         abstract class Payment          {   //constants and methods         }   Example   abstract class Payment         {   abstract void doPayment();   }   class CreditCardPayment extends Payment          {                 @Override   void doPayment()                                     {                    Sysout("Payment with CreditCard");   }   } Interface Interface is the way to achieve abstraction in Java. ' Interface ' keyword is used to create Interface. Just like Abstract class Interface also cannot be instantiated. All the fields declare

Understanding JDK, JRE & JVM

Image
JDK Stands for Java Development Kit JDK includes JRE and command-line development tools such as compilers , debuggers etc All the commands such as javac, java, jar, javap etc found in JDK. JDK is a superset of a JRE since it contains JRE with Java compiler, debugger and core classes. JDK is a platform specific software, we have separate installers for Windows, Mac and Unix systems JRE Stands for Java Runtime Environment The JRE provides the libraries, JVM, and other components necessary for you to run java applications.  JRE is the implementation of Java virtual machine, it provides platform to execute java programs. If you want to execute java program, you should have JRE installed. JVM Stands for Java Virtual Machine The JVM is an abstract computing machine that has an instruction set and manipulates memory at run time.  When we run a program, JVM is responsible to convert Byte code to the machine specific code. The JVM provides hardware and operating syst