Hello World
Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
GoLang
func main() {
fmt.Println("hello world")
}
Variables & constants
Java
int a;
int b = 1;
var c = 1; // var inside methods
final var hello = "Hello"
GoLang
var a int
var b = 1
c := 1 // inside methods
const hello = "Hello"
Strings I
Java
var name = "John";
var lastName = "Smith";
var text = "My name is: " + name + " " + lastName;
var text2 = String.format("My names is: %s %s", name, lastName);
var otherText = "My name is: " + name.substring(2);
GoLang
var name = "John"
var lastName = "Smith"
var text = "My name is: " + name + " " + lastName;
var text2 = fmt.Sprintf("My names is: %s %s", name, lastName)
var otherText = "My name is: " + name[2:len(name)]
Multiline strings
Java
var text = "First Line\n" +
"Second Line\n" +
"Third Line";
GoLang
var text = `First Line
Second Line
Third Line`