Pular para o conteúdo

Conheça Walt Disney World

Criticism of Java

A number of criticisms have been leveled at Java programming language for various design choices in the language and platform. Such criticisms include the implementation of generics, the handling of unsigned numbers, the implementation of floating-point arithmetic, and a history of security vulnerabilities in the primary Java VM implementation HotSpot. Additionally, Java, especially its early versions, has been criticized for its performance compared to other programming languages. Developers have also remarked that differences in various Java implementations must be taken into account when writing complex Java programs that must be used across these implementations[1]

Contents

Language syntax and semantics

Generics

When generics were added to Java 5.0, there was already a large framework of classes (many of which were already deprecated), so generics were chosen to be implemented using erasure to allow for migration compatibility and re-use of these existing classes. This limited the features that could be provided by this addition as compared to other languages.[2][3]

Because generics were implemented using type erasure the actual type of a template parameter is unavailable at runtime. Thus, the following operations are not possible in java:[4]

public class MyClass<E> {
    public static void myMethod(Object item) {
        if (item instanceof E) {  //Compiler error
            ...
        }
        E item2 = new E();   //Compiler error
        E[] iArray = new E[10]; //Compiler error
    }
}

Unsigned integer types

Java lacks native unsigned integer types. Unsigned data is often generated from programs written in C and the lack of these types prevents direct data interchange between C and Java. Unsigned large numbers are also used in a number of numeric processing fields, including cryptography, which can make Java more inconvenient to use for these tasks.[5] Although it is possible to partially circumvent this problem with conversion code and using larger data types, it makes using Java cumbersome for handling unsigned data. While a 32-bit signed integer may be used to hold a 16-bit unsigned value losslessly and a 32-bit unsigned value would require a 64-bit signed integer, a 64-bit unsigned value cannot be stored easily using any integer type because no type larger than 64 bits exists in the Java language. In all cases, the memory consumed is doubled (This is only partially correct, since Java internally uses either 32- or 64-bit storage for shorter primitive types such as byte (8 bits), short (16 bits), boolean (1 bit)), and any logic that depends on the rules of two's complement overflow must typically be rewritten. If abstracted using functions, function calls become necessary for many operations which are native to some other languages. Alternatively, it is possible to use Java's signed integers to emulate unsigned integers of the same size, but this requires detailed knowledge of complex bitwise operations.[6]

Compound Value Types

Java lacks (compound) value types, such as structs in C/C++, bundles of data that are manipulated directly instead of indirectly via references. Value types can offer significant performance improvements and memory savings in some cases.[7] [8] [9] A typical example is Java's HashMap, which is internally implemented as an array of HashMap.Entry objects.[10] Because Java lacks value types, this array is actually an array of references (pointers) to Entry objects, which in turn contains references to key and value objects. Looking up something in the map requires inefficient double indirection. If Entry were a value type, the array could store pairs of key and value references directly, eliminating the first indirection, increasing locality and reducing memory usage and heap fragmentation. If Java further supported generic primitive types, primitive keys and values could be stored in the array directly, removing the second indirection.

Large Arrays

Java has been criticized for not supporting arrays of more than 231 - 1 (about 2.1 billion) elements. [11] [12] [13] This is a limitation of the language; the Java Language Specification, Section 10.4, states that:

Arrays must be indexed by int values... An attempt to access an array component with a long index value results in a compile-time error.[14]

Supporting large arrays would also require changes to the JVM.[15] This limitation manifests itself in areas such as collections being limited to 2 billion elements[16] and the inability to memory map files larger than 2 GB.[17] Java also lacks true multidimensional arrays (contiguously allocated single blocks of memory accessed by a single indirection), which limits performance for scientific and technical computing.[8]

Integration of Primitives and Arrays

The fact that arrays and primitives are somewhat special and need to be treated differently from (other) objects has been criticized[18], because it requires writing many variants when creating general libraries.

Floating point arithmetic

While Java's floating point arithmetic is largely based on IEEE 754 (Standard for Binary Floating-Point Arithmetic), certain features are not supported even when using the strictfp modifier, such as Exception Flags and Directed Roundings — capabilities mandated by IEEE Standard 754. Additionally, the extended precision floating-point types permitted in 754 and present in many processors are not permitted in Java.[19][20][21]

Performance

In the early days of Java (before the HotSpot VM was implemented in Java 1.3 in 2000) there were many criticisms of performance. Java has been demonstrated to run at a speed comparable with optimised native code, and modern JVM implementations are regularly benchmarked as one of the fastest language platforms available—typically within a factor of 3 relative to C/C++.[22]

Java's performance has improved substantially since the early versions.[23] Performance of JIT compilers relative to native compilers has in some optimized tests been shown to be quite similar.[23][24][25]

Java bytecode can either be interpreted at run time by a virtual machine, or it can be compiled at load time or runtime into native code which runs directly on the computer's hardware. Interpretation is slower than native execution, and compilation at load time or runtime has an initial performance penalty for the compilation. Modern performance JVM implementations all use the compilation approach, so after the initial startup time the performance is equivalent to native code.

Security

In 2010, targeting of Java security exploits increased significantly, resulting in Java becoming a common target. Often long-known security holes in the Java virtual machine are targeted. This is tied to high numbers of computers with Java installed and the high percentage of computers that have not been updated with Java security updates.[26]

Critics have suggested that updated versions of Java are not used because there is a lack of awareness by many users that Java is installed, there is a lack of awareness of many users of how to update Java, and (on corporate computers) many companies restrict software installation and are slow to deploy updates.[26][27]

See also

