unucirebon.prestasi.web.id Layanan Informasi 17 Jam
Telp/Fax : 021-8762002, 8762003, 8762004, 87912360
HP/SMS : 081 1110 4824 27, 0812 9526 2009, 08523 1234 000
WhatsApp : 0817 0816 486, 0812 9526 2009
email : _Hubungi Kami__ silahkan klik
Chatting dengan Staf :
ggkarir.com
ggiklan.com
Pilih Bahasa :   ID   EN   Permintaan Katalog / Brosur (GRATIS via POS)   Kelas Karyawan   Reguler
S1 SosiologiS1 Akhwal al Syakhsiyyah / Hukum Perdata Islam (Syariah)S1 Ilmu PertanianS1 PsikologiUmumKedutaan KBRIPerpustakaanJavaScriptPerangkat Lunak (Software)

   
Cari  
    Informatika & Komputer

    Sebelumnya  (Comparison of iOS e-book reade ...) (Comparison of Java virtual machines)  Berikutnya    

Perbandingan -- Java and C++

This is a comparison of the Java programming language with the C++ programming language.

Contents

Design aims

The differences between the C++ and Java programming languages can be traced to their heritage, as they have different design goals.

The different goals in the development of C++ and Java resulted in different principles and design trade-offs between the languages. The differences are as follows :

C++Java
Compatible with C source code, except for a few corner cases.No backward compatibility with any previous language. The syntax is, however, strongly influenced by C/C++. There are things such as reserved keywords, such as const and goto that don't do anything so that people who write on C++ don't get confused.
Write once, compile anywhere (WOCA).Write once, run anywhere / everywhere (WORA / WORE).
Allows procedural programming, functional programming, object-oriented programming, and template metaprogramming.Strongly encourages an object-oriented programming paradigm.
Allows direct calls to native system libraries.Call through the Java Native Interface and recently Java Native Access
Exposes low-level system facilities.Runs in a virtual machine.
Only provides object types and type names.Is reflective, allowing metaprogramming and dynamic code generation at runtime.
Has multiple binary compatibility standards (commonly Microsoft and Itanium/GNU).Has a binary compatibility standard, allowing runtime check of correctness of libraries.
Optional automated bounds checking (e.g., the at() method in vector and string containers).Normally performs bounds checking. 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 as typedefs (uint8_t, ..., uintptr_t, ...).Standardized limits and sizes of all primitive types on all platforms.
Pointers, references, and pass-by-value are supported.Primitive and reference data type (object) parameters are always passed by value.[1]
Explicit memory management. Supports destructors. C++11 replaces the old standard RAII auto_ptr<T> by unique_ptr<T> and adds shared_ptr<T> (smart pointer with reference counter), though third party frameworks exist to provide better garbage collection.Automatic garbage collection (can be triggered manually). Has a finalize() method that works like a destructor though should not be used to free resources since its call is uncertain.[2]
Supports classes, structs, and unions, and can allocate them on heap or stack.Only supports classes, and allocates them on the heap. Java SE 6 optimizes with escape analysis to allocate some objects on the stack.
Allows explicitly overriding types.Rigid type safety except for widening conversions. Autoboxing/unboxing added in Java 1.5.
The C++ Standard Library has a much more limited scope and functionality than the Java standard library but includes language support, diagnostics, general utilities, strings, locales, containers, algorithms, iterators, numerics, input/output, and Standard C Library. The Boost library offers more functionality, including threads and network I/O. Users must choose from a plethora of (mostly mutually incompatible) third-party libraries for GUI and other functionality.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.The meaning of operators is generally immutable, but the + and += operators have been overloaded for Strings.
Full Multiple inheritance, including virtual inheritance.Only single inheritance is allowed. A class can implement multiple Interfaces, but can inherit neither data members nor function bodies from more than one ancestor.
Compile-time templates.Generics are used to achieve an analogous effect to C++ templates, 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.No function pointer mechanism except through reflection. Instead, idioms such as Interface, Adapter, and Listener are extensively used.
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.final provides a version of const, equivalent to type* const pointers for objects and plain const for primitive types only. No const member functions, nor any equivalent to const type* pointers.
Supports the goto statement. It may cause Spaghetti Programming.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.Compiled into byte code for the JVM. Byte code is dependent on the Java platform, but is typically independent of operating system specific features.

Language features

Syntax

  • Java syntax has a context-free grammar that can be parsed by a simple LALR parser. Parsing C++ is more complicated. For example, Foo<1>(3); is a sequence of comparisons if Foo is a variable, but creates an object if Foo is the name of a class template.
  • C++ allows namespace-level constants, variables, and functions. In Java, such entities must belong to some given type, and therefore must be defined inside a type definition, either a class or an interface.
  • In C++, objects are values, while in Java they are not. C++ uses value semantics by default, while Java always uses reference semantics. To achieve reference semantics in C++, either a pointer or a reference can be used.
