SlideShare a Scribd company logo
GO
JAVA,
GO!
ANDRES ALMIRAY IXCHEL RUIZ
@AALMIRAY @IXCHELRUIZ
ANDRESALMIRAY.COM IXCHELRUIZ.COM
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
23 8
@ixchelruiz @aalmiray
GO: GETTING STARTED
Official (executable) documentation
https://gobyexample.com/
Test your knowledge with
https://github.com/cdarwin/go-koans
@ixchelruiz @aalmiray
HELLO WORLD (JAVA)
package main;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
$ java main/HelloWorld.java
$ javac –d classes main/HelloWorld.java
$ java –cp classes main.HelloWorld
@ixchelruiz @aalmiray
HELLO WORLD (GO)
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
$ go run hello-world.go
$ go build hello-world.go
$ ./hello-world
FAMILIAR
FEATURES
@ixchelruiz @aalmiray
VALUES (JAVA)
package main;
public class Values {
public static void main(String[] args) {
System.out.println("go" + "lang");
System.out.println("1+1 = "+ (1+1));
System.out.println("7.0/3.0 = " + (7.0/3.0));
System.out.println(true && false);
System.out.println(true || false);
System.out.println(!true);
}
}
@ixchelruiz @aalmiray
VALUES (GO)
package main
import "fmt"
func main() {
fmt.Println("go" + "lang")
fmt.Println("1+1 = ", 1+1)
fmt.Println("7.0/3.0 = ", 7.0/3.0)
fmt.Println(true && false)
fmt.Println(true || false)
fmt.Println(!true)
}
@ixchelruiz @aalmiray
VALUES (OUTPUT)
golang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false
@ixchelruiz @aalmiray
CONDITIONS (JAVA)
package main;
public class Conditions {
public static void main(String[] args) {
if (7%2 == 0) {
System.out.println("7 is odd");
} else {
System.out.println("7 is even");
}
}
}
@ixchelruiz @aalmiray
CONDITIONS (GO)
package main
import "fmt"
func main() {
if 7%2 == 0 {
fmt.Println("7 is odd")
} else {
fmt.Println("7 is even")
}
}
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
VISIBILITY
• There are 4 visibility modifiers in Java:
• public, protected, private, and package private
• Well… technically 5 -> modules
• There is a case convention in Go
• Symbols starting with uppercase as public
• Symbols starting with lowercase are private
• That’s it, no more, move along.
@ixchelruiz @aalmiray
TYPE INFERENCE (JAVA)
• We’ve got verbosity reduction with the <> operator (JDK 7)
List<String> strings = new ArrayList<>();
• Next we’ve got type inference for local variables (JDK 10)
var strings = new ArrayList<String>();
• Use var in lambda expression arguments (JDK 11)
@ixchelruiz @aalmiray
TYPE INFERENCE (GO)
• You may define and assign variables in this way
var strings = []string{"a","b","c"};
• Or use the short notation
strings := []string{"a","b","c"};
@ixchelruiz @aalmiray
COLLECTIONS
• Slices and Maps (collections)
var sliceOfStrings = []string{"a", "b", "c"}
mapOfValues := make(map([string]int))
mapOfValues["foo"] = 1
anotherMap := map[string]int{"foo": 1}
@ixchelruiz @aalmiray
ARRAYS
• Arrays look like slices but their length is part of the type
var an_array [5]int
another_one := [5]int{1,2,3,4,5}
• Any function that takes [5]int can’t take [4]int or any other
array with a different length than 5.
@ixchelruiz @aalmiray
FUNCTIONS
• Functions may have zero or more arguments
• Return type is defined after the argument list
• Symbol naming convention applies
func fib(n int) int {
if n <= 1 {
return n
}
return fib(n-1) + fib(n-2)
}
@ixchelruiz @aalmiray
MULTIPLE RETURN VALUES
• Return as many values as needed
func thisAndTheOtherThing() (int,string) {
// do some work
return 0, "OK"
}
@ixchelruiz @aalmiray
FUNCTIONS AS CODE
• Just like lambda expressions
package main
import "fmt"
func greeting_gen() func(string) string {
return func(s string) string {
return "Hello " + s
}
}
func main() {
fmt.Println(greeting_gen()("Go"))
}
@ixchelruiz @aalmiray
THERE IS NO CLASS
@ixchelruiz @aalmiray
BUT THERE IS STRUCT
• There’s no equivalent to POJOs in Go
• You may create new types by leveraging structs
type Person struct {
name string
age int
}
@ixchelruiz @aalmiray
CONSTRUCTORS
package main
import "fmt"
type Person struct {
name string
age int
}
func main() {
p1 := Person{"Duke", 23}
p2 := Person{name: "Duke", age: 23}
}
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
SPOT THE COMPILE ERROR
package main
import "fmt"
type Person struct {
name string
age int
}
func main() {
p1 := Person{"Duke", 23}
}
@ixchelruiz @aalmiray
SPOT THE COMPILE ERROR
package main
import "fmt"
type Person struct {
name string
age int
}
func main() {
p1 := Person{"Duke", 23} // UNUSED!
}
@ixchelruiz @aalmiray
THERE ARE NO METHODS
@ixchelruiz @aalmiray
ATTACH FUNCTIONS TO TYPES
package main
import "fmt"
type Person struct {
name string
age int
}
func (p *Person) printAge() {
fmt.Println("Age is = ", p.age)
}
func main() {
p1 := Person{"Duke", 23}
p1.printAge()
}
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
WHILE LOOP (JAVA)
package main;
public class While {
public static void main(String[] args) {
int i = 0;
while(i <= 3) {
System.out.println(i);
i++;
}
}
}
@ixchelruiz @aalmiray
WHILE LOOP (GO)
package main
import "fmt"
func main() {
i := 0
for i <= 3 {
fmt.Println(i)
i++
}
}
@ixchelruiz @aalmiray
FOR LOOP (JAVA)
package main;
public class For {
public static void main(String[] args) {
for(int i = 0; i <=3; i++) {
System.out.println(i);
}
}
}
@ixchelruiz @aalmiray
FOR LOOP (GO)
package main
import "fmt"
func main() {
for i:= 0; i <= 3; i++ {
fmt.Println(i)
}
}
@ixchelruiz @aalmiray
INFINITE LOOPS (JAVA)
package main;
public class Infinite {
public static void main(String[] args) {
while(true) {
System.out.println("Infinite loop");
break;
}
}
}
@ixchelruiz @aalmiray
INFINITE LOOPS (JAVA)
package main;
public class Infinite {
public static void main(String[] args) {
for(;;) {
System.out.println("Infinite loop");
break;
}
}
}
@ixchelruiz @aalmiray
INFINITE LOOPS (JAVA)
package main;
public class Infinite {
public static void main(String[] args) {
do {
System.out.println("Infinite loop");
break;
} while(true);
}
}
@ixchelruiz @aalmiray
INFINITE LOOPS (GO)
package main
import "fmt"
func main() {
for {
fmt.Println("Infinite loop")
break
}
}
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
INTERFACES
• Interfaces are implemented automatically as long as the type
matches all methods.
• The interface{} type is roughly equivalent to
java.lang.Object
@ixchelruiz @aalmiray
package main
import "fmt"
import "math"
type geometry interface {
area() float64
perim() float64
}
type rect struct {
width, height float64
}
type circle struct {
radius float64
}
@ixchelruiz @aalmiray
func (r rect) area() float64 {
return r.width * r.height
}
func (r rect) perim() float64 {
return 2*r.width + 2*r.height
}
func (c circle) area() float64 {
return math.Pi * c.radius * c.radius
}
func (c circle) perim() float64 {
return 2 * math.Pi * c.radius
}
@ixchelruiz @aalmiray
func measure(g geometry) {
fmt.Println(g)
fmt.Println(g.area())
fmt.Println(g.perim())
}
func main() {
r := rect{width: 3, height: 4}
c := circle{radius: 5}
measure(r)
measure(c)
}
@ixchelruiz @aalmiray
ERRORS
• Go doesn’t have exceptions like Java does
• Errors are just another type that can be handled
• Use the multiple return feature to “throw” errors
func f1(arg int) (int, error) {
if arg == 42 {
return -1, errors.New("can't work with 42")
}
return arg + 3, nil
}
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
TYPE CLONE VS TYPE ALIAS
• Type cloning
type foo int
• Type aliasing
type bar = int
• Instances of foo behave like int BUT they are not the same
as int, that is, a method taking an int as argument can’t take
a foo.
• Instances of bar are identical to int, that is, anywhere an int
fits so does a bar and viceversa.
OK,
BUT WHY?
@ixchelruiz @aalmiray
HELLO WORLD (JAVA)
$ time java main/HelloWorld.java
Hello World
real 0m0.538s
user 0m0.918s
sys 0m0.069s
$ javac -d classes main/HelloWorld.java
$ time java -cp classes main.HelloWorld
Hello World
real 0m0.112s
user 0m0.104s
sys 0m0.029s
@ixchelruiz @aalmiray
HELLO WORLD (GO)
$ time go run hello-world.go
Hello World
real 0m0.191s
user 0m0.135s
sys 0m0.080s
$ go build hello-world.go
$ time ./hello-world
Hello World
real 0m0.006s
user 0m0.001s
sys 0m0.004s
@ixchelruiz @aalmiray
TIMES
Java Go Percentage
Run
Real 0.538 0.191 65.59
User 0.918 0.135 85.29
Sys 0.069 0.080 -15.94
Compile & Run
Real 0.112 0.006 94.64
User 0.104 0.001 99.03
Sys 0.029 0.004 86.20
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
HTTPS://GRPC.IO
gRPC is a modern, open source, high-performance remote
procedure call (RPC) framework that can run anywhere. It
enables client and server applications to communicate
transparently, and makes it easier to build connected systems.
Stream data between client and server, in either direction, event
both directions at the same time.
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
HTTPS://WEBASSEMBLY.ORG/
WebAssembly (abbreviated Wasm) is a binary instruction format
for a stack-based virtual machine. Wasm is designed as a
portable target for compilation of high-level languages, enabling
deployment on the web for client and server applications.
@ixchelruiz @aalmiray
GO + WEBASSEMBLY
https://github.com/golang/go/wiki/WebAssembly
@ixchelruiz @aalmiray
@ixchelruiz @aalmiray
HTTP://ANDRESALMIRAY.COM/NEWSLETTER
HTTP://ANDRESALMIRAY.COM/EDITORIAL
@ixchelruiz @aalmiray
THANK YOU!
ANDRES ALMIRAY IXCHEL RUIZ
@AALMIRAY @IXCHELRUIZ
ANDRESALMIRAY.COM IXCHELRUIZ.COM