Notes

  1. ^ Wong, William (2002-05-27). "Write Once, Debug Everywhere". electronicdesign.com. http://electronicdesign.com/Articles/Index.cfm?ArticleID=2255&pg=3. Retrieved 2008-08-03. "So far, the "write-once, run-everywhere" promise of Java hasn't come true. The bulk of a Java application will migrate between most Java implementations, but taking advantage of a VM-specific feature causes porting problems." 
  2. ^ "Generics in Java". Object Computing, Inc.. http://www.ociweb.com/jnb/jnbJul2003.html. Retrieved 2006-12-09. 
  3. ^ "What's Wrong With Java: Type Erasure". 2006-12-06. http://www.safalra.com/programming/java/wrong-type-erasure/. Retrieved 2006-12-09. 
  4. ^ "Type Erasure". http://java.sun.com/docs/books/tutorial/java/generics/erasure.html. 
  5. ^ "Java libraries should provide support for unsigned integer arithmetic". Bug Database, Sun Developer Network. Oracle. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4504839. Retrieved 2011-01-18. 
  6. ^ Owen, Sean R. (2009-11-05). Java and unsigned integers "Java and unsigned int, unsigned short, unsigned byte, unsigned long, etc. (Or rather, the lack thereof)". http://darksleep.com/player/JavaAndUnsignedTypes.html Java and unsigned integers. Retrieved 2010-10-09. 
  7. ^ Java Grande Forum Panel (November 1998). "Java Grande Forum Report: Making Java Work for High-End Computing". SC98. http://www.javagrande.org/sc98/sc98grande.pdf. 
  8. ^ a b Moreira, J.E.; S. P. Midkiff, M. Gupta, P. V. Artigas, M. Snir, R. D. Lawrence (2000). "Java programming for high-performance numerical computing". IBM Systems Journal 39 (1). http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.13.1554&rep=rep1&type=pdf. "True rectangular multidimensional arrays are the most important data structures for scientific and engineering computing." 
  9. ^ Hutchinson, Ben. "The JVM needs Value Types". https://benhutchison.wordpress.com/2008/06/15/the-jvm-needs-value-types/. Retrieved 3 February 2012. 
  10. ^ "java.util.HashMap Source Code". JDK 7. Grepcode. http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/util/HashMap.java. Retrieved 3 February 2012. 
  11. ^ Arndt, Holger; Markus Bundschus, Andreas Naegele (July 2009). "Towards a Next-Generation Matrix Library for Java". 33rd Annual IEEE International Computer Software and Applications Conference 1: 460-467. http://www.holger-arndt.com/library/COMPSAC2009-ujmp-draft.pdf. "...it is not possible in Java to have arrays with more that 231 entries..." 
  12. ^ "Why does Java's Collection.size() return an int?". Stack Overflow. http://programmers.stackexchange.com/questions/108699/why-does-javas-collection-size-return-an-int. Retrieved 10 February 2012. 
  13. ^ Carpenter, Bob. "Big Bit-Packed Array Abstraction (for Java, C, etc.)". LingPipe Blog. http://lingpipe-blog.com/2010/07/28/big-bit-packed-array-abstraction-for-java-c-etc/. Retrieved 10 February 2012. 
  14. ^ James Gosling; Bill Joy, Guy Steele, Gilad Bracha. "The Java Language Specification (Third Edition)". Addison Wesley. http://java.sun.com/docs/books/jls/third_edition/html/arrays.html. Retrieved 6 February 2012. 
  15. ^ Lowden, James. "Proposal: Large arrays (take two)". Java.net coin-dev mailing list. http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000869.html. Retrieved 10 February 2012. 
  16. ^ [docs.oracle.com/javase/7/docs/api/java/util/Collection.html "java.util.Collection"]. Java™ Platform, Standard Edition 7 API Specification. docs.oracle.com/javase/7/docs/api/java/util/Collection.html. Retrieved 10 February 2012. 
  17. ^ "java.nio.ByteBuffer". Java™ Platform, Standard Edition 7 API Specification. http://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html. Retrieved 6 February 2012. 
  18. ^ primitive types considered harmful
  19. ^ Kahan, W.; Joseph D. Darcy (1998-03-01). "How Java's Floating-Point Hurts Everyone Everywhere" (PDF). http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf. Retrieved 2006-12-09. 
  20. ^ "Types, Values, and Variables". Sun Microsystems. http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3. Retrieved 2006-12-09. 
  21. ^ "Java theory and practice: Where's your point? Tricks and traps with floating point and decimal numbers". IBM. 2003-01-01. http://www.ibm.com/developerworks/java/library/j-jtp0114/. Retrieved 2011-11-19. 
  22. ^ "Computer Language Benchmarks Game: Java vs Gnu C++". Debian.org. http://shootout.alioth.debian.org/u64q/java.php. Retrieved 2011-11-19. 
  23. ^ a b J.P.Lewis and Ulrich Neumann. "Performance of Java versus C++". Graphics and Immersive Technology Lab, University of Southern California. http://scribblethink.org/Computer/javaCbenchmark.html. 
  24. ^ The Java is Faster than C++ and C++ Sucks Unbiased Benchmark
  25. ^ FreeTTS - A Performance Case Study, Willie Walker, Paul Lamere, Philip Kwok
  26. ^ a b "Researchers Highlight Recent Uptick in Java Security Exploits". http://www.infoq.com/news/2010/10/java-exploit-uptick. 
  27. ^ "Have you checked the Java?". http://blogs.technet.com/b/mmpc/archive/2010/10/18/have-you-checked-the-java.aspx. 

External links

Personal tools
  • Log in / create account
Namespaces

Variants
Actions
Navigation
Toolbox
Print/export