Monday 12 August 2013

Difference Between JAVA and C++

Difference between JAVA and C++


C++ Java
Strongly influenced by C syntax, with Object-Oriented features added. Strongly influenced by C++/C syntax.
Compatible with C source code, except for a few corner cases. Provides the Java Native Interface and recently Java Native Access as a way to directly call C/C++ code.
Write once, compile anywhere (WOCA). Write once, run anywhere / everywhere (WORA / WORE).
Allows procedural programming, functional programming, object-oriented programming, generic programming, and template metaprogramming. Favors a mix of paradigms. Strongly encourages exclusive use of the object-oriented programming paradigm. Includes support for generic programming and creation of scripting languages.
Runs as native executable machine code for the target instruction set(s). Runs in a virtual machine.
Provides object types and type names. Allows reflection through RTTI. Is reflective, allowing metaprogramming and dynamic code generation at runtime.
Has multiple binary compatibility standards (commonly Microsoft (for MSVC compiler) and Itanium/GNU (for virtually all other compilers)). Has a single, OS- and compiler-independent binary compatibility standard, allowing runtime check of correctness of libraries.
Optional automated bounds checking (e.g., the at() method in vector and string containers). All operations are required to be Bound-checked by all compliant distributions of Java. HotSpot can remove bounds checking.
Supports native unsigned arithmetic. No native support for unsigned arithmetic.
Standardized minimum limits for all numerical types, but the actual sizes are implementation-defined. Standardized types are available through the standard library <cstdint>. Standardized limits and sizes of all primitive types on all platforms.
Pointers, references, and pass-by-value are supported for all types (primitive or user-defined). All types (primitive types and reference types) are always passed by value.[1]
Memory management can be done explicitly through new / delete, by automatic scope-based resource management (RAII), or by smart pointers. Supports deterministic destruction of objects. Garbage collection ABI standardized in C++11, though compilers are not required to implement garbage collection. Automatic garbage collection. Supports a non-deterministic finalize() method whose use is not recommended.[2]
Resource management can be done manually or by automatic scope-based resource management (RAII). Resource management must be done manually, or automatically via finalisers, though this is generally discouraged. Has try-with-resources for automatic scope-based resource management (version 7 onwards).
Supports classes, structs (POD-types), and unions, and can allocate them on the heap or the stack. Classes are allocated on the heap. Java SE 6 optimizes with escape analysis to allocate some objects on the stack.
Allows explicitly overriding types as well as some implicit narrowing conversions (for compatibility with C). Rigid type safety except for widening conversions.
The C++ Standard Library was designed to have a limited scope and functionality but includes language support, diagnostics, general utilities, strings, locales, containers, algorithms, iterators, numerics, input/output, random number generators, regular expression parsing, threading facilities, type traits (for static type introspection) and Standard C Library. The Boost library offers more functionality including network I/O. A rich amount of third-party libraries exist for GUI and other functionalities like: ACE, Crypto++, various XMPP Instant Messaging (IM) libraries,[3] OpenLDAP, Qt, gtkmm.
The standard library has grown with each release. By version 1.6, the library included support for locales, logging, containers and iterators, algorithms, GUI programming (but not using the system GUI), graphics, multi-threading, networking, platform security, introspection, dynamic class loading, blocking and non-blocking I/O. It provided interfaces or support classes for XML, XSLT, MIDI, database connectivity, naming services (e.g. LDAP), cryptography, security services (e.g. Kerberos), print services, and web services. SWT offers an abstraction for platform-specific GUIs.
Operator overloading for most operators. Preserving meaning (semantics) is highly recommended. Operators are not overridable. The language overrides + and += for the String class.
Single and Multiple inheritance of classes, including virtual inheritance. Single inheritance of classes. Supports multiple inheritance via the Interfaces construct, which is equivalent to a C++ class composed of virtual methods.
Compile-time templates. Allows for Turing complete meta-programming. Generics are used to achieve basic type-parametrization, but they do not translate from source code to byte code due to the use of type erasure by the compiler.
Function pointers, function objects, lambdas (in C++11), and interfaces. References to functions achieved via the reflection API. OOP idioms using Interfaces, such as Adapter, Observer, and Listener are generally preferred over direct references to methods.
No standard inline documentation mechanism. Third-party software (e.g. Doxygen) exists. Extensive Javadoc documentation standard on all system classes and methods.
const keyword for defining immutable variables and member functions that do not change the object. Const-ness is propagated as a means to enforce, at compile-time, correctness of the code with respect to mutability of objects (see const-correctness). final provides a version of const, equivalent to type* const pointers for objects and const for primitive types. Immutability of object members achieved through read-only interfaces and object encapsulation.
Supports the goto statement. Supports labels with loops and statement blocks.
Source code can be written to be platform-independent (can be compiled for Windows, BSD, Linux, Mac OS X, Solaris, etc., without modification) and written to take advantage of platform-specific features. Typically compiled into native machine code, must be re-compiled for each target platform. Compiled into byte code for the JVM. Byte code is dependent on the Java platform, but is typically independent of operating system specific features.

No comments:

Post a Comment