C++Java
class Foo {           // Declares class Foopublic:    int x;           // Member variable     Foo(): x(0) {}   //  Constructor for Foo; initializes                     //  x to 0. If the initializer were                     //  omitted, the variable would not                     //  be initialized to a specific                     //  value.     int bar(int i) { // Member function bar()        return 3*i + x;    }};
class Foo {               // Defines class Foo    public int x;         // Member variable,                          //initialized to 0 by default     public Foo() {        // Constructor for Foo    }     public int bar(int i) {// Member method bar()        return 3*i + x;    }}
Foo a;// declares a to be a Foo object value,// initialized using the default constructor.// Another constructor can be used asFoo a(args);
Foo a;// declares a to be a reference to a Foo objecta = new Foo();// initializes using the default constructor// Another constructor can be used asFoo a = new Foo(args);
Foo b = a;// copies the contents of a to a new Foo object b;// alternative syntax is "Foo b(a)"
Foo b = a.clone();// copies the contents of the object pointed to by a to a new Foo object;// sets the reference b to point to this new object;// the Foo class must implement the Clonable interface for this code to compile
a.x = 5; // modifies the object a
a.x = 5; // modifies the object referenced by a
cout << b.x << endl;// outputs 0, because b is// a different object than a
System.out.println(b.x);// outputs 0, because b points to// a different object than a
Foo *c;// declares c to be a pointer to a// Foo object (initially// undefined; could point anywhere)
Foo c;// declares c to be a reference to a Foo// object (initially null if c is a class member;// it is necessary to initialize c before use// if it is a local variable)
c = new Foo;// binds c to reference a new Foo object
c = new Foo();// binds c to reference a new Foo object
Foo *d = c;// binds d to reference the same object as c
Foo d = c;// binds d to reference the same object as c
c->x = 5;// modifies the object referenced by c
c.x = 5;// modifies the object referenced by c
a.bar(5);  // invokes Foo::bar() for ac->bar(5); // invokes Foo::bar() for *c
a.bar(5); // invokes Foo.bar() for ac.bar(5); // invokes Foo.bar() for c
cout << d->x << endl;// outputs 5, because d references the// same object as c
System.out.println(d.x);// outputs 5, because d references the// same object as c
  • In C++, it is possible to declare a pointer to a const type in order to prevent client code from modifying the object pointed to by that pointer. Functions and methods can also guarantee that they will not modify the object pointed to by a pointer by using the "const" keyword. This enforces const-correctness.
  • In Java, const-correctness is enforced by the semantics of the class of which a given object is an instance. Client code is prevented from changing the internal state of an object if and only if every accessible member of the class is labeled final.
C++Java
const Foo *a; // it is not possible to modify the object              // pointed to by a through a
final Foo a; // a declaration of a "final" reference:             // it is possible to modify the object,              // but the reference will constantly point              // to the first object assigned to it
a = new Foo();
a = new Foo(); // Only in constructor
a->x = 5;// ILLEGAL
a.x = 5;// LEGAL, the object can still be modified
Foo *const b = new Foo();// a declaration of a "const" pointer
final Foo b = new Foo();// a declaration of a "final" reference
b = new Foo();//ILLEGAL, it is not allowed to re-bind it
b = new Foo();// ILLEGAL, it is not allowed to re-bind it
b->x = 5;// LEGAL, the object can still be modified
b.x = 5;// LEGAL, the object can still be modified
  • C++ supports goto statements, which may lead to Spaghetti programming. With the exception of the goto statement, both Java and C++ have basically the same control flow structures, designed to enforce structured control flow, and relies on break and continue statements to provide some goto-like functionality. Some commenters point out that these labelled flow control statements break the single point-of-exit property of structured programming.[3]
  • C++ provides low-level features which Java lacks. In C++, pointers can be used to manipulate specific memory locations, a task necessary for writing low-level operating system components. Similarly, many C++ compilers support an inline assembler.

In Java, such code must reside in external libraries, and can only be accessed through the Java Native Interface, with a significant overhead for each call.

Semantics

  • C++ allows default values for arguments of a function/method. Java does not. However, method overloading can be used to obtain similar results in Java but generate redundant stub code.
  • The minimum of code you need to compile for C++ is a function(method). The minimum for java is a class.
  • C++ allows a range of implicit conversions between native types, and also allows the programmer to define implicit conversions involving user-defined types. In Java, only widening conversions between native types are implicit; other conversions require explicit cast syntax.
    • A consequence of this is that although loop conditions (if, while and the exit condition in for) in Java and C++ both expect a boolean expression, code such as if(a = 5) will cause a compile error in Java because there is no implicit narrowing conversion from int to boolean. This is handy if the code was a typo for if(a == 5). Yet current C++ compilers usually generate a warning when such an assignment is performed within a conditional expression. Similarly, standalone comparison statements, eg. a==5;, without a side effect generate a warning.
  • For passing parameters to functions, C++ supports both pass-by-reference and pass-by-value. In Java, primitive parameters are always passed by value. Class types, interface types, and array types are collectively called reference types in Java and object references are passed by value.[4][5][6]
  • Java built-in types are of a specified size and range defined by the language specification. In C++, a minimal range of values is defined for built-in types, but the exact representation (number of bits) can be mapped to whatever native types are supported on a given platform.
    • For instance, Java characters are 16-bit Unicode characters, and strings are composed of a sequence of such characters. C++ offers both narrow and wide characters, but the actual size of each is platform dependent, as is the character set used. Strings can be formed from either type.
  • The rounding and precision of floating point values and operations in C++ is platform dependent. Java provides an optional strict floating-point model that guarantees consistent results across platforms, though possibly at the cost of slower run-time performance. Some C++ compilers also provide similar options for floating-point behavior.[7]
  • In C++, pointers can be manipulated directly as memory address values. Java references are pointers[8] but these references can refer only to objects and arrays. Java references do not allow direct access to memory addresses or allow memory addresses to be manipulated with pointer arithmetic. In C++ one can construct pointers to pointers, pointers to ints and doubles, and pointers to arbitrary memory locations. Java references only access objects and arrays, never primitives, other references, or arbitrary memory locations.
  • In C++, pointers can point to functions or methods (function pointers or functors). The equivalent mechanism in Java uses object or interface references.
  • Through the use of stack-allocated objects, C++ supports scoped resource management, a technique used to automatically manage memory and other system resources that supports deterministic object destruction. While scoped resource management in C++ cannot be guaranteed (even objects with proper destructors can be allocated using new and left undeleted) it provides a good means of simple resource management. Shared resources can be managed using shared_ptr. In case of cyclic references, shared_ptr will fail to detect loss of accessibility and the resources will leak. Java supports automatic memory management using garbage collection which can free unaccessible objects even in presence of cyclic references, but other system resources (files, streams, windows, communication ports, threads(?)) must be explicitly released because garbage collection is not guaranteed to occur immediately after last object reference is abandoned.
  • C++ features programmer-defined operator overloading which is not supported in Java. The only overloaded operators in Java are the "+" and "+=" operators, which concatenate strings as well as performing addition.
  • Java features standard API support for reflection and dynamic loading of arbitrary new code.
  • C++ supports static and dynamic linking of binaries.
  • Java has generics, whose main purpose is to provide type-safe containers. C++ has compile-time templates, which provide more extensive support for generic programming and metaprogramming. Java has annotations, which allow adding arbitrary custom metadata to classes and metaprogramming via an annotation processing tool.
  • Both Java and C++ distinguish between native types (these are also known as "fundamental" or "built-in" types) and user-defined types (these are also known as "compound" types). In Java, native types have value semantics only, and compound types have reference semantics only. In C++ all types have value semantics, but a reference can be created to any type, which will allow the object to be manipulated via reference semantics.
  • C++ supports multiple inheritance of arbitrary classes. In Java a class can derive from only one class, but a class can implement multiple interfaces (in other words, it supports multiple inheritance of types, but only single inheritance of implementation).
  • Java explicitly distinguishes between interfaces and classes. In C++, multiple inheritance and pure virtual functions make it possible to define classes that function almost like Java interfaces do, with a few small differences.
  • Java has both language and standard library support for multi-threading. The synchronized keyword in Java provides simple and secure mutex locks to support multi-threaded applications. Java also provides robust and complex libraries for more advanced multi-threading synchronization. Only as of C++11 is there a defined memory model for multi-threading in C++. There are also third-party libraries to provide support roughly equivalent to that of Java.
  • C++ methods can be declared as virtual functions, which means the method to be called is determined by the run-time type of the object. By default, methods in C++ are not virtual. In Java, methods are virtual by default, but can be made non-virtual by using the final keyword.
  • C++ enumerations are primitive types and support conversion to and comparison with other integer types. Java enumerations can be public static enum{enumName1,enumName2} and are used like classes. Another way is to make another class that extends java.lang.Enum<E>) and may therefore define constructors, fields, and methods as any other class.
  • Unary operators '++' and '--': in C++ "The operand shall be a modifiable lvalue. [skipped] The result is the updated operand; it is an lvalue...",[9] but in Java "A variable that is declared final cannot be {decremented,incremented} because when an access of such a final variable is used as an expression, the result is a value, not a variable.",[10] i.e. in Java if "Integer i(2);" then "++i;" changes the reference i by assigning new object, while in C++ the object is still the same.

Resource management

