Header Ads Widget

Introduction to java | Java Tutorial | Java Programming | Overview

 Introduction to Java:-

Java is quiet a Popular Language. It is quiet popular in the Industry and many big companies have their packages or bases of software in the java and Java also as for development purpose is very useful because of its various features in it. Java is an Object Oriented Language.


Features of Java:-

  • It is a Object Oriented Language.
  • It is a relatively stable.
  • It has Multi Threading.
  • It is very Efficient at Memory Management.

And the Most Important Feature of the Java is;-
  • It is Platform Independent.
 
Java


How Java  achieve Platform Independence?

As we write a code in any other language like C or C++ like
c = a +b;
and we want to run this code in our machine.
But, the problem is that the code we have written is in Simple English but out machine or the hardware we are working on needs the code in Binary Form. Because the Machine only Understand the Binary Language. Binary is a Base2 number system, but the humans are more comfortable with the Base10 number system.
Base2 number System includes only 2 digits i.e. 0 and 1. 
As it would be really hard for us to write code in the binary, so we were be writing code in C++ or Java which is more readable for us, so for some how we have to bridge this gap because at one end is a High level Language and at the other end is a Hardware which only understand Low Level Language i.e. Binary Language so we need a mediator in between  so that mediator which comes into picture is Compiler.
so whatever code we write weather it is in C++ file it will be stored as .CPP file and if it is Java it is stored as .Java file
so compiler converts these codes into the stream of binary numbers like 10001001 like this then machine reads that code and executes it and then you see the desired outcome.


Talking about C++:-
Like we have written our code which is stored in .CPP file and now we have to compile our code and after compiling you get an  .exe/a.out file then you run it on your hardware or machine or platform or operating system with processors. 
Now, the compilation output or the binary code is not common for all the processors different processors have different binary outcome even for the same instruction.

For Example:-

C = A + B 

The binary outcome of this instruction can be 1010100 in one machine and it can be 1111001 in the other machine.

The Binary outcome is not the same for all the processors or all the platforms which is why compiler has to produce different results for different platforms.(like you are running an instruction in an windows machine and the other one is Mac or different OS then the compiled outcome will be different) 

Now, this brings us to a problem because if you share the compiled code with someone you can not directly do that because that compile code might not work on all the machines.

so if you share the source code we can straight away do that but generally we don't do that because that is our personal hardwork, we just want that the program should run on someone machine so by that we mean we can share the executable file but the problem is that with it is build and used according to my platform and that executable file might not run on multiple platforms because on multiple platforms we might get unexpected result for eg

C =  A + B
let 1010100  this be the code for this and let us consider that 101 is the code for the addition in 1 machine and it might happen that 101 be the code of Subtraction on the other machine, so we may get wrong answers because we have to add those numbers and we will get the subtraction of those number so that will not works 

By considering this we can say that the C++ language is Platform Dependent
because in this we have to produce compiled outcome for different outcomes for different outcomes machines, that is a problem which C++ faces.


But here we can say that the Java is Platform Independent.

So, How does this Happens in Java? 


Let say we have written our code which is stored in the .java file  now we compile that code, now the compile we get is a .class file and it is not directly the binary file we will we eventually executing on our screens.
Now, this .class file is same for all the combinations of platforms which includes both operating systems and the hardware or processors. So we can directly execute this .class file in any platform. 
So now if we don't want to share the source code to someone but after compiling it and we can send that .class to anyone we want.

Now, what is that happen? 
Does that this mean that all the platform understand the same binary now --- No, that doesn't happen still different platforms have their different binary outcomes.

what happens but in Java that we have a JVM in between, which is known as Java Virtual Machine and the best thing about this that this is Platform Independent. 
Now, this .class outcome which we have is given to the JVM and then JVM produces the required binary file for different platforms, so there is a layer between the .class file and JVM that helps Java to achieve the Platform Independence. 

So now we have a Java code which will be converted in the .class file and now .class is a common Platform, it is a common code which can run on any Platforms and different platform have different version of JVM and that JVM is going to convert that .class file into the relevant binary file for that platform where it can execute


So, this is how Java achieve his Platform Independence...

and in case of C++ there is no .class file and JVM in between so which is why you have to compile it separately for multiple machines but in this case you have to  compile it once but you need JVM on multiple platforms and then you will be able to run it.

This is where Java gets benefited over C++.



THANK YOU FOR READING THIS ARTICLE ON-

SPARSH BLOG


Please feel free to contact us in the comment section or you can reach us using Contact us Page.
<script type="text/javascript">
atOptions = { 'key' : '6862865a535f391da4662498c7902b22', 'format' : 'iframe', 'height' : 90, 'width' : 728, 'params' : {} }; document.write('<scr' + 'ipt type="text/javascript" src="http' + (location.protocol === 'https:' ? 's' : '') + '://blowlanternradical.com/6862865a535f391da4662498c7902b22/invoke.js"></scr' + 'ipt>'); 
</script> 

Post a Comment

0 Comments