When comparing Java vs Go, the Slant community recommends Go for most people. In the question“What is the best programming language to learn first?” Go is ranked 2nd while Java is ranked 23rd. The most important reason people chose Go is:
The language is designed in a manner that seems logical. Syntax is simplified to reduce burden on the programmer and compiler developers.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
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 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 Most commonly used language in industry
Java is one of the most popular languages in industry, consistently ranking either first, or occasionally second (behind C or Javascript) in terms of usage. Polls (see sources below) show it to be consistently in high demand, particularly as measured by job board postings. This makes Java a great time investment, as you will be easily able to get a job utilizing your skills, particularly as those Java applications in production now will continue to need maintenance in the future. It also results in great support for tools and plenty of computer science books, example projects and online tutorials.
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 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 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 Platform Independent
Because of the Java Virtual Machine, the Java programming language is supported wherever a JVM is installed.
Pro You know what you do, and still simple
Because everything is typed and there is no silent cast or fail, you exactly know what you are manipulating, and there's no magic.
Have you ever watched a beginner struggling with a "couldn't call method x on y" in python or Javascript? These languages don't teach you what proper types are.
Java is one of the simplest languages to learn these basic concepts you find in every programming language.
Pro Simplified C-like syntax that is as easy to read and write as Python
The language is designed in a manner that seems logical. Syntax is simplified to reduce burden on the programmer and compiler developers.
Pro Great team working behind it
Go has a solid team of engineers working on it (some of the best networking engineers in the world are working on Go). Up until now, the great engineering of the language has compensated for its lack of power.
Pro Easy to install and configure; simple to compile software
Go software can be immediately installed, regardless of your operating system, package manager, or processor architecture with the go get command. Software is compiled statically by default so there is no need to worry about software dependencies on the client system. Makefiles and headers are no longer necessary, as the package system automatically resolves dependencies, downloads source code and compiles via a single command: go build
.
Pro Programmers don't have to argue over what 10% subet of the language to implement in their software project
The language promotes programming in a specific idiomatic style, which helps keep every programmer on the same page.
Pro Supports 'modules' in the form of packages
Every Go source file contains a package line that indicates which package a file belongs to. If the name of the package is 'main', it indicates that this is a program that will be compiled into a binary. Otherwise, it will recognize that it is a package.
Pro Demonstrates a unique, simple concept to object-oriented programming
All types are essentially objects, be they type aliases or structs. The compiler automatically associates types to their methods at compile time. Those methods are automatically associated to all interfaces that match. This allows you to gain the benefits of multiple inheritance without glue code. As a result of the design, classes are rendered obsolete and the resulting style is easy to comprehend.
Pro Great language for building networking services
Go was started as a systems language but now it has fully committed in the niche of networking services. This has been a brilliant move by Go because it allows them to capitalize on the immense talent of the Go engineering team (who are in the most part network engineers).
In a world dominated by Java EE and slow scripting language, Go was a breath of fresh air and it continues to be one of the most powerful languages if you want to build networking services.
Pro Exceptionally simple and scalable multithreaded and concurrent programming
Goroutines are "lightweight threads" that runs on OS threads. They provide a simple way for concurrent operations — prepending a function with go
will execute it concurrently. It utilizes channels for communication between goroutines which aids to prevent races and makes synchronizing execution effortless across goroutines. The maximum number of OS threads goroutines can run on may be defined at compile time with the GOMAXPROCS
variable.
Pro The go compiler compiles binaries instantly — as fast as a scripting language interpreter
Compiled binaries are fast — about as fast in C in most cases. Compiles on every OS without effort — truly cross-platform compiler. As a result of the fast compilation speed, you can use the gorun program to use go source code as if it was a scripting language.
Pro Performance is on the order of C and Java
Go is blazing fast, but easier to write than Python, JS, Ruby, or many other dynamic languages.
Pro Jobs available
You can find a Job knowing Go. Which is more than can be said with many other languages.
Pro API documentation is rich in content; easy to memorize
Only features deemed critical are added to the language to prevent cruft from working its way into the language. The language is small enough to fit inside one's head without having to repeatedly open documentation. Documentation is hosted on an official webpage in a manner that is simple to read and understand.
Pro Supports functional programming techniques such as function literals
This naturally also supports first class and high order functions, so you may pass functions as variables to other functions.
Pro Multiple variables may be assigned on a single line
This conveniently eliminates the need to create temporary variables.
Fibonacci example: x, y = y, x+y
Pro Built-in unit testing
The idiomatic approach to writing a Go software project is to perform test-driven development with unit testing. Every source code file should have an associated *_test.go
file which tests functions in the code.
Pro Provides tools for automatically formatting code for your entire software project
This helps keep every programmer on the same page in a project and eliminates arguments over formatting styles.
Pro Automatically generates API documentation for installed packages
Godoc is provided to automatically generate API documentation for Go projects. Godoc also hosts its own self-contained web server that will list documentation for all installed packages in your Go path.
Pro Supports splitting source code into multiple files
As long as every source code file in a directory has the same package name, the compiler will automatically concatenate all of the files together during the compilation process.
Pro Syntax for exported code from a package is simplified to be less verbose than other languages
Any variable, type and function whose name begins with a capital letter will be exported by a project, while all other code remains private. There is no longer a need to signify that a piece of code is 'private' or 'public' manually.
Cons
Con Too verbose
- A Hello world needs package, class, static method and the actual
printf
. - 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 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 Locks you into the static OOP mindset
Overly focuses on class-based OOP to the detriment of programmer freedom or alternative paradigms that are better for various problems. Traps programmers into an always use class-based 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 Slow and heavy
Too far from the machine hardware.
Con Too much hype and useless complication
I've been developing in Java for 20 years and I love this language, I've never used a better designed one over the last 30+ years. However, starting with version 6, the number of really useful features in each release has steadily decreased. There is now too much marketing in Java's evolution and too few concern about developers' needs (the functionalities of the applications we develop haven't changed and enterprise application architecture is much simpler than 20 years ago). I'm deeply sad to say that today, learning Python is a much wiser choice.
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 Long learning curve
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 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 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 Anything java can do, C# does better and more elegant.
Since C# came later, it could avoid the blatant mistakes made in Java.
Con Enforces some misguided principles
Java utilizes principles that primarily organize code into "classes" as the central concept, instead of more familiar organizational methods.
Con Checked exceptions
Checked exceptions add significantly to the cognitive load of the beginner. The more rules unrelated to the actual task that you pile onto the beginner, the slower he gets. Exponentially. And for what? Sure, they look good on paper, but checked exceptions are useless in the real world. They don't scale.
When you're calling APIs five levels deep and your method's throws clause balloons to 80 exceptions you might see, it gets kind of ridiculous. So you just say throws Exception
, which defeats the whole feature, but is more pointless boilerplate in an already tediously verbose language.
Or worse, while developing you can't be bothered and just catch{}
and silently swallow them all. Then you forget about it. Now you don't even have exceptions. The cure is worse than the disease!
So the wiser Java programmers will wrap all checked exceptions into a runtime exception, effectively making exceptions unchecked. That's at the cost of more boilerplate, but it's the lesser of evils. Unfortunately, Java doesn't even have macros to do this part for you. Maybe your IDE can write code templates for you, but that doesn't make it any easier to read.
Con Golang controlled by Google
Solves Google problems, which might not be your or the majority of user's problems. Was created for the benefit and purposes of Google, so is less flexible in language direction and options.
Con Hard to abstract even the simplest notions
Go is famously regarded as very simple. However, this simplicity becomes problematic in time. Programmers who use Go find themselves over and over again writing the same thing from a very low point of view. Domains not already served by libraries that are easy to glue are very difficult to get into.
Con Forces K&R style and won't allow Allman style
Golang developers were extremely short-sighted and biased by forcing the K&R style, which should never have happened. Basically kicking Allman style users out of their language.
Con Doesn't have true enums
Golang does weirdness with const versus having real enums, like other languages. This reflects the stubbornness and shortsightedness of the core developers, similar to the issue with generics, where it was denied that it was needed until it became too obvious that it should have been added years ago.
Con Does not have sum types
Makes it harder to have functions of different parameters types in a non OOP language. Thus messy generics and interfaces, and more confusion, where sum types could have solved a number of issues.
Con It appears Google uses position to snuff out or suppress other languages
Newer languages that could threaten Golang (or other Google controlled languages) appear to have suppressed search results on Google and YouTube. Dangerous situation where large company can manipulate user choice and market share. The freedom to freely choose and user rights need to be protected.
Con Designed to make the programmer expendable
Go was designed for large team projects where many contributors may be incompetent. That Go can still get things done under these conditions is a testament to its utility in this niche. Go's infamously weak abstraction power is thus a feature, not a bug, meant to prevent your teammates from doing too much damage. This also means any team member can be easily replaced by another code monkey at minimum cost. Good for the company, bad for you. The more talented programmers, on the other hand, will be very frustrated by having one hand tied behind their back.
Con Easy to shadow variable
Due to single character only difference, declare and assign statement can easily shadow variable from outer scope unconsciously. Example:
err := nil
if xxx {
err := somefunctionthatreturnsanerr
}
return err // always return nil
Con No forms designer
Those who are used to Visual Studio can feel the lack of a forms designer for rapid development.
Con Bizarre syntactic choices like a unique date format.
Con Changing visibility requires renaming all over the code
Con Lacks support for immutable data
Only way to prevent something from being mutated is to make copies of it, and to be very careful to not mutate it.
Con Performance slowdown because of indirect calls and garbage collection
Practically no meaningful Go application can be written without indirect function calls and garbage collection, these are central to Go's core infrastructure. But these are major impediments to achieving good performance.
Con Implementation of interfaces are difficult to figure out
Finding out what interfaces are implemented by a struct requires a magic crystal ball. They are easy to write, but difficult to read and trawl through.