◎ Go for
Java Developers
Section 01

Packages & Imports

Every Go file begins with package name. All files in the same directory share one package. The package name is the namespace — short, lowercase, one word.

Package declaration and imports

☕ Java — class per file, reverse-domain package
// File: UserService.java
package com.mycompany.service;

import com.mycompany.model.User;
import java.util.List;

public class UserService {
    // class required — cannot have free functions
}
◎ Go — package per folder, short name
// File: user_service.go
package service

import (
    "fmt"
    "github.com/mycompany/model"
)

// No class needed — functions live at package level
func GetUser(id string) (*model.User, error) {
    return nil, nil
}
Why Go does thisGo has no classes. The package IS the unit of organisation. Functions, types, and variables at the package level are the equivalent of static members in a Java utility class — except they are the default, not a special case.

Exported vs Unexported — capitalisation is the access modifier

☕ Java — keywords for visibility
public class User {
    public String id;          // public
    public String email;       // public
    private String password;   // private

    public User newUser(String email) { ... }
    private String hashPw(String pw) { ... }
}
◎ Go — capitalisation for visibility
type User struct {
    ID       string   // Capital = exported (public)
    Email    string   // Capital = exported
    password string   // lowercase = unexported (package-private)
}

// Capital = exported function
func NewUser(email string) User { ... }

// lowercase = unexported function
func hashPw(pw string) string { ... }
Why Go does thisNo public/private/protected keywords. Capitalisation is the entire visibility system. Go has no protected — there is no inheritance. There are only two scopes: this package, or everyone.
Package names: short, lowercase, single word — handler not handlerService. Types: PascalCase. Unexported functions: camelCase. Acronyms stay uppercase: UserID not UserId.