When comparing Java vs Clojure, the Slant community recommends Clojure for most people. In the question“What is the best programming language to learn first?” Clojure is ranked 19th while Java is ranked 22nd. The most important reason people chose Clojure is:
Clojure programmers are highly encouraged to use immutable data in their code. Therefore, most data will be immutable by default. State change is handled by functions (for transformations) and atoms (an abstraction that encapsulates the idea of some entity having an identity).
Ranked in these QuestionsQuestion Ranking
Pro Fantastic IDEs
Because Java is statically typed, integrated development environments (IDEs) for Java can provide a lot more feedback on errors you will encounter. Java IDEs can give you specific errors in the location where they occur without having to run the code every time. This makes is faster to debug and learn from your mistakes.
IDEs also have extensive auto complete capabilities that can help you learn the programming libraries you are using faster and tell you what functions are available.
Pro Most commonly used language in industry
Pro Consistent programming standards
Most Java code follows very standardized coding styles. This means that when you're starting out, there are fewer questions about how you should implement something as the programming styles and patterns are well established and consistent. This consistent style means that it's often easier to follow others' example code, and that it's more likely to meet at least a certain minimum standard of quality. This discipline with consistent stylistic standards also becomes useful later, when collaborating on projects with larger teams.
Pro Best introduction to "C style" languages
The Java syntax is very similar to other C style languages. Learning the fundamentals of Java will port over well to other languages so you can apply what you've leaned to other languages afterwards.
Pro Introduces you to object oriented languages
Object Oriented Programming (OOP) is a paradigm that teaches you to split your problem into simpler modules with few connections between them; it's the most common paradigm used in industry. Java is the best choice as an introduction to object oriented languages because, as a statically-typed OOP-only language, it very clearly highlights core OOP principles such as encapsulation, access control, data abstraction, and inheritance.
While a scripting language provides more flexibility and terseness, learning a scripting language first would not instill these fundamental concepts as well, as they tend to obscure details such as how types work, and are less encouraging of an object oriented style.
Pro Platform Independent
Because of the Java Virtual Machine, the Java programming language is supported wherever a JVM is installed.
Pro Massive amount of libraries and APIs
Java has been around for such a long time that there have been tens of thousands of APIs and libraries written for almost anything you want to do.
Pro Immutability is the default
Clojure programmers are highly encouraged to use immutable data in their code. Therefore, most data will be immutable by default.
State change is handled by functions (for transformations) and atoms (an abstraction that encapsulates the idea of some entity having an identity).
Pro Minimal syntax
Being a LISP, programs are simple: they're just functions and data. That it doesn't get bogged down with syntax or the loftier FP concepts like monads makes it one of most approachable functional languages for beginners.
Pro Tries to solve problems as simply as possible
Simplicity is one of the pillars on which Clojure is built. Clojure tries to solve many problems in software development as simply as possible. Instead of building complex interfaces, objects or factories, it uses immutability and simple data structures.
Pro Good for writing concurrent programs
Since Clojure is designed for concurrency, it offers things like Software Transaction Memory, functional programming without side-effects and immutable data structures right out of the box. This means that the development team can focus their energies on developing features instead of concurrency details.
Pro Huge ecosystem of libraries to work with
There's a very large ecosystem of high-quality Clojure libraries which developers can use. One example is Incanter. It's a great data analytics library and a very powerful tool for dealing with matrices, datasets and csv files.
Pro Cross platform
Clojure compiles to JVM bytecode and runs inside the JVM. This means that applications written in Clojure are cross-platform out of the box.
Pro Rich Hickey
The creator is so awesome, he's a feature. Just look up his talks and see why.
Pro Great tool used in automating, configuring and managing dependencies available
Leiningen is a very useful tool for Clojure developers. It helps wiht automation, configuration and dependency management. It's basically a must for every Clojure project.
Pro Dynamic language
A superb data processing language. While rich type and specification systems are available they are optional.
Clojure has an elegant macro system which enables language additions, Domain-specific languages (DSLs), to be created much easier than most other languages (with the exception of Racket, perhaps).
Pro Game is available with which you can learn Clojure
Nightmod is a tool used to make "live-moddable" games. It displays the game's code while you are playing and allows you to inject new code using Clojure. This can be a fun and useful experience for people trying to learn Clojure.
Pro No C/Java syntax
Con Worst-of-both-worlds static type system
It's just barely good enough to make decent IDEs, but it's not at the level of Idris or even Haskell. For large enterprise projects, the IDE support is important, but the static typing in Java just gets in the way for the smaller projects beginners would start with.
Python is duck typed and this makes small programs easy to develop quickly, but the price is that you have to write unit tests to avoid breaking larger programs. In contrast, you can be reasonably certain that a program that actually compiles in Idris does what you want, because assertions are built into the powerful type system. Java can't make that claim and still requires unit tests. Java has the worst of both worlds because of its poor static type system.
Con Lacks modern features
Java evolves very slowly - lambda expressions weren't available until Java 8 (which is not available on Android), and despite getters/setters being a long-time convention, the language still doesn't have native accessor syntax (a la C#'s properties). It's unlikely newer, popular features like list comprehensions or disjoint union types will be available anytime soon. While not strictly required for novice programmers, these make problems more complicated and tedious than they need to be - for example, when a simple local function would do, (portable) Java demands anonymous inner classes, an interface and a class, or worse, no abstraction at all.
Con Confusing mis-features
Some features in Java can be quite confusing for beginners.
Encapsulation is needlessly obfuscated with a confusing access control model. As an example, the "protected" keyword not only grants access to child classes, but to the entire package. Since small programs are written as one package, it becomes functionally equivalent to "public".
In OOP, everything is supposed to be an object, but, in Java, primitive types such as integers, booleans and characters are not, and must be handled as special cases.
Java continues to lack many high-level features, and, particularly prior to Java 7, compensated by adding confusing Java-only features, such as anonymous subclasses. Some example code is unreadable without knowing a special-case feature, libraries differ in style based on when they were released or what platform they target(e.g., Android vs. Desktop), and some solutions just aren't available on some platforms.
Con Too verbose
- A Hello world needs package, class, static method and the actual
- Reading a line from input requires instatiating 5 objects in the right order.
- Exceptions are everywhere, particularly since all values are nullable.
- Java has a getter/setter culture, but without native syntax support.
- portable Java code lacks anonymous functions, and continues to lack good support for partial application, compensating instead with verbose design patterns, kludges like anonymous inner classes, or just inline code.
- It is statically typed without type inference, with a culture that promotes long class names.
- Poor support for sum-types and pattern matching leads to overuse of inheritance for dynamic dispatch and chains of nested conditionals
Especially for beginners, this can make reading Java code feel overwhelming; most Java courses tell students to simply copy, paste, and ignore a significant percentage of the code until they've learned enough to understand what it means.
For experienced programmers, this makes Java feel tedious, especially without an IDE, and actively discourages some solutions and some forms of abstraction.
Con Locks you into the static OOP mindset
Con Half-baked generics
Type erasure means it doesn't even exist at runtime. The whole generics system is confusing for beginners.
Con Garbage collection may teach bad habits
Java is a garbage collected language and it does not force programmers to think about memory allocation and management for their programs. This is fine most of the time. However, it may cause some difficulties in adjusting to a non-GC language (such as C for example), where memory management needs to be done manually. But if good coding practices and habits are followed, this shouldn't be much of a problem.
Con Enforces some misguided principles
Java utilizes principles that organize code into "classes" as the central concept, instead of more familiar organizational methods.
Con Long learning curve
Con Static typing but no type inference
The type system gets in your way more than it helps. Heavy IDE support is absolutely required for reasonable productivity. This means beginners have to learn not just the language, but eventually a complex, heavyweight IDE too.
Con Checked exceptions
Catch blocks can be a frequent source of mistakes.
Con Confusing error messages
Clojure's error messages more often than not are very confusing. They usually involve stack traces that do not thoroughly explain where the error was caused or what caused it.
Con Dynamic types
You can put anything in. This makes reasoning about code after a time has passed very hard.
Con Tied to the JVM and it's limitations.
Some language constructs were obviously created as workarounds for JVM limitations. This makes the language much less elegant than it could have been.
Also, the JVM has a very cumbersome FFI.
Con Syntax can be alien / jarring for those used to other Lisps
Perhaps some may consider this attribute an advantage, but I do not. Clojure does not attempt to maintain significant compatibility with other Lisps. So, if you already know a Lisp or are used to the way Lisp works in general, you'll probably be confused if you take a look at Clojure. See these resources for more details on this subject: