SlideShare a Scribd company logo
1 of 28
COMPARING
GOLANG AND
UNDERSTANDING
JAVA VALUE TYPES
April 26, 2018 12:00-13:00
Peter Verhas
Software Architect
I AM JAVA PROGRAMMER, WHY SHOULD I CARE?
• I have read about ValueTypes in
2015... So what ?
• I learned a bit Golang in 2016 and
then again Value Types
• Ahhh... that’s it!
• Go is so much different from Java, we
can learn a lot from it
Photo by Les Anderson on Unsplash
DISCLAIMER
1. I am a Java programmer first
2. I am a polyglot programmer second
3. I know Java and Go is only one of the many languages I
am not afraid of
4. I have Swiss Chocolate
WHAT IS THE ANSWER TO THE ULTIMATE QUESTION OF LIFE,
THE UNIVERSE, AND EVERYTHING ?
WAS IST DIE ANTWORT NACH DEM LEBEN, DEM UNIVERSUM UND
DEM GANZEN REST?
FORTY-TWO
ZWEIUNDVIERZIG
42
WHY?
WHICH IS THE BETTER?
GO IS THE LANGUAGE OF GOOGLE
• Go is the new C++
• Go is a system programming language
• Go is genius
• Go is terrible
Photo by Henry Hustava on Unsplash
SERIOUSLY…
• Go is a compiled language source -> exe, no VM
• Object oriented and functional
• There is a garbage collector but it is not a real garbage collector,
• … or is it?
WE WILL TALK ABOUT
• Language syntax
• Exception handling (panic)
• GC
• Local variables and the stack
• Closures
• Goroutines
• Object Orientation and Inheritance
• There is
• There is not
This will teach us the most!
We only slightly touch these!
SYNTAX
• mostly C like Java, C#, Perl, ….
• BUT if a == b {
…
}
if( a == b )
var x : = expressiontypeOfx
• if variable is not used it is an error
• if you import a package you do not use it is an error
• if you do not use semicolon at the end of the line… go will assume you
wanted
• Public is written capitalized. Otherwise private.
FUNCTION DEFINITION
• There are functions… just function
• Methods are also functions with receiver
• We just separate the parts with spaces and parentheses
EXCEPTION HANDLING
• There is no exception handling
• Methods return multiple values (like Python), usually result and error
status
• Panic is like Java throw but should not be used for exceptions, only error
• Defer can be used like Java finally
GARBAGE COLLECTION
• For the programmer: there is an automated Garbage Collector
• For the hard-core JVM guys: it is not a real GC, there is no compacting
• and how objects are stored and managed is a reason for that
LOCAL VARIABLES AND THE STACK
• What happens when you return a pointer to a local variable in C?
• What happens when you return a pointer to a local variable in Go?
• Go will allocate the escaping local variable on the heap.
CLOSURES
• Functions defined inside function
• Surrounding is closure
• Return a function as result (Go is functional)
GOROUTINES
• Goroutines are fibers, lightweight threads.
• You can start a few tens of thousands of them, no problem.
• There is a built-in type: channel. This is a fixed size FIFO.
OBJECTS IN GO
• There is interface in GO but this is something different from what it
is in Java.
• You do not … implements … an interface, you just implement it.
• There is a struct type
• Struct can not extend other structs but it may contain other structs
• Functions may operate on a certain type
17CONFIDENTIAL
INTERFACE
STRUCT DOES NOT „IMPLEMENTS”
STRUCT CONTAINS
FUNCTION WORKS ON A STRUCT TYPE
(RECEIVER OF THE FUNCTION)
VARIABLES ARE EITHER STRUCT TYPE OR
INTERFACE TYPE
OBJECTS IN GO OBJECTS IN JAVA
INTERFACE
CLASS IMPLEMENTS INTERFACE
CLASS EXTENDS
METHOD INSIDE CLASS
VARIABLES ARE EITHER CLASS TYPE OR
INTERFACE TYPE, BUT IT DOES NOT
MATTER
GOLANG „OBJECTS” ARE HEADLESS
• Java has ~ 8/16 byte header in front of each object
• Golang has struct, no header
• Java array  array of references to objects
• Go array  array of struct memory
• (interface array is array of references)
GOLANG „OBJECTS” ARE HEADLESS
• Variables that are struct type hold the value
• Variables that are pointer to struct type know what they point to
• Variables that are interface type have a reference to the struct and
also reference to the struct definition
• Let’s have a weird example that will make you understand and
remember
AND NOW SOMETHING COMPLETELY DIFFERENT
JAVA VALUE TYPES
WHAT ARE VALUE TYPES IN JAVA?
• Project Valhalla started 2014
• byte, short, int, long, float, double, char and boolean
are value types
• Project Valhalla aims user definable value types
• Value types are not objects, they hold only the value
GOLANG STRUCT VS. JAVA VALUE TYPE
struct
interface
value
type
object
object
header
WHY DO WE NEED THEM?
• For example Date is a good candidate to be a value type
• Old mistake: object has synchronization lock support (seemed to be
a good idea)
• Objects occupy the heap, value types are allocated on the stack
• Value type arrays are CPU cache friendly
Codes like a class, works like an int!
CONSEQUENCES
• Compare with ==
• Value type variable can not be null
• Limited or no inheritance
• Even if there is inheritance we cannot have polymorphism
• Method call pass-by-value
CONSEQUENCES FOR JVM
• Scala Value Type can be extended (restricted to 1 field)
• Languages like Swift, Golang can be effectively compiled to JVM
or not…
• Many cases we can stop joking around with off-heap memory
mapped files for high performance data intensive application
OBJECT
DATA
OBJECT HEADER
WHY?
WHICH IS THE BETTER?
VARIABLE
TAKEAWAY
• Java is good as it is
• But it can be and it will be better with value types
• Java will always be better
• and better
• Go, and learn go to be a better (Java) programmer.
https://play.golang.org/
THANK YOU
DANKE
peter@verhas.com, verhas@twitter/github, http://javax0.wordpress.com

