Criticism of Java explained

The Java programming language and Java software platform have been criticized for design choices including the implementation of generics, forced object-oriented programming, the handling of unsigned numbers, the implementation of floating-point arithmetic, and a history of security vulnerabilities in the primary Java VM implementation, HotSpot. Software written in Java, especially its early versions, has been criticized for its performance compared to software written in 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 work with all of them.[1]

Language syntax and semantics

Checked exceptions

Java introduced checked exceptions where a method must declare the checked exceptions it throws in the method signature. This can result in unnecessarily verbose boilerplate code. No major language has followed Java in implementing checked exceptions.

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 implemented using type erasure to allow for migration compatibility and re-use of these existing classes. This limited the features that could be provided, compared to other languages.[2] [3]

Because generics are implemented using type erasure the actual type of a template parameter E is unavailable at run time. Thus, the following operations are not possible in Java:[4] public class MyClass

Additionally, in 2016, the following example was found revealing Java to be unsound and in turn making JVMs which threw ClassCastExceptions or any other kind of runtime error technically non-conforming.[5] This was corrected in Java 10.

class Nullless

Noun-orientedness

By design, Java encourages programmers to think of a 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.[6] Steve Yegge argues that this causes an unnecessary restriction on language expressiveness because a class can have multiple functions that operate on it, but a function is bound to a class and can never operate on multiple types.[7]

Many other multi-paradigm languages support functions as a top-level construct. When combined with other features such as function overloading (one verb, multiple nouns) and generic functions (one verb, a family of nouns with certain properties), the programmer can decide whether to solve a specific problem in terms of nouns or verbs. Java version 8 introduced some functional programming features.

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.[8] Although it is possible to get around this problem using conversion code and 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 64-bit signed integer a 32-bit unsigned integer, there is no larger type to hold a 64-bit unsigned integer. In all cases, the memory consumed may double, and typically any logic relying on two's complement overflow must be rewritten. If abstracted, 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.[9] Some support for unsigned integer types was provided in JDK 8, but not for unsigned bytes and with no support in the Java language.[10]

Operator overloading

Java has been criticized for not supporting user-defined operators. Operator overloading improves readability,[11] so its absence can make Java code less readable, especially for classes representing mathematical objects, such as complex numbers and matrices. Java has only one non-numerical use of an operator: + and += for string concatenation. However, this is implemented by the compiler, which generates code to create StringBuilder instances. It is impossible to create user-defined operator overloads.

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 sometimes be faster and smaller than classes with references.[12] [13] For example, Java's HashMap is implemented as an array of references to HashMap.Entry objects,[14] which in turn contain references to key and value objects. Looking something up requires inefficient double dereferencing. If Entry were a value type, the array could store key-value pairs directly, eliminating the first indirection, increasing locality of reference and reducing memory use and heap fragmentation. Further, if Java supported generic primitive types, keys and values could be stored in the array directly, removing both levels of indirection.

Large arrays

Java has been criticized for not supporting arrays of 231 (about 2.1 billion) or more elements.[15] [16] 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.[17]
Supporting large arrays would also require changes to the JVM.[18] This limitation manifests itself in areas such as collections being limited to 2 billion elements[19] and the inability to memory map continuous file segments larger than 2 GB.[20] Java also lacks (outside of its 2D arrays) multidimensional arrays (contiguously allocated single blocks of memory accessed by a single indirection), which limits performance for scientific and technical computing.[21]

Integration of primitives and arrays

Arrays and primitives are somewhat special and need to be treated differently from classes. This has been criticized[22] because it requires many variants of functions when creating general-purpose libraries.

Parallelism

Per Brinch Hansen argued in 1999[23] that Java's implementation of parallelism in general, and monitors in particular, does not provide the guarantees and enforcements required for secure and reliable parallel programming. While a programmer can establish design and coding conventions, the compiler can make no attempt to enforce them, so the programmer may unwittingly write insecure or unreliable code.

Serialization

Java provides a mechanism for object serialization, where an object can be represented as a sequence of bytes that includes its data fields, together with type information about itself and its fields. After an object is serialized, it can later be deserialized; that is, the type information and bytes that represent its data can be used to recreate the object in memory.[24] This raises very serious theoretical and actual security risks.[25] [26]

Floating point arithmetic

Although Java's floating point arithmetic is largely based on IEEE 754 (Standard for Binary Floating-Point Arithmetic), some mandated standard features are not supported even when using the [[strictfp]] modifier, such as Exception Flags and Directed Roundings. The extended precision types defined by IEEE 754 (and supported by many processors) are not supported by Java.[27] [28] [29]

Lack of tuples