More Related Content

What's hot (20)

PPT
Developing iOS apps with Swift
New Generation Applications
 
PDF
Real world gobbledygook
Pawel Szulc
 
PDF
Python and sysadmin I
Guixing Bai
 
PPTX
P3 2018 python_regexes
Prof. Wim Van Criekinge
 
ODP
Programming Under Linux In Python
Marwan Osman
 
PDF
A swift introduction to Swift
Giordano Scalzo
 
PPTX
Learn python in 20 minutes
Sidharth Nadhan
 
PDF
ES2015 (ES6) Overview
hesher
 
PPT
Python легко и просто. Красиво решаем повседневные задачи
Maxim Kulsha
 
PDF
Haskell in the Real World
osfameron
 
PPTX
Kotlin standard
Myeongin Woo
 
PDF
Expression trees in c#
Oleksii Holub
 
PDF
Introduction to Swift programming language.
Icalia Labs
 
PDF
Implementing virtual machines in go & c 2018 redux
Eleanor McHugh
 
PDF
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
PROIDEA
 
PPTX
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
PDF
Introduction to python
Ahmed Salama
 
PPTX
Expression trees in c#, Алексей Голубь (Svitla Systems)
Alina Vilk
 
KEY
Why Learn Python?
Christine Cheung
 
ODP
The bones of a nice Python script
saniac
 