More Related Content

What's hot

New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_vNico Ludwig
 
Functional programming principles and Java 8
Functional programming principles and Java 8Functional programming principles and Java 8
Functional programming principles and Java 8Dragos Balan
 
“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic DiabetesTzach Zohar
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Brian Sam-Bodden
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8Talha Ocakçı
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Rormyuser
 
Introduction to functional programming with java 8
Introduction to functional programming with java 8Introduction to functional programming with java 8
Introduction to functional programming with java 8JavaBrahman
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesRoman Elizarov
 
Into the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional ProgrammingInto the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional ProgrammingMike Pence
 
Java object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - BrainsmartlabsJava object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - Brainsmartlabsbrainsmartlabsedu
 
Core java programming tutorial - Brainsmartlabs
Core java programming tutorial - BrainsmartlabsCore java programming tutorial - Brainsmartlabs
Core java programming tutorial - Brainsmartlabsbrainsmartlabsedu
 
OOP programming
OOP programmingOOP programming
OOP programminganhdbh
 

What's hot (20)

New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
Functional programming principles and Java 8
Functional programming principles and Java 8Functional programming principles and Java 8
Functional programming principles and Java 8
 
“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
Scala
ScalaScala
Scala
 
Scala days mizushima
Scala days mizushimaScala days mizushima
Scala days mizushima
 
Java script unleashed
Java script unleashedJava script unleashed
Java script unleashed
 
Introduction to functional programming with java 8
Introduction to functional programming with java 8Introduction to functional programming with java 8
Introduction to functional programming with java 8
 
2CPP19 - Summation
2CPP19 - Summation2CPP19 - Summation
2CPP19 - Summation
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
Lambdas
LambdasLambdas
Lambdas
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin Coroutines
 
Into the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional ProgrammingInto the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional Programming
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
Coding in kotlin
Coding in kotlinCoding in kotlin
Coding in kotlin
 
Java object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - BrainsmartlabsJava object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - Brainsmartlabs
 
Core java programming tutorial - Brainsmartlabs
Core java programming tutorial - BrainsmartlabsCore java programming tutorial - Brainsmartlabs
Core java programming tutorial - Brainsmartlabs
 
OOP programming
OOP programmingOOP programming
OOP programming
 

Similar to Comparing Golang and understanding Java Value Types

Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itlokeshpappaka10
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Codersebbe
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaBrian Topping
 
Kevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptKevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptAxway Appcelerator
 
U1 JAVA.pptx
U1 JAVA.pptxU1 JAVA.pptx
U1 JAVA.pptxmadan r
 
javerosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparisonjaverosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparisonDomingo Suarez Torres
 
C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem Claudson Oliveira
 
Noam Kfir - There is no Java Script - code.talks 2015
Noam Kfir - There is no Java Script - code.talks 2015Noam Kfir - There is no Java Script - code.talks 2015
Noam Kfir - There is no Java Script - code.talks 2015AboutYouGmbH
 
There Is No JavaScript
There Is No JavaScriptThere Is No JavaScript
There Is No JavaScriptNoam Kfir
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Martijn Verburg
 
Introduction to java
Introduction to java Introduction to java
Introduction to java sanjay joshi
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applicationseightbit
 
How to not suck at JavaScript
How to not suck at JavaScriptHow to not suck at JavaScript
How to not suck at JavaScripttmont
 
Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building BlocksCate Huston
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |ShubhamAthawane
 
Perl5 meta programming
Perl5 meta programmingPerl5 meta programming
Perl5 meta programmingkarupanerura
 

Similar to Comparing Golang and understanding Java Value Types (20)

Java Closures
Java ClosuresJava Closures
Java Closures
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
 
Kevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptKevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScript
 
U1 JAVA.pptx
U1 JAVA.pptxU1 JAVA.pptx
U1 JAVA.pptx
 
javerosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparisonjaverosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparison
 
C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem
 
Noam Kfir - There is no Java Script - code.talks 2015
Noam Kfir - There is no Java Script - code.talks 2015Noam Kfir - There is no Java Script - code.talks 2015
Noam Kfir - There is no Java Script - code.talks 2015
 
There Is No JavaScript
There Is No JavaScriptThere Is No JavaScript
There Is No JavaScript
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Js basics
Js basicsJs basics
Js basics
 
Java basic
Java basicJava basic
Java basic
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
How to not suck at JavaScript
How to not suck at JavaScriptHow to not suck at JavaScript
How to not suck at JavaScript
 
Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building Blocks
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |
 
Perl5 meta programming
Perl5 meta programmingPerl5 meta programming
Perl5 meta programming
 

Recently uploaded

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 

Recently uploaded (20)

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 

