Differences between C and Java

  1. C is a procedural language, Java is object oriented

  2. C's main structuring element are functions in files. Java organizes code in classes and packages, thereby providing better namespaces.

  3. C code gets compiled into machine code for a specific CPU. Java code gets compiled into bytecode which is interpreted on a virtual machine (JVM). Java code can get compiled into machine code as well (just-in-time compilers etc.)

  4. C does not have exceptions. Errors are handled through return codes.

  5. C types like structures (objects without methods) can be allocated on the stack. Java needs to allocate all non-primitives on the heap using expensive memory management functions (e.g. "new").

  6. Arrays and strings in C are not bounds-checked. It is the programmers responsibility to stay within the allocated bounds

  7. C lets programmers access memory addresses directly through the use of POINTERS. Pointers are variables which contain a memory address. Text (code), data, heap and stack areas are all within a programmers reach. Java lets only the virtual machine access a programs stack, e.g. to perform security checks.

  8. Java primitive types are fixed in length. C types can vary per machine. This lets C take maximum use of hardware specifics (e.g. 16 bit register size vs. 32 bit register size). It also creates portability problems.

  9. C has a preprocessor and include files. The preprocess works like a macro processor which substitutes macros in the program file.