Criticism of Java

From Infogalactic: the planetary knowledge core
Jump to: navigation, search

A number of criticisms have been leveled at the Java programming language and the Java software platform for various design choices in the language and platform. Such criticisms include the implementation of generics, forced object-oriented programming only, 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, some of which the Java community (before it was a community) had claimed it would better. 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]

Language syntax and semantics

Generics

<templatestyles src="Module:Hatnote/styles.css"></templatestyles>

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 common template parameter E 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
    }
}

Noun-orientedness

<templatestyles src="Module:Hatnote/styles.css"></templatestyles>

By design, Java encourages programmers to think of a programming solution in terms of nouns (classes) interacting with each other, and to think of verbs (methods) as operations that can be performed on or by that noun.[5] In the early days of Java, many argued that this caused an unnecessary restriction on language expressiveness because of the fact that a class can have multiple functions that operate on it, but a method is bound to a class and can never operate on multiple types.[6] This was due to the fact that new programmers often tried to port their style from the languages they already knew when learning Java, even to the point of calling a method by the term more familiar to them: 'function'. This often resulted in those Java developers spending large amounts of time writing trivial classes that exist only to perform a handful of functions on other classes.[citation needed] Good practices and proper blueprints solve this problem; Static classes, method overloading, Interfaces, Generics and the Collections framework also address the strongly typed nature of the language and allow the same method to be executed in multiple classes and to accept virtually infinite combinations of parameters. What was once a puzzle for newcomers is now easily solved using nothing but structures inside the language that have often been the result of the JCP (Java Community Process) improving the specification. The Java Community Process has also started to include constructs derived from functional programming into the Java Specification since Java 8.

Note that in many other multi-paradigm languages, there is support for functions as a top-level construct. When combined with other language features such as Function Overloading (one verb, multiple nouns) and/or Generic Functions (one verb, a family of nouns with certain properties), the programmer is given the ability to decide whether it makes more sense to solve a specific problem in terms of nouns or verbs. Java version 8 introduced some functional programming features.

Hidden relationship between code and hardware

In 2008 the U.S. DOD's Center Software Technology Support published in the "Journal of Defense Software Engineering" an article discussing the unsuitableness of Java as first learned programming language in education. Disadvantages given for Java as first language were that students "had no feeling for the relationship between the source program and what the hardware would actually do" and the impossibility "to develop a sense of the run-time cost of what is written because it is extremely hard to know what any method call will eventually execute".[7] Similarly Joel Spolsky in 2005, criticised Java as overfocused part of universities' curriculum in his essay The Perils of JavaSchools.[8] Others, like Ned Batchelder, disagree with Joel Spolsky for criticizing the parts of the language that he found difficult to understand, making Joel's commentary more of a subjective rant.[9]

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.[10] 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 may increase by a factor of up to two, 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 bitwise operations.[11] Some support for unsigned integer types were provided in JDK 8, but not for unsigned bytes and with no support in the Java language.[12]

Compound value types

Java lacks compound value types, such as structs in 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.[13][14][15] A typical example is Java's HashMap, which is internally implemented as an array of HashMap.Entry objects.[16] 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.[17][18][19] 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.[20]

Supporting large arrays would also require changes to the JVM.[21] This limitation manifests itself in areas such as collections being limited to 2 billion elements[22] and the inability to memory map files larger than 2 GB.[23] 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.[14]

There is no efficient way to initialize arrays in Java. When declaring an array, the JVM compiles it to bytecodes with instructions that set its elements one by one at runtime. Because Java methods cannot be bigger than 64KB, arrays of even modest sizes with values assigned directly in the code will throw the message "Error: code too large" on compilation.[24]

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,[25] because it requires writing many variants when creating general libraries.

Parallelism

Per Brinch Hansen argued in 1999[26] that Java's implementation of parallelism in general and monitors in particular do not provide the guarantees and enforcements required for secure and reliable parallel programming. While it is possible for a programmer to establish design and coding conventions to, say, only access thread-global variables in a controlled fashion, the language and compiler make no attempt to enforce that controlled access. I.e. the programmer may mistakenly allow uncontrolled access to thread-global variables, and the compiler will not detect it.

Floating point arithmetic

Although 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.[27][28][29]

Performance

<templatestyles src="Module:Hatnote/styles.css"></templatestyles>

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 and C++.[30]

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

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 performant JVM implementations all use the compilation approach, so after the initial startup time the performance is similar to native code. Note however, that Java's native code will still be bloated due to its excessive abstraction levels, taking more memory and running slower than code compiled in other languages not as over-engineered.

Game designer and programmer John D. Carmack concluded in 2005 about Java on cell-phones: "The biggest problem is that Java is really slow. On a pure cpu / memory / display / communications level, most modern cell phones should be considerably better gaming platforms than a Game Boy Advanced. With Java, on most phones you are left with about the CPU power of an original 4.77 mhz (sic) IBM PC, and lousy control over everything."[34]

Security

<templatestyles src="Module:Hatnote/styles.css"></templatestyles>