  • Java offers automatic garbage collection. Memory management in C++ is usually done through constructors, destructors, and smart pointers. The C++ standard permits garbage collection, but does not require it; garbage collection is rarely used in practice. The enforced use of automatic garbage collection means that writing real-time software can be difficult in Java.[3]
  • C++ can allocate arbitrary blocks of memory. Java only allocates memory through object instantiation. (Note that in Java, the programmer can simulate allocation of arbitrary memory blocks by creating an array of bytes. Still, Java arrays are objects.)
  • Java and C++ use different idioms for resource management. Java relies mainly on garbage collection, which can reclaim memory, while C++ relies mainly on the RAII (Resource Acquisition Is Initialization) idiom. This is reflected in several differences between the two languages:
    • In C++ it is common to allocate objects of compound types as local stack-bound variables which are destroyed when they go out of scope. In Java compound types are always allocated on the heap and collected by the garbage collector (except in virtual machines that use escape analysis to convert heap allocations to stack allocations).
    • C++ has destructors, while Java has finalizers. Both are invoked prior to an object's deallocation, but they differ significantly. A C++ object's destructor must be implicitly (in the case of stack-bound variables) or explicitly invoked to deallocate the object. The destructor executes synchronously just prior to the point in the program at which the object is deallocated. Synchronous, coordinated uninitialization and deallocation in C++ thus satisfy the RAII idiom. In Java, object deallocation is implicitly handled by the garbage collector. A Java object's finalizer is invoked asynchronously some time after it has been accessed for the last time and before it is actually deallocated, which may never happen. Very few objects require finalizers; a finalizer is only required by objects that must guarantee some clean up of the object state prior to deallocation — typically releasing resources external to the JVM. In Java, safe synchronous deallocation of resources can be performed explicitly using the try/catch/finally construct.
    • In C++, it is possible to have a dangling pointer – a stale reference to an object that has already been deallocated. Attempting to use a dangling pointer typically results in program failure. In Java, the garbage collector will not destroy a referenced object.
    • In C++, it is possible to have uninitialized primitive objects. Java enforces default initialization.
    • In C++, it is possible to have an allocated object to which there is no valid reference. Such an unreachable object cannot be destroyed (deallocated), and results in a memory leak. In contrast, in Java an object will not be deallocated by the garbage collector until it becomes unreachable (by the user program). (Note: weak references are supported, which work with the Java garbage collector to allow for different strengths of reachability.) Garbage collection in Java prevents many memory leaks, but leaks are still possible under some circumstances.[11]

Libraries

