Showing posts with label platform independent. Show all posts
Showing posts with label platform independent. Show all posts

Thursday, July 17, 2014

Why Java Is Platform Independent

Getting output from java program is two step procedure, compilation and interpretation. Output of java compiler is not executable code but it is compiled code. JVM is an interpreter for byte code. Byte code is set of instructions which are to be executed by java run time system called as Java Virtual Machine (JVM). Each JVM has its own executable format so this byte code (.class file) becomes platform independent as this byte code runs on JVM and not on actual OS.
So once we have compiled java program, it can be executed on any platform. The details of the JVM differ from platform to platform and each OS has its own JVM format.  So in java it is “write once; run anywhere, anytime”.

So java is platform independent and JVM is highly platform dependent.

Why Java Is Preferred?

The developers preferred java over traditional programming languages like C and C++.Java is preferred due to its unique feature platform independent, robustness and more secure.
·         Simple: Java inherits most of the syntax of C and many of the OOPs features of C++. In addition to this is has its own add in features which are easy for professional programmers to learn.
·         Object Oriented: Java uses OOPs concepts for faster programming. It has most of the packages and interfaces built-in which are easily reused and extended. The class and object structure provides data encapsulation, abstraction, inheritance and polymorphism.
·         Robust:  Java is robust because of two reasons memory management and exception handling. In traditional programming C,C++ dynamic memory management is very difficult as memory allocation and de-allocation must be done by programmer but java does this dynamic memory allocation and de-allocation without any extra efforts. Exceptional conditions may arise in traditional programming which may leads to abnormal termination of programs but java provides exception handling which helps to handle and eliminate these run time errors.
·         Secure: All java programs run over JVM platform and not on Operating system. So any OS related updates or modification does not affect execution of java program. Java also provides packages and access modifiers which in turn provides security. Java applets are executed inside sandbox which creates an environment which provides restricted access to OS resources and allows user to run untrusted code from unknown source safely. Java uses byte code verifier module which checks java code automatically before executing it. Java provides run time array boundary check which is not provided in traditional programming. In traditional programming memory references can be manipulated but in java you cannot manipulate references which interns provides secure memory access.
·         Platform Independent: Traditional languages C, C++ were designed to compile for specific platform (processors, OS). In java executable code runs over JVM platform which is independent of OS. So once we have byte code (.class file) we can execute it on any OS. So java code needs to be compile only once and we can execute it any number of times across different platforms (processors, OS). So it is “write once, run anywhere, anytime”. 
·      Multithreaded: Java provides multithreaded programming which allows doing many things simultaneously. Each thread performs separate task. For example using text editor with spell check feature enabled which allows editing and spelling check simultaneously.

Tuesday, July 15, 2014

Why Java is preferred over C and C++

When it comes on selecting a programming language, we need to consider few parameters like security, robustness, ease in programming and few other parameters, because of below mentioned parameters java is preferred over C++ :

·         Robust:  Java is robust because of two reasons memory management and exception handling. In C,C++ programming dynamic memory management is very difficult as memory allocation and de-allocation must be done by programmer but Java does this dynamic memory allocation and de-allocation without any extra efforts.

·         No Pointers: Use of pointer is avoided in Java. In C++ programming memory references can be manipulated but in Java, you cannot manipulate references which in turn provide secure memory access.

·         Platform Independence and Portability: Traditional languages C, C++ were designed to compile for specific platform (processors, OS). In Java executable code runs over JVM platform which is independent of OS. So once we have byte code (.class file) we can execute it on any OS. So Java code needs to be compiled only once and we can execute it any number of times across different platforms (processors, OS). So Java provides platform independence and portability.

·         Secure: Java provides sandbox security model for applet execution which creates an environment which provides restricted access to OS resources and allows user to run un-trusted code from unknown source safely. All Java programs run over JVM platform and not on Operating system. So any OS related updates or modifications do not affect execution of Java program.  Java uses byte code verifier module which checks Java code automatically before executing it.


·         Multithreading : its support to multithreading made java enabled for multitasking which allows available resources to be used optimally. Java has built in support for multithreading but in C++, multithreading is entirely dependent on Operating System.