Tuesday, 30 May 2017

What is Transient Keyword ?


Transient keyword is used along with instance variables to exclude them from serialization process.It provides you some control over serialization process and gives you flexibility to exclude some of object properties from serialization process.
  • While performing serialization if we don’t want to serialize the value of a particular variable then we should declare that variable with “transient” keyword.
  •  At the time of serialization JVM  ignores the original value of transient variable and save default value.
  • That is transient means “not to serialize”.
Important Points:
  • Transient keyword can not be used along with static keyword.Static variable is not part of object state hence they won’t participate in serialization because of this declaring a static variable as transient these is no use.
  • Final variables will be participated into serialization directly by their values. Hence declaring a final variable as transient there is no use.
  • Transient keyword can only be applied to fields or member variable. Applying it to method or local variable is compilation error.
  • Transient variable in java is not persisted or saved when an object gets serialized.

Sunday, 28 May 2017

Introduction To JVM

What is JVM ?

Java virtual Machine(JVM) is a virtual Machine that provides runtime environment to execute java byte code. The JVM doesn't understand Java type, that's why you compile your *.java files to obtain *.class files that contain the byte codes understandable by the JVM.

JVM control execution of every Java program. It enables features such as automated exception handling, Garbage-collected heap.


JVM Architecture : 



Class Loader : Class loader loads the Class for execution. Boot Strap class Loader, Extension class Loader, and Application class Loader are the three class loader which will help in achieving it.
  1. Boot Strap ClassLoader – Responsible for loading classes from the bootstrap classpath,   nothing but rt.jar. Highest priority will be given to this loader.
  2. Extension ClassLoader – Responsible for loading classes which are inside ext folder (jre\lib).
  3. Application ClassLoader –Responsible for loading Application Level Classpath, path mentioned Environment Variable etc.
Method area : All the class level data will be stored here, including static variables. There is only One Method Area per JVM.

Heap : All the Objects and their corresponding instance variables and arrays will be stored here. There is also one Heap Area per JVM. Since the Method and Heap areas share memory for multiple threads, the data stored is not thread safe.


Stack : Local variables and partial results are store here. Each thread has a private JVM stack created when the thread is created.


Program Register : Program register holds the address of JVM instruction currently being executed.


Native method stack : It contains all native used in application.


Executive Engine : The byte code which is assigned to the Run time  Area will be executed by the Execution Engine. The Execution Engine reads the byte code and executes it piece by piece.

  1. Interpreter
  2. JIT Compiler
  3. Garbage Collector

Native Method Interface : Native method interface gives an interface between java code and native code during execution.

Native Method Libraries :It is a collection of the Native Libraries which is required for the Execution Engine.

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...