Menu
CoddyTech
Course

Go for Java Developers

Transfer your Java experience to Go: typed values, control flow, slices, functions, methods, interfaces and error handling. Build a tested multi-file order pipeline.

Java and Go side by side

The same program in Java and in Go, from the lessons of this course.

  1. Files and the first run

    Java organizes behavior around classes and a static main method. Go has package-level functions and a main function in package main. Sibling files in that package are compiled together without class wrappers.

    Java
    1import java.util.*;2class Main {3
    4public static void main(String[] args) {5System.out.println("Java 3");6}7}
    Go
    1package main2import ("fmt")3
    4func main(){fmt.Println("Go", 3)}
  2. If and scoped names

    Java typically declares a local before an if or inside a branch. Go allows an initializer inside the if header, with scope including else. Braces are required in Go even for a single statement.

    Java
    1import java.util.*;2class Main {3
    4public static void main(String[] args) {5int n="go".length(); if(n>1){System.out.println("long");}else{System.out.println("short");}6}7}
    Go
    1package main2import ("fmt")3
    4func main(){if n := len("go"); n > 1 { fmt.Println("long") } else { fmt.Println("short") }}
  3. Arrays are values

    Java arrays are reference objects and need clone or copy operations for independent storage. Go fixed arrays copy on assignment; their length is part of their type. Slice assignment has different semantics from fixed-array assignment.

    Java
    1import java.util.*;2class Main {3
    4public static void main(String[] args) {5int[] a={3,5};int[] b=a.clone();b[0]=9;System.out.println(a[0]+" "+b[0]);6}7}
    Go
    1package main2import ("fmt")3
    4func main(){a:=[2]int{3,5}5b:=a6b[0]=97fmt.Println(a[0],b[0])}
  4. Typed function contracts

    Java methods belong to classes and may overload by parameter types. Go package functions need no class and cannot overload a name. Arguments are passed by value, including pointer values rather than implicit object-reference parameters.

    Java
    1import java.util.*;2class Main {3static boolean isEven(int n){return n%2==0;}4public static void main(String[] args) {5System.out.println(isEven(6));6}7}
    Go
    1package main2import ("fmt")3func IsEven(n int) bool { return n%2==0 }4func main(){fmt.Println(IsEven(6))}
  5. Struct values

    Java class instances retain reference identity; the example explicitly constructs a second instance. Go structs copy by value on assignment. Reference-like fields inside a copied struct still need deliberate ownership decisions.

    Java
    1import java.util.*;2class Main {3static class Label{String text;Label(String text){this.text=text;}}4public static void main(String[] args) {5Label a=new Label("old");Label b=new Label(a.text);b.text="new";System.out.println(a.text+" "+b.text);6}7}
    Go
    1package main2import ("fmt")3type Label struct { Text string }4func main(){a:=Label{Text:"old"}5b:=a6b.Text="new"7fmt.Println(a.Text,b.Text)}
  6. Errors are returned values

    Java uses checked and unchecked exceptions with stack unwinding. Go ordinary functions return error values explicitly. error is an interface, not a Throwable hierarchy; callers decide whether to add context, recover or propagate.

    Java
    1import java.util.*;2class Main {3static int positive(int n){if(n<=0)throw new IllegalArgumentException("not positive");return n;}4public static void main(String[] args) {5try{positive(-2);}catch(IllegalArgumentException e){System.out.println("rejected");}6}7}
    Go
    1package main2import ("fmt";"errors")3func Positive(n int)(int,error) { if n<=0{return 0,errors.New("not positive")};return n,nil }4func main(){_,e:=Positive(-2)5fmt.Println(e!=nil)}

Syllabus

9 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Java developers

Learn Go from another language

Frequently asked questions

Who is Go for Java Developers for?

For people who already write Java and want to learn Go. Each lesson starts from Java you know and shows how Go does the same thing, so you skip the beginner basics.

Do I need to know Go already?

No. The course starts with your first Go program. You need Java basics: variables, conditions, loops, functions and collections.

How many lessons does Go for Java Developers have?

Go for Java Developers contains 48 interactive lessons you can complete at your own pace.

What does Go for Java Developers cover?

The course is organized into chapters covering: Values and expressions, Control flow, Collections, Functions and pointers, and more.

Is Go for Java Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Go for Java Developers for free

Get started