The Java platform provides a security architecture[35] which is designed to allow the user to run untrusted bytecode in a "sandboxed" manner to protect against malicious or poorly written software. This "sandboxing" feature is intended to protect the user by restricting access to certain platform features and APIs which could be exploited by malware, such as accessing the local filesystem, running arbitrary commands, or accessing communication networks.

In 2010, there was a significant increase in the prevalence of malicious software targeting security flaws in the sandboxing mechanism in multiple commonly used Java implementations, including Oracle's. These flaws allow untrusted code to bypass the sandbox restrictions, exposing the user to malicious attacks. Targeted security flaws that have already been fixed by security updates from the JVM maintainers have been exploited in computers without the security updates.[36]

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.[36][37]

Oracle has been criticised for not providing Java security updates for known security bugs, for long periods of time, despite these security bugs having known exploits.[38] When Oracle finally acted to patch against widely exploited flaws in Java 7, they deleted Java 6 on the users' machines in spite of this being widely used by enterprise applications that Oracle had claimed were not impacted by the flaws.[39]

Multiple parallel Java installations

With Java versions prior to 7, it was normal for the installer to not detect or remove prior Java installations. It was quite common on a Windows computer to see multiple installations of Java 6 on the same computer, varying only by update revision. Multiple Javas are permitted and can be accessed by programs that look for specific versions.

This has the effect that new Java installations only provide new language features and bug fixes, but they do not correct security vulnerabilities, because malicious programs can look for the older prior Java releases and use them rather than the newest versions.

Java 7 updated prior versions of itself, but did not look for the presence of Java 6 and earlier.

The current Java 8 now looks for any prior versions and offers to remove them during installation.

No automatic self-update capability

As of 2014, other common 3rd party tools such as Adobe Flash and Adobe Reader that have also been the subject of security vulnerability scrutiny have moved to an automatic self-update model on Windows that does not require any user intervention. This assures that security issues are promptly resolved without requiring additional effort by the system users or administrators.

As of 2015, Java 8 still requires that the computer user manually apply Java updates themselves. These updates can only be applied by those with administrator privileges. The Windows Java updater frequently triggers a disruptive random User Account Control elevation prompt; however, choosing Yes or No for elevation will still yield the same "Java needs to be updated" message.

See also

Notes

  1. Lua error in package.lua at line 80: module 'strict' not found.
  2. Lua error in package.lua at line 80: module 'strict' not found.
  3. Lua error in package.lua at line 80: module 'strict' not found.
  4. Lua error in package.lua at line 80: module 'strict' not found.
  5. Lua error in package.lua at line 80: module 'strict' not found.
  6. Lua error in package.lua at line 80: module 'strict' not found.
  7. Lua error in package.lua at line 80: module 'strict' not found.
  8. Lua error in package.lua at line 80: module 'strict' not found.
  9. Lua error in package.lua at line 80: module 'strict' not found.
  10. Lua error in package.lua at line 80: module 'strict' not found.
  11. Lua error in package.lua at line 80: module 'strict' not found.
  12. Lua error in package.lua at line 80: module 'strict' not found.
  13. Lua error in package.lua at line 80: module 'strict' not found.
  14. 14.0 14.1 Lua error in package.lua at line 80: module 'strict' not found.
  15. Lua error in package.lua at line 80: module 'strict' not found.
  16. Lua error in package.lua at line 80: module 'strict' not found.
  17. Lua error in package.lua at line 80: module 'strict' not found.
  18. Lua error in package.lua at line 80: module 'strict' not found.
  19. Lua error in package.lua at line 80: module 'strict' not found.
  20. Lua error in package.lua at line 80: module 'strict' not found.
  21. Lua error in package.lua at line 80: module 'strict' not found.
  22. Lua error in package.lua at line 80: module 'strict' not found.
  23. Lua error in package.lua at line 80: module 'strict' not found.
  24. title=Java in a Nutshell|author=David Flanagan|page=77
  25. Lua error in package.lua at line 80: module 'strict' not found.
  26. Lua error in package.lua at line 80: module 'strict' not found.; alternate url
  27. Lua error in package.lua at line 80: module 'strict' not found.
  28. Lua error in package.lua at line 80: module 'strict' not found.
  29. Lua error in package.lua at line 80: module 'strict' not found.
  30. Lua error in package.lua at line 80: module 'strict' not found.
  31. 31.0 31.1 Lua error in package.lua at line 80: module 'strict' not found.
  32. Lua error in package.lua at line 80: module 'strict' not found.
  33. FreeTTS - A Performance Case Study, Willie Walker, Paul Lamere, Philip Kwok
  34. Lua error in package.lua at line 80: module 'strict' not found.
  35. Java SE Platform Security Architecture. Oracle. Retrieved 2013-04-23.
  36. 36.0 36.1 Lua error in package.lua at line 80: module 'strict' not found.
  37. Lua error in package.lua at line 80: module 'strict' not found.
  38. Lua error in package.lua at line 80: module 'strict' not found.
  39. Lua error in package.lua at line 80: module 'strict' not found.

External links

de:Java (Technik)#Kritik