Developing iOS apps with Swift
New Generation Applications
 
Real world gobbledygook
Pawel Szulc
 
Python and sysadmin I
Guixing Bai
 
P3 2018 python_regexes
Prof. Wim Van Criekinge
 
Programming Under Linux In Python
Marwan Osman
 
A swift introduction to Swift
Giordano Scalzo
 
Learn python in 20 minutes
Sidharth Nadhan
 
ES2015 (ES6) Overview
hesher
 
Python легко и просто. Красиво решаем повседневные задачи
Maxim Kulsha
 
Haskell in the Real World
osfameron
 
Kotlin standard
Myeongin Woo
 
Expression trees in c#
Oleksii Holub
 
Introduction to Swift programming language.
Icalia Labs
 
Implementing virtual machines in go & c 2018 redux
Eleanor McHugh
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
PROIDEA
 
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
Introduction to python
Ahmed Salama
 
Expression trees in c#, Алексей Голубь (Svitla Systems)
Alina Vilk
 
Why Learn Python?
Christine Cheung
 
The bones of a nice Python script
saniac
 

Similar to Go Java, Go! (20)

PPTX
Go Java, Go!
Andres Almiray
 
PDF
Go Java, Go!
Andres Almiray
 
PDF
Swift, functional programming, and the future of Objective-C
Alexis Gallagher
 
PDF
A comparison between C# and Java
Ali MasudianPour
 
ODP
Turtle Graphics in Groovy
Jim Driscoll
 
PPT
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
PDF
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
PDF
An Intro To ES6
FITC
 
PDF
No excuses, switch to kotlin
Thijs Suijten
 
PDF
Kotlin @ Coupang Backend 2017
Sunghyouk Bae
 
PDF
Impress Your Friends with EcmaScript 2015
Lukas Ruebbelke
 
PPTX
Poly-paradigm Java
Pavel Tcholakov
 
PDF
JEEConf 2017 - Having fun with Javassist
Anton Arhipov
 
PPTX
Java string handling
GaneshKumarKanthiah
 
PPT
Learning Java 1 – Introduction
caswenson
 
PPTX
A Brief Intro to Scala
Tim Underwood
 
PDF
Presentatie - Introductie in Groovy
Getting value from IoT, Integration and Data Analytics
 
PDF
Stuff you didn't know about action script
Christophe Herreman
 
PPT
Scala in a nutshell by venkat
Venkateswaran Kandasamy
 
PDF
Kotlin intro
Elifarley Cruz
 
Go Java, Go!
Andres Almiray
 
Go Java, Go!
Andres Almiray
 
Swift, functional programming, and the future of Objective-C
Alexis Gallagher
 
A comparison between C# and Java
Ali MasudianPour
 
Turtle Graphics in Groovy
Jim Driscoll
 
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
An Intro To ES6
FITC
 
No excuses, switch to kotlin
Thijs Suijten
 
Kotlin @ Coupang Backend 2017
Sunghyouk Bae
 
Impress Your Friends with EcmaScript 2015
Lukas Ruebbelke
 
Poly-paradigm Java
Pavel Tcholakov
 
JEEConf 2017 - Having fun with Javassist
Anton Arhipov
 
Java string handling
GaneshKumarKanthiah
 
Learning Java 1 – Introduction
caswenson
 
A Brief Intro to Scala
Tim Underwood
 
Presentatie - Introductie in Groovy
Getting value from IoT, Integration and Data Analytics
 
Stuff you didn't know about action script
Christophe Herreman
 
Scala in a nutshell by venkat
Venkateswaran Kandasamy
 
Kotlin intro
Elifarley Cruz
 
Ad

More from Andres Almiray (20)

PDF
Dealing with JSON in the relational world
Andres Almiray
 
PDF
Deploying to production with confidence 🚀
Andres Almiray
 
PDF
Going beyond ORMs with JSON Relational Duality Views
Andres Almiray
 
PDF
Setting up data driven tests with Java tools
Andres Almiray
 
PDF
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Andres Almiray
 
PDF
Liberando a produccion con confianza
Andres Almiray
 
PDF
Liberando a produccion con confidencia
Andres Almiray
 
PDF
OracleDB Ecosystem for Java Developers
Andres Almiray
 
PDF
Softcon.ph - Maven Puzzlers
Andres Almiray
 
PDF
Maven Puzzlers
Andres Almiray
 
PDF
Oracle Database Ecosystem for Java Developers
Andres Almiray
 
PDF
JReleaser - Releasing at the speed of light
Andres Almiray
 
PDF
Building modular applications with the Java Platform Module System and Layrry
Andres Almiray
 
PDF
Going Reactive with g rpc
Andres Almiray
 
PDF
Building modular applications with JPMS and Layrry
Andres Almiray
 
PDF
Taking Micronaut out for a spin
Andres Almiray
 
PDF
Apache Groovy's Metaprogramming Options and You
Andres Almiray
 
PDF
What I wish I knew about Maven years ago
Andres Almiray
 
PDF
What I wish I knew about maven years ago
Andres Almiray
 
PDF
The impact of sci fi in tech
Andres Almiray
 
Dealing with JSON in the relational world
Andres Almiray
 
Deploying to production with confidence 🚀
Andres Almiray
 
Going beyond ORMs with JSON Relational Duality Views
Andres Almiray
 
Setting up data driven tests with Java tools
Andres Almiray
 
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Andres Almiray
 
Liberando a produccion con confianza
Andres Almiray
 
Liberando a produccion con confidencia
Andres Almiray
 
OracleDB Ecosystem for Java Developers
Andres Almiray
 
Softcon.ph - Maven Puzzlers
Andres Almiray
 
Maven Puzzlers
Andres Almiray
 
Oracle Database Ecosystem for Java Developers
Andres Almiray
 
JReleaser - Releasing at the speed of light
Andres Almiray
 
Building modular applications with the Java Platform Module System and Layrry
Andres Almiray
 
Going Reactive with g rpc
Andres Almiray
 
Building modular applications with JPMS and Layrry
Andres Almiray
 
Taking Micronaut out for a spin
Andres Almiray
 
Apache Groovy's Metaprogramming Options and You
Andres Almiray
 
What I wish I knew about Maven years ago
Andres Almiray
 
What I wish I knew about maven years ago
Andres Almiray
 
The impact of sci fi in tech
Andres Almiray
 
Ad

Recently uploaded (20)

PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Français Patch Tuesday - Juillet
Ivanti
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Français Patch Tuesday - Juillet
Ivanti
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 

Go Java, Go!