Table of Contents for Programming Languages: a survey
Java
Because it is so well-known, Java gets its own chapter.
Java Attributes
Java Pros
Java Cons
- memory hog
- long initial startup time
- type erasure [1]
JVM Pros
- runtime profiling and monitoring tools, runtime bytecode instrumentation
- dynamic class loading
- safety (no segfault/null pointer error crashes)
JVM Cons
Java Best practices and style guides
Java Respected exemplar code
Java Retrospectives and whitepapers
Java Opinions
- "uses abstractions on the same level as Java (higher than C, lower than Clojure), designed as a blue-collar language, emphasizes readability (at the expense of verbosity), and generally avoids low-level bit-diddling as well as high-level meta-programming tricks." -- https://news.ycombinator.com/item?id=7023390
- "Java is a blue collar language. It’s not PhD? thesis material but a language for a job. Java feels very familiar to many different programmers because I had a very strong tendency to prefer things that had been used a lot over things that just sounded like a good idea." -- James Gosling, http://dfjug.org/thefeelofjava.pdf
- "Java encouraged a limited “pure object-oriented” view of programming with a heavy emphasis on run-time resolution and a de-emphasis of the static type system (only in 2005 did Java introduce “generics”)." -- [3]
- "the Java object model inhibits performance where abstraction is seriously used" -- [4]
- "One way of viewing Java is as a somewhat restricted version of Smalltalk’s run-time model hidden behind a C++-like syntax and statically type-checked interfaces." -- [5]
- "At the core of the Java ecosystem is the JVM. Most people talk about Java the language, and this may sound odd coming from me, but I could hardly care less. What I really care about is the Java Virtual Machine as a concept, because that is the thing that ties it all together; it's the thing that makes Java the language possible; it's the thing that makes things work on all kinds of different platforms; and it makes all kinds of languages able to coexist." -- James Gosling, the 'father of Java'
- "My guess is that Java’s real strength compared to C++ is the binary compatibility gained from Sun having de facto control of the linker as expressed through the definition of the Java virtual machine. This gives Java the link compatibility that has eluded the C++ community because of the decision to use the basic system linkers and the lack of agreement among C++ vendors on key platforms (§7.4)." -- [6]
- "For my money, Java is a pretty good language; there are only a couple of things that I think were real mistakes in the core language. And the JVM certainly performs. But the ecosystem around Java is very complex and hard to manage. Dealing with JVM configuration, webserver configuration, build system configuration, IDE configuration and God knows what else takes up all kinds of brain-space. And every so often the community goes off on some crusade. Everything must be Design Patterns. Everything must be specified in XML. Everything must be a Bean. No, everything must be Injection. No, no, everything must be Annotation. The Java culture really needs to learn the value of the simple and explicit." [7]
- "Java doesn't require an IDE either: emacs/Ant/Maven is all I've ever used. Barring specialized platform-specific toolsets (like Android Studio) you don't NEED anything else (you might WANT something else, but that's a separate issue...)" [8]
- "Java is 100-ton dinosaur to be working with using a simple editor. Spring, it dependencies, hibernate, junit alone make you want to work with an IDE." [9]
- "Green threads are awkward to express with the JVM threading/memory/io model." [10]
- https://news.ycombinator.com/item?id=11387683
- "Java won for a bunch of reason: 1) It’s fast. Like almost C/C++ fast. Yes like any language you can write crappy slow code in Java but it is fast by default. 2) While certainly not an easy language it is a simple language. The number of footguns in Java is pretty small. There’s only a little of magic that languages like Ruby and Python have. Which of course means the programmer has to be more specific and add lots of boilerplate. And if you get it wrong the compiler yells loudly. And there’s none of the memory management ceremony from C/C++ that everyone gets wrong constantly. GC can lead to hard to explain madness but your basic enterprise CRUD app is never going to see that. 3) The standard library is awesome. Things like Java collections and concurrency just work: no fuss. And when you need to reach into the back of the tool cabinet the defacto STL provided by Apache is incredible. Need something super specialized like an ordered bidi map in a tree? Apache’s got one and I have faith it’s well tested, decently performant and has good documentation..." [11]
- "Java also has some particular deficiencies that have been cleaned up by newer languages: Kotlin adds “data class”, which are values (equality, hashing, printing) I think Scala case classes are pretty similar Python also added dataclass late in its life. This was also a deficiency, but Python at least has tuples and dicts, and free functions, so you weren’t forced to put everything in a class. Java didn’t have this. Java lacks free functions. It confuses classes and namespaces, which is extremely miseadling and leads to bad design (which I’ve seen many times in real life). In the way I use Python and C++, classes and namespaces are very much distinct and orthogonal. " [12]
- "I have a completely opposite opinion. Java is not the best language out there, I prefer Scala and Kotlin, but the selling point for me is the ecosystem: great tooling (tools simply work in lots of cases), great platform (lots of platforms are covered, really awesome backward compatibility, stability), great API (it might be far fetched, but I have a feeling that Java’s stdlib is one of the most feature-packed runtimes out there, if not the most?)." [13]
- "Java is a horrible language. No mortal can mentally hold on to a class hierarchy where inheritance is more than a few levels deep. Furthermore it is a bad way to add “another layer of abstraction” , because it just paints you more and more into a corner. (Clojure is a great language, you can add layers of abstraction to solve problems, without just digging yourself deeper.) " [14]
- "I don’t agree that Java is a good language at all, but I wanted to hard-agree at the distaste for magic annotations and DI frameworks. " [15]
- "Java simply feels good to write. A lot of this is due to the craftsmanship JetBrains? puts into IntelliJ? IDEA. Everything is autocompleted, jump-to-definition is fast, find-usage works well, and refactoring is easy. However, where Java truly shines is the developer experience with third-party libraries....I don't think the current affinity for third-party dependencies is particularly harmful, but upstream API changes can wreak havoc on untyped JS/Python code bases. When consuming third-party libraries in Java, you always know exactly what types need to be passed to a method. Most importantly, incorrect usage of a function will result in red squigglies in your editor." [16]
- "There are a number of disadvantages with dynamic/duck/weak/whatever typing. When a dependency changes an API method and your application fails at runtime rather than build time that's a problem. When a developer has to refer back to the implementation of a method to figure out which types to pass it, that's a waste of time. TypeScript? and Python type hints solve this problem a bit, but they lack the ability to validate passed types at runtime without extra code...Unlike TypeScript? definitions, Java's nominal type systems takes load off the programmer's brain by crystallizing type definitions and guaranteeing type guards by default." [17]
- "How many languages can you think of that meet the following conditions? Quality package manager and build system (I (heart) Maven) Nominal typing Large community Hands-off optimization I think the only qualifying tool is Java, but let me know if there are others! edit: As Jwosty pointed out Microsoft's Java competitor C# has all these characteristics and more/newer language features." [18] (note: by 'hands-off optimization e means good performance)
- https://danluu.com/boring-languages/ contains a list of important software written in Java
- "I used to really love Java, it was my second "real" programming language after C/C++, and GC, type safety, and object orientation really changed the way I thought. I also learned almost all I knew about high-performance VMs (up to 2013) in the context of JVMs. But these days it seems like Java is engaged in one long apology for the "everything is an object" mindset it started out with. It both took it too far and not far enough. Erased generics were the start of the problem. Parametric types! You were the chosen one! You were supposed to unify the primitive types and the object types! And never adding syntax for function types, just single-method interfaces...just ugly and clunky IMHO. C# did generics right. Well, almost. "void" isn't a real type, so you can't be generic over it. It is really important in language design that generics can range over any type. It allows the full combinatorial space. I worked really hard to make the Virgil compiler support arbitrary combinations of tuples, arrays, function types, and all of those work together seemlessly in the polymorphic type system. Everything else is a unfortunate shortcut, IMHO." [19]
- "Am I the only one who's seeing "sealed" classes as an unfortunate development? I can't count how many times I had to resolve to using PowerMock? and hacking bytecode just to mock something in one of the libraries I use because it's ingenious author "final"-ed the whole API surface of the library (and bits of the implementation usually). Now this gives even greater tool to people who love to lock everything up and think that they know better than me what I need. " [20]
- https://elizarov.medium.com/a-tribute-to-java-c184cd97db8f
Java Opinionated comparisons
- ""C++ is too complex, too unsafe, and too hard to maintain, and Python is too slow."...Which is why Java gets used instead." -- https://news.ycombinator.com/item?id=9712768
- "In those Techempower benchmarks Java destroyed Go for web app style requests. And given that the JVM is so dominant in big data (e.g. Spark, Storm), online betting and applications like high frequency trading you could make the reasonable assumption that Java is anything but slow." -- https://news.ycombinator.com/item?id=9713282
- "I also used Erlang and in my experience the JVM can achieve much lower latency and better throughput. Where Erlang systems tend to shine is in being more resilient and adaptable." -- https://news.ycombinator.com/item?id=9763236
- "I’ve been working to suppress the strong feelings I used to have against Java. I still dislike it as a language and the way of programming it encourages, though. I revisited it a couple of years ago to write some Android apps and nope, still not my cup of tea. Everything just feels convoluted and over engineered, I’d constantly think how much simpler this is in Python or Perl or Ruby or JavaScript?. It’s a very programmer-centric view, I’m aware, mostly based in what I enjoy in the day to day, which doesn’t necessarily make sense from a business perspective. There’s a reason why big companies go to Java; I recognize there’s a lot of top of the class software written in it, and it’s fast. I don’t have the background to make a serious assessment of the JVM but I’m pretty sure it’s an amazing piece of software." [21]
- vs Lisp, Rust: https://renato.athaydes.com/posts/revisiting-prechelt-paper-comparing-languages.html
- "Java's FFI and value type situation are the two major missing pieces for Java gamedev. C# has better stories for both, and has from the beginning. Don't confuse Java having the fastest GC with Java being the fastest GC'd language (especially not in all situations) " [22]
- vs Kotlin: https://elizarov.medium.com/why-im-not-enthusiastic-about-java-10-b2d789b6d42a
Java Popularity
- Popular, but also disliked by many
Java Tours and tutorials
Java Specs
Java Implementations
Java also attempted to be a platform to run 'applets' in the web browser. It wasn't so successful. Some reasons given have been:
- users don't bother to download and install the Java browser plugin
- "the Java applet didn't have direct access to the DOM bindings. Instead, the applet rendered it's own GUI via the plugin, and the look and behavior was inconsistent with the rest of the browser experience. A similar story with activex and flash." [23]
- slow [24]
Variants:
- "Lightweight Java Lightweight Java (LJ) is an imperative fragment of Java. It is intended to be as simple as possible while still retaining the feel of Java. LJ includes fields, methods, single inheritance, dynamic method dispatch, and method overriding. It does not include support for local variables, field hiding, interfaces, inner classes, or generics. LJ is largely a simplification of Middleweight Java (MJ). A major difference w.r.t. Featherweight Java (FJ) is that LJ also models state, whereas FJ is purely functional. In this sense, LJ is similar to ClassicJava?; however, unlike ClassicJava?, LJ is a proper subset of Java, i.e. every LJ program is a valid Java program."
- Featherweight Java
- Middleweight Java
- Classic Java
Java Popular libraries outside of stdlib
frameworks:
Java Features
Links about features:
Safety
Java guarantees no segfault/null pointer error crashes. This simple idea is an innovative one, particularly in light of its high performance and usage of an intermediate bytecode representation; in fact, this safety property is present in the JVM itself, not just at the Java level; the JVM won't run bytecode that might cause a segfault.
No implicit narrowing conversions [25]. However, "It can catch people by surprise that Java's narrowing conversions may not preserve the sign. For example, the following is broken:
class TimestampedObject? implements Comparable<TimestampedObject?> { long timestamp; int compareTo(TimestampedObject? other) { return (int)(timestamp - other.timestamp); } ... }
ErrorProne? catches this: https://errorprone.info/bugpattern/BadComparable " [26]
Closures with immutable upvalues
http://lambda-the-ultimate.org/node/4735#comment-75278
Pass-by-?
Primitives are passed by value; object references are passed by value.
(it is often said that objects are 'passed by reference' in Java, but as [27] points out, that's not quite correct, as you cannot write a 'swap' function in Java)
Gotchas
Internals and implementations
Core data structures: todo
Number representations
Integers
Floating points todo
array representation
Java arrays are typically stored with a length header [29].
Java array lengths are immutable (once set; you can have a data type of an array of uncertain length)
java vectors (resizable arrays) use arrays internally to have a block of memory to grow into [30].
Java multidimensional arrays are stored as a row of pointers, where each pointer points to a columnar slice [31] [32]
Java array have a maximum size [33], typically close to Integer.MAX_VALUE, typically around 2^31.
string representation
Java strings are arrays of chars. [34]
Since Java arrays are typically stored with a length header, this means they are 'Pascal-style' strings.
Representation of structures with fields
todo
Internals and implementation links
Java tools
Implementations
Links