  • C++ provides cross-platform access to many features typically available in platform-specific libraries. Direct access from Java to native operating system and hardware functions requires the use of the Java Native Interface.

Runtime

C++Java
C++ is compiled directly to machine code which is then executed directly by the operating system.Java is compiled to byte-code which the Java virtual machine (JVM) then interprets at runtime. Actual Java implementations do Just-in-time compilation to native machine code, resulting in comparable execution time to C++.
  • Due to its unconstrained expressiveness, low level C++ language features (e.g. unchecked array access, raw pointers, type punning) cannot be reliably checked at compile-time or without overhead at run-time. Related programming errors can lead to low-level buffer overflows and segmentation faults. The Standard Template Library provides higher-level abstractions (like vector, list and map) to help avoid such errors. In Java, low level errors either cannot occur or are detected by the JVM and reported to the application in the form of an exception.
  • The Java language requires specific behavior in the case of an out-of-bounds array access, which generally requires bounds checking of array accesses. This eliminates a possible source of instability but usually at the cost of slowing down execution. In some cases, especially since Java 7, compiler analysis can prove a bounds check unnecessary and eliminate it. C++ has no required behavior for out-of-bounds access of native arrays, thus requiring no bounds checking for native arrays. C++ standard library collections like std::vector, however, offer optional bounds checking. In summary, Java arrays are "usually safe; slightly constrained; often have overhead" while C++ native arrays "have optional overhead; are slightly unconstrained; are possibly unsafe."

Templates vs. generics

Both C++ and Java provide facilities for generic programming, templates and generics, respectively. Although they were created to solve similar kinds of problems, and have similar syntax, they are actually quite different.

C++ TemplatesJava Generics
Classes and functions can be templated.Classes and methods can be genericized.
Parameters can be any type, integral value, or character literal.Parameters can be reference types or boxed primitive types (i.e. Integer, Boolean...).
Separate copies of the class or function are likely to be generated for each type parameter when compiled.One version of the class or function is compiled, works for all type parameters.
Objects of a class with different type parameters are different types at run time.Type parameters are erased when compiled; objects of a class with different type parameters are the same type at run time. It just causes a different constructor. Because of this type erasure, it is not possible to overload methods using different instantiations of the generic class.
Implementation source code of the templated class or function must be included in order to use it (declaration insufficient).Signature of the class or function from a compiled class file is sufficient to use it.
Templates can be specialized—a separate implementation could be provided for a particular template parameter.Generics cannot be specialized.
Template parameters can have default arguments. (Prior to C++11, this was allowed only for template classes, not functions.)Generic type parameters cannot have default arguments.
Does not support wildcards. Instead, return types are often available as nested typedefs. (Also, C++11 added keyword auto, which acts as a wildcard for any type that can be determined at compile time.)Supports wildcard as type parameter.
Does not directly support bounding of type parameters, but metaprogramming provides this[12]Supports bounding of type parameters with "extends" and "super" for upper and lower bounds, respectively; allows enforcement of relationships between type parameters.
Allows instantiation of an object with the type of the parameter type.Does not allow instantiation of an object with the type of the parameter type (except through reflection).
Type parameter of templated class can be used for static methods and variables.Type parameter of templated class cannot be used for static methods and variables.
Static variables are not shared between classes of different type parameters.Static variables are shared between instances of classes of different type parameters.
Templated classes and functions do not enforce type relations for type parameters in their declaration. Use of an incorrect type parameter results in compilation failure, often generating an error message within the template code rather than in the user's code that invokes it. Proper use of templated classes and functions is dependent on proper documentation. Metaprogramming provides these features at the cost of additional effort.Generic classes and functions can enforce type relationships for type parameters in their declaration. Use of an incorrect type parameter results in a type error within the code that uses it. Operations on parametrized types in generic code are only allowed in ways that can be guaranteed to be safe by the declaration. This results in greater type safety at the cost of flexibility.
Templates are Turing-complete (see template metaprogramming).Generics are probably not Turing-complete.

Miscellaneous

  • Java and C++ use different techniques for splitting up code in multiple source files. Java uses a package system that dictates the file name and path for all program definitions. In Java, the compiler imports the executable class files. C++ uses a header file source code inclusion system for sharing declarations between source files.
  • Compiled Java code files are generally smaller than code files in C++ as Java bytecode is usually more compact than native machine code[citation needed] and Java programs are never statically linked.
  • C++ compilation features an additional textual preprocessing phase, while Java does not. Thus some users add a preprocessing phase to their build process for better support of conditional compilation.
  • Java's division and modulus operators are well defined to truncate to zero. C++ (prior to C++11) does not specify whether or not these operators truncate to zero or "truncate to -infinity". -3/2 will always be -1 in Java and C++11, but a C++03 compiler may return either -1 or -2, depending on the platform. C99 defines division in the same fashion as Java and C++11. Both languages guarantee (where a and b are integer types) that (a/b)*b + (a%b) == a for all a and b (b != 0). The C++03 version will sometimes be faster, as it is allowed to pick whichever truncation mode is native to the processor.
  • The sizes of integer types is defined in Java (int is 32-bit, long is 64-bit), while in C++ the size of integers and pointers is compiler and ABI dependent within given constraints. Thus, carefully written C++ code can take advantage of the 64-bit processor's capabilities while still functioning properly on 32-bit processors. However, this requires care and effort to ensure that the C++ source code is written in a portable manner. In contrast, Java's fixed integer sizes mean that programmer error in this regard are not possible, although this may incur a performance penalty since Java code cannot run using an arbitrary processor's word size.

Performance

In addition to running a compiled Java program, computers running Java applications generally must also run the Java virtual machine (JVM), while compiled C++ programs can be run without external applications. Early versions of Java were significantly outperformed by statically compiled languages such as C++. This is because the program statements of these two closely related languages may compile to a few machine instructions with C++, while compiling into several byte codes involving several machine instructions each when interpreted by a JVM. For example:

Java/C++ statementC++ generated code (x86)Java generated byte code
vector[i]++;mov edx,[ebp+4h]

mov eax,[ebp+1Ch]
inc dword ptr [edx+eax*4]

aload_1

iload_2
dup2
iaload
iconst_1
iadd
iastore

Certain inefficiencies are inherent to the Java language itself, primarily:

  • All objects are allocated on the heap. For functions using small objects this can result in performance degradation as stack allocation, in contrast, costs essentially zero. However, this advantage is obsoleted by modern JIT compilers utilising escape analysis or escape detection to allocate objects on the stack. Escape analysis was introduced in Oracle JDK 6.
  • Methods are virtual by default. This slightly increases memory usage by adding a single pointer to a virtual table per each object. It also induces a startup performance penalty, since a JIT compiler must perform additional optimization passes even for de-virtualization of small functions.
  • A lot of casting required even using standard containers induces a performance penalty. However, most of these casts are statically eliminated by the JIT compiler, and the casts that remain in the code usually do not cost more than a single CPU cycle on modern processors, thanks to branch prediction.
  • Array access must be safe. The compiler is required to put appropriate range checks in the code. The naive approach of guarding each array access with a range check is not efficient, so most JIT compilers generate range check instructions only if they cannot statically prove the array access is safe. Even if all runtime range checks cannot be statically elided, JIT compilers try to move them out of inner loops to make the performance degradation as low as possible.
  • Lack of access to low-level details prevents the developer from improving the program where the compiler is unable to do so.[13] Programmers can interface with the OS directly by providing code in C or C++ and calling that code from Java by means of JNI.

In contrast, various optimizations in C++ are either too difficult or impractical to implement:

