Golang for Java Developers — Pointers, Error Handling, and Concurrency

The Go programming language from a Java perspective — part 2

Dave Taubler
Level Up Coding
Published in
13 min readApr 6, 2021

--

Bad sketches by the author

In this series’ first article, I described myself as a long-time Java engineer who has recently decided to give Go a go. Although I’ll always love Java, I know that it’s important to keep learning languages. I chose Go because it’s a statically-typed, compiled language that doesn’t face some of the issues (such as slow compile times and startup times) that Java faces.

This series is not meant to pit Java versus Go. Both are strong languages with their own strengths and weaknesses. Rather, it is meant to provide my first observations of Go as a Java developer. Given that I’m still learning about Go, I welcome any feedback if any readers believe that I’ve misrepresented Go (or Java, for that matter).

With that, let’s jump into some areas which really differentiate Go from Java: pointers, error handling, and concurrency.

Pointers

In Java, when we pass an object to a method, we’re passing a pointer to that object. But when we pass a primitive (such as an int or a double), we’re actually passing a copy of that primitive (which is why, if I pass int myInt = 2 to a method: void quadruple(int i) { i = i * 4; } the value of…

--

--