What is Different With Golang & Java?
Golang to Java Transition
In programming lectures, students use the Java language to carry out practical work.
But I connected the concepts in golang to Java to adapt faster.
Here's a similar concept:
- Worker
- Class/struct
- Method
- Receiver
- Typing
What is the difference between Java and Golang?
There are differences in writing in Java, namely Golang with its simple philosophy, and Java with its stricter writing.
And maybe it's less familiar because the writing position in Java has to be written:
- visibilitas (public,private, protected)
- Typing (int,string,bool,byte[])
- Variable Name
Example:
While in Golang visibility is sufficient to use capital letters in front of lowercase letters to provide visibility.
Then typing is defined after the variable,Or if you want to follow the type of the Variable value, just use ":=".
Example:
How is the Implementation different between Golang and Java?
Golang doesn't have classes but uses "Struct" and use receiver func as method
Example:
In Golang there is no constructor and you have to create it manually NewStruct, or simply
And the method has 2 types of receivers:
- Pointer Receiver
- The pointer method changes the original value of the struct.
- Value Receiver
- The method receives a copy of the data. Changing attribute values within the method will not change the original struct value.