  • Pointers make optimization difficult since they may point to arbitrary data. However, in some cases this is obsoleted as new compilers introduced a strict-aliasing rule[14] and because of support of the C99 keyword restrict.[15]
  • Java garbage collection may have better cache coherence than the usual usage of malloc/new for memory allocation, as its allocations are generally made sequentially. Nevertheless, arguments exist[weasel words] that both allocators equally fragment the heap and neither exhibits better cache locality.
  • Due to the lack of garbage collection in C++, programmers must supply their own memory management code, often in the form of reference-counted smart pointers.
  • Since the code generated from various concretisations of the same templated class in C++ is not shared, excessive use of templates may lead to significant increase of the executable code size.
  • Run-time compilation can potentially use additional information available at run-time to improve code more effectively, such as the processor on which the code will be executed. However, this claim is effectively made obsolete as most state-of-the-art C++ compilers generate multiple code paths to employ the full computational abilities of the given system[16]
  • Run-time compilation allows for more aggressive virtual function inlining than is possible for a static compiler, because the JIT compiler has complete information about all possible targets of the virtual call, even if they are in different dynamically loaded modules. Currently available JVM implementations have no problem in inlining most of the monomorphic, mostly monomorphic and dimorphic calls, and research is in progress to inline also megamorphic calls, thanks to the recent invoke dynamic enhancements added in Java 7.[17] Inlining can allow for further optimisations like loop vectorisation or loop unrolling, resulting in a huge overall performance increase.
  • Because dynamic linking is performed after code generation and optimisation in C++, function calls spanning different dynamic modules cannot be inlined.
  • Because thread support is provided by libraries in C++, C++ compilers have no chance to perform thread-related optimisations. In Java, thread synchronisation is built into the language, so the JIT compiler can, with the help of escape analysis, easily elide or coarse locks,[18] significantly improving performance of multithreaded code. This technique was introduced in Sun JDK 6 update 10 and is named biased locking.[19]

Official standard and reference of the language

Language specification

The C++ language is defined by ISO/IEC 14882, an ISO standard, which is published by the ISO/IEC JTC1/SC22/WG21 committee. The Java language is defined by the Java Language Specification,[20] a book which is published by Sun (now Oracle).

The Java language continuously evolves through a process called the Java Community Process, and the world's programming community is represented by a group of people and organizations - the Java Community members[21] - which is actively engaged into the enhancement of the language, by sending public requests - the Java Specification Requests - which must pass formal and public reviews before they get integrated into the language.
In contrast, the C++ programming community does not have this power, because the C++ language specification was statically defined by ISO.

Trademarks

"C++" is not a trademark of any company or organization and is not owned by any individual.[22] "Java" is a trademark of Sun Microsystems (now Oracle).[23]

References

  1. ^ "The Java Tutorials: Passing Information to a Method or a Constructor". Oracle. http://download.oracle.com/javase/tutorial/java/javaOO/arguments.html. Retrieved 17 February 2013.
  2. ^ "The Java Tutorials: Object as a Superclass". Oracle. http://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html. Retrieved 17 February 2013.
  3. ^ a b Robert C. Martin (January 1997). "Java vs. C++: A Critical Comparison" (PDF). http://www.objectmentor.com/resources/articles/javacpp.pdf.
  4. ^ "Reference Types and Values". The Java Language Specification, Third Edition. http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3. Retrieved 9 December 2010.
  5. ^ Horstmann, Cay; Cornell, Gary (2008). Core Java I (Eighth ed.). Sun Microsystems. pp. 140–141. ISBN 978-0-13-235476-9. "Some programmers (and unfortunately even some book authors) claim that the Java programming language uses call by reference for objects. However, that is false. Because this is such a common misunderstanding, it is worth examining a counterexample in some detail... This discussion demonstrates that the Java programming language does not use call by reference for objects. Instead object references are passed by value." 
  6. ^ Deitel, Paul; Deitel, Harvey (2009). Java for Programmers. Prentice Hall. p. 223. ISBN 978-0-13-700129-3. "Unlike some other languages, Java does not allow programmers to choose pass-by-value or pass-by-reference—all arguments are passed by value. A method call can pass two types of values to a method—copies of primitive values (e.g., values of type int and double) and copies of references to objects (including references to arrays). Objects themselves cannot be passed to methods." 
  7. ^ "Microsoft c++ compiler, /fp (Specify Floating-Point Behavior)". Microsoft Corporation. http://msdn.microsoft.com/en-us/library/e7s85ffb.aspx. Retrieved 19 march 2013.
  8. ^ "Java Language Specification 4.3.1: Objects". Sun Microsystems. http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3.1. Retrieved 9 December 2010.
  9. ^ Standard for Programming Language C++ '11, 5.3.2 Increment and decrement [expr.pre.incr].
  10. ^ The Java™ Language Specification, Java SE 7 Edition, Chapters 15.14.2 , 15.14.3, 15.15.1, 15.15.2, http://docs.oracle.com/javase/specs/
  11. ^ "Java memory leaks -- Catch me if you can" by Satish Chandra Gupta, Rajeev Palanki, IBM DeveloperWorks, 16 August 2005
  12. ^ Boost type traits library
  13. ^ Clark, Nathan; Amir Hormati, Sami Yehia, Scott Mahlke (2007). "Liquid SIMD: Abstracting SIMD hardware using lightweight dynamic mapping". HPCA’07: 216–227. 
  14. ^ Understanding Strict Aliasing - CellPerformance
  15. ^ Demystifying the Restrict Keyword
  16. ^ Targeting IA-32 Architecture Processors for Run-time Performance Checking
  17. ^ Fixing The Inlining “Problem” by Dr. Cliff Click | Azul Systems: Blogs
  18. ^ Oracle Technology Network for Java Developers
  19. ^ Oracle Technology Network for Java Developers
  20. ^ The Java Language Specification
  21. ^ The Java Community Process(SM) Program - Participation - JCP Members
  22. ^ Bjarne Stroustrup's FAQ: Do you own C++?
  23. ^ ZDNet: Oracle buys Sun; Now owns Java.

External links

