Wednesday, November 3, 2010

JVM-the Heart of JAVA

JVM-JAVA VIRTUAL MACHINE-(lay man answer)...think differently...yes!!! I can put it this way..
JVM is a set of programs that is assigned with many tasks....then why it is called a virtual machine...we know MACHINE performs many tasks and this is what is done by JVM, since it is a software and all the tasks performed by it are done by programz(that are not seen),it is called virtual machine
As I already said JVM is assigned with many tasks,u might probably think of what tasks they could be???
well!!
  • JVM loads byte code to RAM.
  • Searches and locates the functionality.
  • It converts the functionality into executable code of the correspondig operating system.
  • Allocates memory and loads the executable code of the current functionality.
  • Maintains the executable code in the RAM.
  • Makes processor to execute the current functionality.
  • Deletes the executable code of the function once its execution is complete.
these are the tasks performed by JVM,hence u can call it a virtual machine.

How can we say that JVM is responsible for platform independency????
As we already know that JVM converts bytecode to executable code,only this part of the program is designed according to the operating system compatibility,hence ,therefore u need not change the entire software of java into OS compatible,and we already know JVM is so small in size,easily downloadable,itis not taken into account at all,hence JVM plays a key role in making JAVA Platform Independent.
AND a Key point to remember,it is through JVM we implement the concept of 'Dynamic loading',that is allocating memory to the variables at run-time.
Thus , we can say JVM is the heart of JAVA

Tuesday, November 2, 2010

FEATURES OF JAVA

  • Platform independency
  • Security
  • Multitasking
are the key features of why java has gained its importance in the market..and let me tell u java was exclusively invented to implement  its features on buisness side than on system-side applicationz...so lets have a clear idea on its key features
PLATFORM INDEPENDENCY:
what is a PLATFORM??
Machine + architecture is called  Platform.
The ability of a program to run on any system irrespective of the operating system that is present is called PLATFORM INDEPENDENCY.
C is not platform independent coz the executable code of it cannot run on all operating system. It is confined to operating systems,whereas java runz on an operating system, what makes java program to run on any operating system is JVM, before that lets learn what is source code and executable code????


SOURCE CODE: Any thing which is understandable by the user or programmer is called source code,usually the programz that we write following some syntactic rules is called source code,now this source code can run on any operating system
For example lets take
void main()
{
printf("halo world");
}
this C source code can work on any operating system..(u can check it practically too) then y do we call C as a platform dependent if its source code is running on all operating-systems..well!! here exactly we need to discuss something about Compiled code and executable code.
WHAT IS COMPILED CODE?
Every source code is converted into compiled code in order to make computer understand what the user wants to do,hence compiled code is the binary format which a computer can understand.
Now,in C,compiled code is executable code, this executable code is something which is machine dependent and varies from operating system to operating system,because every operating-system is designed according to its own standards so when u try to run the compiled code of one machine on other machine,definetly u would fail in doing the task coz the machines are not compatible with each other and cant understand each other's code,hence compiled code cannot be run on different systems,hence C is purely platform dependent...
  Now u may have a question of why cant we directly run the source code every time....wats the big deal with compiled code..???
Well! In real time scenario, we can't take risk to give a source code to our clients,the obvious reason is we will run out of buisness in case we do it,hence we always prefer to give compiled code or executable code(in this case) to the clients,hence we need the concept of platform independency i.e the ability of a program to run on any OS(operating system).

Now how java is platform independent??
Java is platform independent because it has the concept of JVM..
before we know what is JVM,lets get into little deep into the concept of compiled code..
Every compiled code need not be executable code,in case of java a compiled code is a byte code,later on this byte code is converted into executable code by JVM.

An obvious question... what is Byte code??
Byte code is also a format which is understandable by computer but it is not in the binary format instead it is in the assembly language format,a combination of alpha numerics and few symbols,(where as binary format is purely 1's and 0's).
So,every java program is firstly converted into byte code and then this byte code is lateron converted to executable code by JVM and is run on machines.
Another obvious question i can expect is when JVM converts byte code into executable code according to machine format,it is obvious that JVM is platform dependent, then how can we say that java is platform independent..
hmm!! It is because JVM is small in size,easily downloadable,fast and hence we do not really take the existence of java into account and hence we run the programz
Remember,JVM is designed compatible to the operating system,hence from OS to OS only JVM varies,thus JVM makes Java Platform independent..


In my next blog we shall see what is JVM,how ever the remaining features of java will be discussed according to the situations we encounter as and when..
I will be happy to see ur comments and doubts in case if u have any