Java for C Developers

Some times ago, many people believed that Java was slower than C because Java had to run through a virtual machine.

Java for C Developers

Java for C Developers

     

  
Some times ago, many people believed that Java was slower than C because Java had to run through a virtual machine. Today however, Time and speed are not really affected by the programming language but it is important that an application developed in any language must be supported on cross platforms (Windows, Linux, etc.).
  
As a result, programmers and developers have started for the most powerful and easy way to 'learn and work? with programming language. Consequently they came for Object Oriented methodology with the multi-platform support, and other great capabilities and features.
OOP stands for Object Oriented Programming. This is a technique used to develop programs revolving around the real world entities. In OOPs programming model, programs are developed around objects rather than actions and logics. In OOPs, every real life object has properties and behavior, which is achieved through the class and object creation. They contain properties (variables of some type) and behavior (methods). 

OOP provides a better flexibility and compatibility for developing large applications.

 Java is a statically typed object-oriented language that uses syntax similar to C, but is not compatible with it. It was designed, with the goal of being easy to use for developer and accessible to wider spectators.
  
Java language comes in light from a language named Oak. Language Oak was developed in the early the nineties at Sun Microsystems as a platform-independent language aimed at allowing entertainment projects such as video game consoles and VCRs to communicate. Now Java has been improved by the newest releases of the implementation for the virtual machine.
 

Features of Java over C

There are a number of important differences between C and Java, which are summarized in the following list:

  1. No preprocessor
    Java does not support a preprocessor such as #define, #include, and #if def directives because it has no header files. Java has class files that contain both the class API and the class implementation.
      

  2. No global variables
    In Java, there is no possibility of namespace collisions among the variables because it defines a very clean namespace in the form of Packages. The Packages contain classes, which contain fields and methods in which local variables are declared.
     

  3. Well-defined primitive type sizes
    In C, the size of short, int, and long types is platform-dependent, which obstruct portability. While in Java, all the primitive Data types have well-defined sizes.
      

  4. No pointers
    In C, pointers are a disreputable source of bugs. Classes and arrays in Java are reference types. These references to objects and arrays are similar to pointers in C. There is no way to convert a reference to a primitive type, and it cannot be incremented or decremented also. Java programs eliminate the pointer to simplify the language and make it more robust and secure.

  5. Garbage collection
    Java programmers do not have to explicitly manage the memory used by all objects and arrays because the Java Virtual Machine (JVM) performs garbage collection implicitly. This feature eliminates another entire category of common bugs and memory leaks from Java programs.
     

  6. No Need of Data Structure
    Java supports a pre-built interface known as Collection. This interface allows programmers to have their own data structure with less of codes. Unlike C, they don?t need to write complex algorithms to make a data structure.
      

  7. Provides String class
    Unlike C, You don?t need to define an array of type char to store the string data. Java provides a String class and its methods to manipulate with strings.
      

  8. Variable declarations anywhere
    C always requires local variable declarations to be made at the beginning of a method or block, while Java allows them anywhere in a class, method or block.
      

  9. Method overloading
    Java provides a feature of method overloading where you can define multiple methods with the same name, but having different parameter lists. While, it is not possible in C.
     

  10. Support Native interfaces  
    The Java Native Interface (JNI) comes with the standard Java Development Kit (JDK) from Sun Microsystems. It permits Java programmers to integrate native code (currently C and C++) into their Java applications. The primary goal of JNI is binary compatibility of native method libraries across all Java virtual machine implementations on a given platform.
     

  11. Forward references  
    The Java compiler is smarter than the C compiler. It allows methods to be invoked before they are defined. Unlike C, this eliminates the need to declare functions in a header file before defining them in a program file.