Is Golang better than Java?
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:
- Google’s Go compiler, “gc”, is developed as open source software
- Targets various platforms including Linux, OS X, Windows, various BSD and Unix versions and smartphones.
Comparison of Golang with Java:
- 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).
- 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.
- 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.
- 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.
- 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.