Java does not natively support tuples, resulting in a proliferation of third-party implementations which must be imported and handled by the programmer.[30]

Abstracted relationship between code and hardware

In 2008 the United States Department of Defense's Center Software Technology Support published an article in the "Journal of Defense Software Engineering" discussing the unsuitability of Java as the first language taught. Disadvantages 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".[31] In 2005 Joel Spolsky criticized Java as an overfocused part of universities' curricula in his essay The Perils of JavaSchools.[32] Others, like Ned Batchelder, disagree with Spolsky for criticizing the parts of the language that he found difficult to understand, claiming that Spolsky's commentary was more of a 'subjective rant'.[33]

Performance

Before 2000, when the HotSpot VM was implemented in Java 1.3, there were many criticisms of its performance. Java has been demonstrated to run at a speed comparable with optimized native code, and modern JVM implementations are regularly benchmarked as one of the fastest language platforms available  - typically no more than three times slower than C and C++.[34]

Performance has improved substantially since early versions.[35] Performance of JIT compilers relative to native compilers has been shown to be quite similar in some optimized tests.[35] [36] [37]

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

Game designer and programmer John 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 Advance. 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."[38]

Security

The Java platform provides a security architecture[39] 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 platform features and APIs which could be exploited by malware, such as accessing the local filesystem or network, or running arbitrary commands.

In 2010, there was a significant rise in malicious software targeting security flaws in the sandboxing mechanisms used by Java implementations, including Oracle's. These flaws allow untrusted code to bypass the sandbox restrictions, exposing the user to attacks. Flaws were fixed by security updates, but were still exploited on machines without the updates.[40]

Critics have suggested that users do not update their Java installations because they don't know they have them, or how to update them. Many organisations restrict software installation by users, but are slow to deploy updates.[41]

Oracle has been criticized for not promptly providing updates for known security bugs.[42] When Oracle finally released a patch for widely-exploited flaws in Java 7, it removed Java 6 from users' machines, despite it being widely used by enterprise applications that Oracle had stated were not impacted by the flaws.[43]

In 2007, a research team led by Marco Pistoia exposed another important flaw of the Java security model,[44] based on stack inspection. When a security-sensitive resource is accessed, the security manager triggers code that walks the call stack, to verify that the codebase of each method on it has authority to access the resource. This is done to prevent confused deputy attacks, which take place every time a legitimate, more privileged program is tricked by another into misusing its authority. The confused-deputy problem is a specific type of privilege escalation. Pistoia observed that when a security-sensitive resource is accessed, the code responsible for acquiring the resource may no longer be on the stack. For example, a method executed in the past may have modified the value of an object field that determines which resource to use. That method call may no longer be on the stack when it is inspected.

Some permissions are implicitly equivalent to Java's AllPermission. These include the permission to change the current security manager (and replace it with one that could potentially bypass the stack inspection), the permission to instantiate and use a custom class loader (which could choose to associate AllPermission to a malicious class upon loading it), and the permission to create a custom permission (which could declare itself as powerful as AllPermission via its implies method). These issues are documented in Pistoia's two books on Java Security.[45] [46]

Parallel installations

JIT related security challenges and possible exploits

JIT compilation fundamentally uses executable data, and thus poses security challenges and possible exploits.

See also

External links

