Is Golang better than Java?

java-vs-go-lang

Golang, also referred as Go, is an open source programming language developed by Google in 2007. It is a compiled, statically typed language somewhat similar to C.  Two major implementations of this language is:

  1. Google’s Go compiler, “gc”, is developed as open source software
  2. Targets various platforms including Linux, OS X, Windows, various BSD and Unix versions and  smartphones.

Comparison of Golang with Java:

  1. Go is compiled to machine code and is executed directly, which makes it much faster than Java. It is so because Java uses VM to run its code which makes it slower as compared to Golang. Java takes a while for the JVM to initialize and get started – slower that typical startup time, and much slower than Go (Go starts up really fast since it’s a statically linked executable).
  2. Golang is also good in memory management,which is crucial in programming languages. Golang does not have references but has pointers. Golang has a garbage collection but there is no memory compaction. It is not necessarily bad. It can go a long way running servers for a very long time and still not have the memory fragmented. As in Java, memory is managed by the JVM, there is a full blown garbage collection that runs from time to time, marking the unreachable objects, sweeping them and compacting the presumably scattered memory.
  3. In case of local variables also, Golang is better as compared to Java. Local variables are stored on the stack in the Java language and other languages. But there is exception to this in Golang, it can return a pointer to a local variable from a function.
  4. Golang is at least as object oriented as JavaScript. Golang has interfaces and structs. But they are not really classes. They are value types. They are passed by value and wherever they are stored in memory the data there is only the pure data without object headers or anything like that.
  5. Golang code is compact. It has no semicolons but you can use them, but you need not. Inserting them is a preprocessing step on the source code and it is very effective. Most of the time they are clutter anyway.
  6. In the term of concurrency Golang is much better than Java. Go uses goroutines while Java uses OS threads to perform parallel executions of work. In Golang, channels are shared between units of work. A channel is essentially an FIFO pipe. A unit of work may read or write to a channel. But in Java, Objects are shared between units of work. When a unit of work accesses this piece of shared data, it must first obtain a lock on it using the entity’s intrinsic lock

Go is an interesting language. It is not a replacement for Java even on a language level. Golang and Java are not supposed to serve the same type of tasks – Java is enterprise development language, Go is a system programming language. Go, just as well as Java, is continuously developing so we may see some change in that in the future.

It is too early to tell if ‘Golang’ will ever replace Java or even reach its level of ubiquity, but quite certainly Golang will make a long lasting impact in the general purpose programming languages category forever.

1 comment

  • Michael Brown

    Whomever wrote this article is woefully misinformed. A few things…
    1. All JVM languages since version 1.5 were compiled such that all frequently running code is
    compiled natively……and currently are compiled natively ahead of time….which allows modern JVM based software to
    run nearly as fast as C/C++
    2. Go peforms miserably against Java in nearly all performance tests….it is after all running against it’s own run-time replete with garbage collection.
    3 Go IS NOT object oriented. It is an imperative language where types may be “composed” of behaviors of other types.
    4. Go does infact use references….else including pointers would be pointless. Pointers are variables meant to hold the memory addresses(otherwise known as variable references)

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.