Comparing Golang and understanding Java Value Types

  • 1. COMPARING GOLANG AND UNDERSTANDING JAVA VALUE TYPES April 26, 2018 12:00-13:00 Peter Verhas Software Architect
  • 2. I AM JAVA PROGRAMMER, WHY SHOULD I CARE? • I have read about ValueTypes in 2015... So what ? • I learned a bit Golang in 2016 and then again Value Types • Ahhh... that’s it! • Go is so much different from Java, we can learn a lot from it Photo by Les Anderson on Unsplash
  • 3. DISCLAIMER 1. I am a Java programmer first 2. I am a polyglot programmer second 3. I know Java and Go is only one of the many languages I am not afraid of 4. I have Swiss Chocolate
  • 4. WHAT IS THE ANSWER TO THE ULTIMATE QUESTION OF LIFE, THE UNIVERSE, AND EVERYTHING ? WAS IST DIE ANTWORT NACH DEM LEBEN, DEM UNIVERSUM UND DEM GANZEN REST? FORTY-TWO ZWEIUNDVIERZIG
  • 6. GO IS THE LANGUAGE OF GOOGLE • Go is the new C++ • Go is a system programming language • Go is genius • Go is terrible Photo by Henry Hustava on Unsplash
  • 7. SERIOUSLY… • Go is a compiled language source -> exe, no VM • Object oriented and functional • There is a garbage collector but it is not a real garbage collector, • … or is it?
  • 8. WE WILL TALK ABOUT • Language syntax • Exception handling (panic) • GC • Local variables and the stack • Closures • Goroutines • Object Orientation and Inheritance • There is • There is not This will teach us the most! We only slightly touch these!
  • 9. SYNTAX • mostly C like Java, C#, Perl, …. • BUT if a == b { … } if( a == b ) var x : = expressiontypeOfx • if variable is not used it is an error • if you import a package you do not use it is an error • if you do not use semicolon at the end of the line… go will assume you wanted • Public is written capitalized. Otherwise private.
  • 10. FUNCTION DEFINITION • There are functions… just function • Methods are also functions with receiver • We just separate the parts with spaces and parentheses
  • 11. EXCEPTION HANDLING • There is no exception handling • Methods return multiple values (like Python), usually result and error status • Panic is like Java throw but should not be used for exceptions, only error • Defer can be used like Java finally
  • 12. GARBAGE COLLECTION • For the programmer: there is an automated Garbage Collector • For the hard-core JVM guys: it is not a real GC, there is no compacting • and how objects are stored and managed is a reason for that
  • 13. LOCAL VARIABLES AND THE STACK • What happens when you return a pointer to a local variable in C? • What happens when you return a pointer to a local variable in Go? • Go will allocate the escaping local variable on the heap.
  • 14. CLOSURES • Functions defined inside function • Surrounding is closure • Return a function as result (Go is functional)
  • 15. GOROUTINES • Goroutines are fibers, lightweight threads. • You can start a few tens of thousands of them, no problem. • There is a built-in type: channel. This is a fixed size FIFO.
  • 16. OBJECTS IN GO • There is interface in GO but this is something different from what it is in Java. • You do not … implements … an interface, you just implement it. • There is a struct type • Struct can not extend other structs but it may contain other structs • Functions may operate on a certain type
  • 17. 17CONFIDENTIAL INTERFACE STRUCT DOES NOT „IMPLEMENTS” STRUCT CONTAINS FUNCTION WORKS ON A STRUCT TYPE (RECEIVER OF THE FUNCTION) VARIABLES ARE EITHER STRUCT TYPE OR INTERFACE TYPE OBJECTS IN GO OBJECTS IN JAVA INTERFACE CLASS IMPLEMENTS INTERFACE CLASS EXTENDS METHOD INSIDE CLASS VARIABLES ARE EITHER CLASS TYPE OR INTERFACE TYPE, BUT IT DOES NOT MATTER
  • 18. GOLANG „OBJECTS” ARE HEADLESS • Java has ~ 8/16 byte header in front of each object • Golang has struct, no header • Java array  array of references to objects • Go array  array of struct memory • (interface array is array of references)
  • 19. GOLANG „OBJECTS” ARE HEADLESS • Variables that are struct type hold the value • Variables that are pointer to struct type know what they point to • Variables that are interface type have a reference to the struct and also reference to the struct definition • Let’s have a weird example that will make you understand and remember
  • 20. AND NOW SOMETHING COMPLETELY DIFFERENT JAVA VALUE TYPES
  • 21. WHAT ARE VALUE TYPES IN JAVA? • Project Valhalla started 2014 • byte, short, int, long, float, double, char and boolean are value types • Project Valhalla aims user definable value types • Value types are not objects, they hold only the value
  • 22. GOLANG STRUCT VS. JAVA VALUE TYPE struct interface value type object object header
  • 23. WHY DO WE NEED THEM? • For example Date is a good candidate to be a value type • Old mistake: object has synchronization lock support (seemed to be a good idea) • Objects occupy the heap, value types are allocated on the stack • Value type arrays are CPU cache friendly Codes like a class, works like an int!
  • 24. CONSEQUENCES • Compare with == • Value type variable can not be null • Limited or no inheritance • Even if there is inheritance we cannot have polymorphism • Method call pass-by-value
  • 25. CONSEQUENCES FOR JVM • Scala Value Type can be extended (restricted to 1 field) • Languages like Swift, Golang can be effectively compiled to JVM or not… • Many cases we can stop joking around with off-heap memory mapped files for high performance data intensive application
  • 27. TAKEAWAY • Java is good as it is • But it can be and it will be better with value types • Java will always be better • and better • Go, and learn go to be a better (Java) programmer. https://play.golang.org/

Editor's Notes

  1. Title slide with speaker’s photo
  2. Key text photo
  3. Key text photo
  4. Key text photo
  5. Key text photo
  6. Key text photo
  7. Key text photo
  8. Key text photo
  9. Key text photo
  10. https://play.golang.org/p/0hAjISo83w1
  11. Key text photo
  12. Key text photo
  13. Key text photo
  14. Key text photo
  15. Key text photo
  16. Key text photo
  17. Key text photo
  18. Key text photo
  19. Key text photo
  20. Key text photo
  21. Key text photo
  22. Key text photo
  23. Key text photo
  24. Key text photo
  25. Key text photo
  26. Key text photo
  27. Key text photo
  28. Key text photo