Notes and References

  1. Web site: Write Once, Debug Everywhere. https://web.archive.org/web/20090321180726/http://electronicdesign.com/Articles/Index.cfm?ArticleID=2255&pg=3. 2009-03-21. electronicdesign.com. Wong. William. 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.. 2002-05-27. 2008-08-03.
  2. Web site: Generics in Java . Object Computing, Inc. . 2006-12-09 . dead . https://web.archive.org/web/20070102132948/http://www.ociweb.com/jnb/jnbJul2003.html . 2 January 2007 . dmy-all .
  3. Web site: What's Wrong With Java: Type Erasure . 2006-12-06 . 2006-12-09 . 22 July 2012 . https://web.archive.org/web/20120722203911/http://code.stephenmorley.org/articles/java-generics-type-erasure/ . dead .
  4. Web site: Type Erasure.
  5. Amin . Nada . Tate . Ross . 2016-10-19 . Java and scala's type systems are unsound: the existential crisis of null pointers . ACM SIGPLAN Notices . 51 . 10 . 838–848 . 10.1145/3022671.2984004 . 0362-1340. free .
  6. Web site: Java SE Specifications.
  7. Web site: Yegge. Steve. Execution in the Kingdom of Nouns.
  8. Web site: Oracle . Bug Database, Sun Developer Network . Java libraries should provide support for unsigned integer arithmetic . 2011-01-18 .
  9. Web site: Java and unsigned int, unsigned short, unsigned byte, unsigned long, etc. (Or rather, the lack thereof) . 2009-11-05. 2010-10-09. Sean R. . Owen.
  10. Web site: Unsigned Integer Arithmetic API now in JDK 8 (Joseph D. Darcy's Oracle Weblog). 15 May 2016.
  11. Web site: C++ Operator Overloading. 7 April 2016. 5 February 2020. 5 February 2020. https://web.archive.org/web/20200205133743/https://blog.miyozinc.com/core-tutorials/cpp/cpp-operator-overloading/. dead.
  12. Java Grande Forum Panel. Java Grande Forum Report: Making Java Work for High-End Computing. SC98. November 1998. 10 February 2012. 18 May 2013. https://web.archive.org/web/20130518233804/http://www.javagrande.org/sc98/sc98grande.pdf. dead.
  13. Web site: Hutchinson. Ben. The JVM needs Value Types. 3 February 2012. 2008-06-14.
  14. Web site: java.util.HashMap Source Code. JDK 8. zGrepCode. 6 August 2018.
  15. Book: http://www.holger-arndt.com/library/COMPSAC2009-ujmp-draft.pdf . ...it is not possible in Java to have arrays with more than 231 entries.... 10.1109/compsac.2009.67. 978-0-7695-3726-9. 10.1.1.471.7567. Towards a Next-Generation Matrix Library for Java. 2009 33rd Annual IEEE International Computer Software and Applications Conference. 460–467. 2009. Arndt. Holger. Bundschus. Markus. Naegele. Andreas. 14672978 .
  16. Web site: Why does Java's Collection.size return an int?. Stack Overflow. 10 February 2012. https://web.archive.org/web/20130326011311/http://programmers.stackexchange.com/questions/108699/why-does-javas-collection-size-return-an-int. 26 March 2013. dead.
  17. Web site: The Java Language Specification. Third. Addison Wesley. 6 February 2012. James Gosling. Bill Joy . Guy Steele . Gilad Bracha .
  18. Web site: Lowden. James. Proposal: Large arrays (take two). Java.net coin-dev mailing list. 24 March 2009 . 10 February 2012.
  19. Web site: java.util.Collection. Java™ Platform, Standard Edition 7 API Specification. 10 February 2012.
  20. Web site: java.nio.ByteBuffer. Java™ Platform, Standard Edition 7 API Specification. 6 February 2012.
  21. Moreira. J.E.. S. P. Midkiff . M. Gupta . P. V. Artigas . M. Snir . R. D. Lawrence . Java programming for high-performance numerical computing. IBM Systems Journal. 2000. 39. 1. 10.1.1.13.1554. True rectangular multidimensional arrays are the most important data structures for scientific and engineering computing. . 10.1147/sj.391.0021 . 21–56.
  22. Web site: Primitive Types Considered Harmful. Sherman R. Alpert (IBM). Java Report, November, 1998 (Volume 3, Number 11). 2015-11-18 . 1998.
  23. Web site: Brinch Hansen. Java's Insecure Parallelism. SIGPLAN. 2012-10-13. April 1999.
    alternate url
  24. https://www.geeksforgeeks.org/serialization-in-java/ Serialization and Deserialization in Java with Example
  25. https://dzone.com/articles/serialization-must-die Serialization Must Die
  26. Book: Bloch, Joshua. 2018. Effective Java. Addison-Wesley. 339–345. 978-0-13-468599-1.
  27. Web site: How Java's Floating-Point Hurts Everyone Everywhere . W. . Kahan . Joseph D. Darcy . 1998-03-01 . 2006-12-09.
  28. Web site: Types, Values, and Variables . Sun Microsystems . 2006-12-09.
  29. Web site: Java theory and practice: Where's your point? Tricks and traps with floating point and decimal numbers . IBM . 2003-01-01 . 2011-11-19.
  30. News: What's Wrong in Java 8, Part V: Tuples - DZone . 18 March 2023 . dzone.com . en.
  31. Web site: Computer Science Education: Where Are the Software Engineers of Tomorrow? . https://web.archive.org/web/20090412180717/http://www.stsc.hill.af.mil/CrossTalk/2008/01/0801DewarSchonberg.html . 2009-04-12 . The Pitfalls of Java as a First Programming Language [...] Students found it hard to write programs that did not have a graphic interface, had no feeling for the relationship between the source program and what the hardware would actually do, and (most damaging) did not understand the semantics of pointers at all, which made the use of C in systems programming very challenging.. U.S. DOD Software Technology Support Center . CrossTalk Jan 2008 . Robert B.K. Dewar . Edmond Schonberg . 2008-01-01 . 2015-03-15.
  32. Web site: Joel on Software - The Perils of JavaSchools . . Joel Spolsky . Joel Spolsky . December 29, 2005 . 2015-11-18 . "It's bad enough that JavaSchools fail to weed out the kids who are never going to be great programmers, which the schools could justifiably say is not their problem. Industry, or, at least, the recruiters-who-use-grep, are surely clamoring for Java to be taught. But JavaSchools also fail to train the brains of kids to be adept, agile, and flexible enough to do good software design".
  33. Web site: Joel Spolsky is a crotchety old man . . Ned Batchelder . Ned Batchelder . January 1, 2006 . 2016-02-02 . "Why does Joel pick out pointers and recursion as the two gatekeeper concepts? Because he found them difficult? As Tim Bray points out, Java is perfectly adept at recursion, and concurrency may be a more important and difficult concept to master in any case. The emphasis on recursion in Lisp languages is a bit over the top, and doesn't carry into other programming cultures. Why do people think it's so important for software engineering? Don't get me wrong: I love recursion when it's the right tool for the job, but that is just not that often to warrant Joel's focus on it as a fundamental concept.
    While we're hunting around for tough concepts that separate the men from the boys, what about the one that got Joel and I into a tussle two years ago: Exceptions. He doesn't like them, basically, because they confuse him. Is this any different than a Java guy not liking pointers? Yes, you can avoid exceptions and use status returns, but you can also try really hard to avoid pointers. Does that mean you should? So Joel's got the concepts he likes (pointers and recursion), and laments their decline, but doesn't seem to notice that there are newer concepts that he's never caught on to, which the Java kiddies feel at home with.".
  34. Web site: Computer Language Benchmarks Game: Java vs Gnu C++ . benchmarksgame.alioth.debian.org . 2011-11-19 . https://web.archive.org/web/20150113040554/http://benchmarksgame.alioth.debian.org/u64q/java.html . 13 January 2015 . dead .
  35. Web site: Performance of Java versus C++. J.P.Lewis. Ulrich Neumann. amp. Graphics and Immersive Technology Lab, University of Southern California.
  36. Web site: The Java Faster than C++ Benchmark. 15 May 2016.
  37. http://research.sun.com/techrep/2002/smli_tr-2002-114.pdf FreeTTS - A Performance Case Study
  38. Web site: Cell phone adventures . 2005-03-27 . 2015-11-10 . John Carmack's Blog . armadilloaerospace.com . John D. Carmack . John D. Carmack . dead . https://web.archive.org/web/20151124005023/http://armadilloaerospace.com/n.x/johnc/recent%20updates/archive?news_id=295 . 24 November 2015 . dmy-all .
  39. http://docs.oracle.com/javase/7/docs/technotes/guides/security/spec/security-spec.doc.html Java SE Platform Security Architecture
  40. Web site: Researchers Highlight Recent Uptick in Java Security Exploits.
  41. Web site: Have you checked the Java?. 25 November 2010. https://web.archive.org/web/20120921140402/http://blogs.technet.com/b/mmpc/archive/2010/10/18/have-you-checked-the-java.aspx. 21 September 2012. dead.
  42. Web site: Oracle knew about critical Java flaws since April . . 30 August 2012 . 30 August 2012.
  43. Web site: 'Silent but deadly' Java security update breaks legacy apps - dev. . 15 May 2016.
  44. Book: Pistoia. Marco. Banerjee. Anindya. Naumann. David A.. 2007 IEEE Symposium on Security and Privacy (SP '07) . Beyond Stack Inspection: A Unified Access-Control and Information-Flow Security Model . May 2007. IEEE. 149–163. 10.1109/sp.2007.10. 978-0-7695-2848-9. 4112294 .
  45. Book: Java 2 network security . 1999 . Prentice Hall . 978-0-13-015592-4 . Pistoia . Marco . 2. . ITSO networking series . Upper Saddle River, New Jersey.
  46. Book: Enterprise Java security: building secure J2EE applications . 2004 . Addison-Wesley . 978-0-321-11889-9 . Pistoia . Marco . Boston, Mass. Munich.
  47. Web site: Grimes . Roger A. . 2011-11-15 . Old Java versions breed new security exploits . 2023-09-10 . InfoWorld . en.
  48. Web site: Krill . Paul . 2012-05-04 . Oracle urges removal of older Java versions due to security risks . 2023-09-10 . InfoWorld . en.
  49. Web site: 2023-09-10 . Why should I uninstall older versions of Java from my system? . 2023-09-10 . Java.
  50. Web site: 2023-09-10 . Java 6 Auto-Update to Java 7 . 2023-09-10 . Oracle.