    Sebelumnya  (Comparison of iOS e-book reade ...) (Comparison of Java virtual machines)  Berikutnya    





Tags: Comparison of Java and C++, Informatika, Komputer, 2233, Perbandingan Java and C Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations String functions List comprehension Object oriented programming Object oriented constructors Database access Evaluation strategy Daftar/Tabel, Hello World, programs ALGOL 58's influence on ALGOL 60 ALGOL 60: Comparisons with other langua, Comparison of Java and C++, Bahasa Indonesia, Contoh Instruksi, Tutorial, Referensi, Buku, Petunjuk unucirebon, prestasi.web.id
 Ensiklopedi Bebas    Download Brosur / Katalog    Peluang Karir    Permintaan Beasiswa Studi    Kelas Reguler Pagi    Berbagai Perdebatan    Program S2 (Pascasarjana, Magister)
Informasi PTS
Khusus Perguruan Tinggi Swasta
Terkemuka & Terakreditasi
STMIKMJ Jakarta
STIE IGI
STTM STIE WP
STEI Jogja
STIE Hidayatullah
STEBI Bina Essa
UMJ: FTan FISIP
Univ. Muhammadiyah Smrg
Univ. Muhammadiyah Sby
UNSUB
STMIK MJ UNKRIS
Univ. Thamrin: FE FASILKOM
ISTA ITBU
STIE Trianandra STIE IGI
STT Mandala Bandung
STMIK STIKOM Bali STTB
POLNAS Denpasar
STT Bina Tunggal Bks.
STIKI Malang
UNDARIS Semarang
INDOCAKTI
UPRI
STIE Hidayatullah Depok
UNISA Dharma Andigha
Universitas Nusantara
UHAMZAH
UTS Makassar
STT Duta Bangsa
STIE GICI IMWI Sukabumi
UNAKI KAHURIPAN
STEI Jogja STIE Pemuda
Universitas Mpu Tantular
USCND Langsa
USM INDONESIA STTM
UNUGHA UM Palangkaraya
STIE WD IKIP WD
STIE Ganesha Yuppentek
STT Muttaqien
STIT BATAM IAI AS
UCM STIE GEMA
Universitas Megou
STIE PIONEER
STIMAIMMI STIEABI
UPGRIS UICM Bandung
AL-AZHAR UNUSA
Tanri Abeng University
STIE AMKOP STIE WP
Univ. Boyolali UDB
UNIBA ITB AD
UNU KALBAR
Ubudiyah
ISIF
STEBI Global Mulia
STT Sapta Taruna
Universitas Bali Dwipa
UNU Kaltim UHS
Univetsitas IVET
CENDEKIA STAI DB
STIE Mitra STiPSi
UNIPI Bandung
STIE Al-Rifa'ie
UNTARA Pelita Bangsa
Patria Artha
Univ. Widya Kartika
UTN Bogor IGN Bogor
Parna Raya
STAI Terpadu Yogyakarta
STIT Al-Hikmah Lampung
Univ. Deli Sumatera
STIA Bayuangga
UI Mandiri
STAI Muhammadiyah Probolinggo
STEBI Bina Essa
STAI Muhammadiyah Tulungagung
Politeknik Harapan Bangsa Surakarta
STIKes Sapta Bakti
ITeKes Tri Tunas Nasional
STEBI Badri Mashduqi
STIA Maulana Yusuf
STAI Miftahul Ulum
STIH Gunung Jati
STIE PPI Balaraja
Poltekkes Kerta Cendekia
ITB Pelita Raya
Poltek Ganesha
Universitas Moch. Sroedji
STIT Al-Hidayah Tasikmalaya
STIT Nur Ahadiyah
Politeknik Aisyiyah
Politeknik Santo Paulus Surakarta
IAI Al-Ghurabaa Jakarta
STAI AL Akbar Surabaya
Universitas Mahakarya Asia Yogyakarta
Politeknik Bhakti Kartini
Univ. Muhammadiyah Smrg
STMIK MJ UNKRIS
Thamrin: FE FASILKOM
STT Bina Tunggal Bks.
STIKI Malang
UNDARIS Semarang
INDOCAKTI
UPRI
STIE Hidayatullah Depok
UNISA Dharma Andigha
Universitas Nusantara
UHAMZAH
UTS Makassar
STT Duta Bangsa
STIE GICI IMWI Sukabumi
UNAKI KAHURIPAN
STEI Jogja STIE Pemuda
Universitas Mpu Tantular
USCND Langsa
USM INDONESIA
UM Palangkaraya
UNUGHA STIE WD IKIP WD
STIE Ganesha Yuppentek
STT Muttaqien
STIT BATAM IAI AS
UCM STIE GEMA
Universitas Megou
STIE PIONEER
STIMAIMMI STIEABI
UPGRIS UICM Bandung
AL-AZHAR UNUSA
Tanri Abeng University
STIE AMKOP STIE WP
Univ. Boyolali UDB
UNIBA ITB AD
UNU KALBAR
Ubudiyah ISIF
STEBI Global Mulia
STT Sapta Taruna
Universitas Bali Dwipa
UNU Kaltim UHS
Univetsitas IVET
CENDEKIA STAI DB
STIE Mitra STiPSi
UNIPI Bandung
STIE Al-Rifa'ie
UNTARA Pelita Bangsa
Patria Artha
Univ. Widya Kartika
UTN Bogor IGN Bogor
Parna Raya
STAI Terpadu Yogyakarta
STIT Al-Hikmah Lampung
Univ. Deli Sumatera
STIA Bayuangga
UI Mandiri
STAI Muhammadiyah Probolinggo
STEBI Bina Essa
STAI Muhammadiyah Tulungagung
Politeknik Harapan Bangsa Surakarta
STIKes Sapta Bakti
ITeKes Tri Tunas Nasional
STEBI Badri Mashduqi
STIA Maulana Yusuf
STAI Miftahul Ulum
STIH Gunung Jati
STIE PPI Balaraja
Poltekkes Kerta Cendekia
ITB Pelita Raya
Poltek Ganesha
Universitas Moch. Sroedji
STIT Al-Hidayah Tasikmalaya
STIT Nur Ahadiyah
Politeknik Aisyiyah
Politeknik Santo Paulus Surakarta
IAI Al-Ghurabaa Jakarta
STAI AL Akbar Surabaya
Universitas Mahakarya Asia Yogyakarta
Politeknik Bhakti Kartini
MM UNKRIS MIKom Fisip UMJ MIA Fisip UMJ
MM STIE Mitra MM UNTARA MM Pelita Bangsa
MM STIE Ganesha
MM STIMAIMMI MM STIEABI
MM STIE IGI MM STIE GICI MKS ITB Ahmad Dahlan
MM IGN MKom IGN
KPT Konsultan Pendidikan Tinggi
Chatting dengan staf
Kuliah Karyawan

(silakan klik di bawah ini)
Penerimaan / Pendaftaran
__Mahasiswa Baru

Lokasi Kampus & Peta
Program Studi (D3, S1, S2)
___(+ Kurikulum & Prospektus)

Pascasarjana (S2)
Biaya Pendidikan
Sistem Pendidikan
Jadwal Kuliah & Dosen
Keunggulan-Keunggulan
Angkutan Umum


GALERI FOTO

Tabel Website Forum
Tabel Website Iklan
Tabel Website Pengumuman
Tabel Website Lowongan

Jaringan Web Gabungan PTS
Jaringan Web Gilland Group
Web Iklan Kelas Karyawan
Jaringan Portal Barterlink
Konsultan Pendidikan Tinggi

Kumpulan Web Kuliah Paralel
Kumpulan Web Kelas Reguler
Kumpulan Web Kelas Malam/Sore
Kumpulan Web Magister
Daftar Portal Ensiklopedia
Tabel Portal Ensiklopedi Dunia
 Kuliah Gratis    Program Kuliah Hybrid di 112 PTS Terbaik    Contoh Soal Try Out    Pendaftaran Online    Semua Reklame    Soal-Jawab Tes Psikologi    Tutorial Teknik Informasi    Jadwal Sholat    Al Qur'an Online    Program Kuliah Shift    Perkuliahan Eksekutif
Beritahu Rekan
Nama Saya

Email Saya

Email Rekan 1

Email Rekan 2 (tidak wajib)

Email Rekan 3 (tidak wajib)
⚽ harus diisi dengan benar

Permintaan Katalog/Brosur
(Gratis dikirim via POS)
Nama Penerima Katalog

Alamat Lengkap

Kota / Kabupaten & Provinsi

Kode Pos

Email (tidak wajib)

▥ harus diisi lengkap & jelas
Atau kirimkan nama dan
alamat lengkap via SMS ke HP:
0811 1990 9026


BROSUR GRATIS
Brosur Kelas Karyawan
Gabungan Seluruh Wilayah Indonesia

PDF (11,2 MB)ZIP (8,8 MB)
JPG (36,2 MB)
Brosur Kelas Karyawan
JABODETABEK

PDF (5,5 MB)ZIP (4,4 MB)
JPG (13,2 MB)
Brosur Kelas Karyawan
DIY,JATENG,JATIM & BALI

PDF (4,4 MB)ZIP (3,5 MB)
JPG (14,5 MB)
Brosur Kelas Karyawan
JAWA BARAT

PDF (2,8 MB)ZIP (2,2 MB)
JPG (7,1 MB)
Brosur Kelas Karyawan
SULAWESI

PDF (1,9 MB)ZIP (1,5 MB)
JPG (5,6 MB)
Brosur Kelas Karyawan
SUMATERA & BATAM

PDF (2,2 MB)ZIP (1,7 MB)
JPG (6,5 MB)
Brosur Khusus Reguler
PDF (4,1 Mb)ZIP (8,4 Mb)

Terobosan Baru
Meningkatkan
Pendapatan, Sumber Daya PTS dan Kualitas Pendidikannya
Rangkuman Tuntas, klik di bawah ini
http://kpt.co.id

PT. Gilland Ganesha
Membutuhkan Segera

