Showing posts with label pointer. Show all posts
Showing posts with label pointer. Show all posts

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.