  • Design Grafis
  • Programmer

Rangkuman Terperinci di :
Informasi karir

155 Jenis / Ras Kucing di Dunia

Desain tempat tidur kucing, sisir kucing, penyebab bulu rontok, dsb.

Facebook Kuliah Karyawan
Twitter Kuliah Karyawan

Link Khusus ke
PTS Terakreditasi & Terkemuka
Penyelenggara Program S1, D3, S2

(silakan klik di bawah ini)
STMIKMJ - STMIKMJ Jakarta
IGI - STIE IGI Jakarta
STTM Cileungsi - STIE Cileungsi
STIE WP - STIE Widya Persada
UPRI - UPRI Makassar
STEI - STEI Yogyakarta
STIE - Hidayatullah Depok
STEBI - Bina Essa
P2KKMPoliteknik Aisyiyah

P2KKMUMPTB Lampung
P2KKMSTIT Al-Hikmah Lampung

P2KKMUniv.Amir Hamzah
P2KKMUSM Indonesia
P2KKMUniv. Al-Azhar Medan
P2KKMUniversitas Deli Sumatera

P2KKMUniv. Muh. Palangkaraya

P2KKMSTIT Nur Ahadiyah

P2KKMUniv. Nahd. Ulama Kalbar

P2KKMUniv. Nahd. Ulama Kaltim

Langsa -- Aceh :
P2KKMUSCND Langsa

P2KKMUniv. Ubudiyah Indonesia

P2KKMSTIT Hidayatullah
P2KKMIAI Abdullah Said

P2KKMUniv. Pejuang Rep. Ind.
P2KKMUniv. Teknologi Sulawesi
P2KKMUniv. Cokroaminoto Makassar
P2KKMITeKes Tri Tunas Nasional

P2KKMUniv. Patria Artha

P2KKMUniv. Nusantara, Manado
P2KKMSTIE Pioneer Manado
P2KKMUniversitas Parna Raya Manado

P2KKMUniversitas Boyolali

P2KKMUniversitas Duta Bangsa
P2KKMPoliteknik Harapan Bangsa Surakarta
P2KKMPoliteknik Santo Paulus Surakarta

P2KKMUNIBABWI

P2KKMUniv. Muhammadiyah Smrg
P2KKMUNDARIS Semarang
P2KKMUNAKI Semarang
P2KKMUPGRIS Semarang
P2KKMUniv. IVET Semarang
P2KKMSTIE Cendekia

P2KKMUNUGHA Cilacap

P2KKMUniv. Muhammadiyah Sby
P2KKMSTIE Pemuda Sby
P2KKMIKIP Widya Darma Sby
P2KKMSTIE Widya Darma Sby
P2KKMSTIE ABI Surabaya
P2KKMUNUSA Surabaya
P2KKMUniv. Widya Kartika
P2KKMSTAI Al Akbar Surabaya

P2KKMUniv. Kahuripan Kediri

P2KKMSTAI Muhammadiyah Tulungagung

P2KKMSTIKI Malang
P2KKMSTIE INDOCAKTI
P2KKMSTIE Al Rifa'ie

P2KKMSTIA Bayuangga
P2KKMSTAI Muhammadiyah Probolinggo

P2KKMUniversitas Moch. Sroedji

P2KKMSTEI JOGJA - STEI Yogyakarta
P2KKMSTIE Mitra Indonesia
P2KKMSTiPsi
P2KKMSTAI Terpadu Yogyakarta
P2KKMUniversitas Mahakarya Asia

P2KKMSTIE Hidayatullah
P2KKMSTIE - GICI A
P2KKMSTIE - GICI A


P2KKMSTMIK-MJ - STMIK Muh. Jkt.
P2KKMUNKRIS - Krisnadwipayana
P2KKMSTT Bina Tunggal - Bekasi
P2KKMSTT Duta Bangsa - Bekasi
P2KKMSTIE - GICI C
P2KKMSTEBI Global Mulia
P2KKMUniversitas Pelita Bangsa
P2KKMUniversitas Indonesia Mandiri
P2KKMPoliteknik Bhakti Kartini

P2KKMSTMIK-STIKOM Bali
P2KKMPOLNAS Denpasar
P2KKMUniversitas Bali Dwipa
P2KKMPoltek Ganesha Guru Singaraja

P2KKMSTIE Ganesha
P2KKMSTT Yuppentek
P2KKMITB Ahmad Dahlan
P2KKMUniv. Tangerang Raya
P2KKMSTIA Maulana Yusuf
P2KKMSTIH Gunung Jati
P2KKMSTIE PPI Balaraja

P2KKMUNSUB - Universitas Subang

P2KKMSTIT Al-Hidayah Tasikmalaya

P2KKMSTIE Walisongo
P2KKMSTT Walisongo

P2KKMUniv. Islam Al-Ihya

P2KKMSTT Mandala, Bandung
P2KKMSTT Bandung
P2KKMSTIE Gema Widya Bangsa
P2KKMUniversitas Insan Cendekia Mandiri
P2KKMUniversitas Halim Sanusi
P2KKMUniversitas Persatuan Islam
P2KKMSTEBI Bina Essa

P2KKMSTT Dr. Khez Muttaqien

P2KKMIMWI Sukabumi

P2KKMSTIH Dharma Andigha
P2KKMUniversitas Teknologi Nusnatara

P2KKMSTT Muhammadiyah Cileungsi

P2KKMISTA - Institut ST Al Kamal
P2KKMSTIE IGI - Inter. Golden Inst.
P2KKM Univ. Mpu Tantular B

P2KKMU M J - Univ. Muh. Jkt

P2KKMFISIP UMJ - Univ. Muh. Jkt.
P2KKMFTan UMJ - Agroteknologi
P2KKMSTIE Trianandra Jakarta
P2KKMSTIE - GICI B
P2KKMSTIE Ganesha
P2KKMSTIMAIMMI Jakarta
P2KKMTanri Abeng University

P2KKMUMHT - Univ. MH. Thamrin
P2KKMFE UMHT - FE MH. Thamrin
P2KKMFASILKOM UMHT
P2KKMUNKRIS - Krisnadwipayana
P2KKMITBU - Inst. Tek. Budi Utomo
P2KKMSTIE Trianandra Jakarta
P2KKMSTMIK Muh. Jkt - Matraman
P2KKMSTMIK Muh. Jkt - Ciracas
P2KKMUniv. Mpu Tantular A
P2KKMSTT Sapta Taruna
P2KKMIAI Al-Ghurabaa Jakarta

P2KKMISIF - Institut Studi Islam Fahmina

P2KKMSTEBI Global Mulia

P2KKMSTIKes Sapta Bakti
P2KKMSTAI Miftahul ulum

P2KKMPoltekkes Kerta Cendekia

P2KKMPelita Raya Institute


KPT Konsultan Pendidikan Tinggi

Rujukan Tambahan
silakan klik
Pemain Terbaik Sepakbola
Pemberdayaan Perempuan
Ensiklopedia Dunia

1. Universitas Yarsi Pratama - Universitas Yarsi Pratama - Kampus : Jl. Aria Jaya Santika No. 7, Pasir Nangka, Kec. Tigaraksa, Kab. Tangerang, Banten
2. STIE Widya Persada Jakarta - Sekolah Tinggi Ilmu Ekonomi Widya Persada Jakarta - Kampus :Jl. Hj. Tutty Alawiyah No.486, RW.5, Kalibata, Kec. Pancoran, Kota Jakarta Selatan, Daerah Khusus Ibukota Jakarta 12740
3. UWIKA Surabaya - Universitas Widya Kartika Surabaya - Kampus UWIKA : Jl. Sutorejo Prima Utara II No.1, Kalisari, Kec. Mulyorejo, Kota Surabaya, Jawa Timur 60112
4. Universitas Wijaya Kusuma Surabaya - Universitas Wijaya Kusuma Surabaya - Kampus : Jl. Dukuh Kupang XXV No.54, Dukuh Kupang, Kec. Dukuhpakis, Surabaya, Jawa Timur 60225
5. Universitas Teknologi Sulawesi Makassar - Universitas Teknologi Sulawesi Makassar - Kampus UTS Makassar : Jl. Talasalapang No.51A, Karunrung, Kec. Rappocini, Kota Makassar, Sulawesi Selatan 90222
6. Universitas Teknologi Nusantara - Universitas Teknologi Nusantara - Kampus UTN : Jl. Kedung Halang Pemda pangkalan II No.66, RT.01/RW.02, Kedunghalang, Kec. Bogor Utara, Kota Bogor, Jawa Barat 16158
pascasarjana-teknik.com  |  s2-mm.com  |  s2-teknik.com  |  sbmpts.com  |  sipenmaru.com  |  snmpts.com  |  bidik-misi.web.id  |  pmb.web.id  |  p2k.nusamandiri.ac.id  |  p2k.cyber-univ.ac.id  |  unnur.web.id