SlideShare a Scribd company logo
Clojure
for
Java developers
Assumptions
Some experience with Java development
Little or no experience with Clojure
You want to try something different!
Haskell, Erlang and
Scala seem hairy!
Why Clojure ?
Why get functional ?
4 cores in a typical developers Mac book Pro
How long until 128 cores
in a laptop is common?
Parallelism made simpler
Provides tools to create massively parallel
applications
Not a panacea
Think differently
Functional concepts
Changing state
What is Clojure
One of many JVM languages
Java
Groovy
JRuby
Jython
Scala
Clojure
Jaskell
Erjalang
A little more ubiquitous
.Net framework – DLR/CLR
In browsers > ClojureScript
Native compilers
Clojure for Java developers
Very small syntax
( )
[ ], { }
def, defn, defproject
list, map, vector, set
let
.
_
atom
Mathematical concepts
Functions have a value
For a given set of arguments, you
should always get the same
result
(Referential transparency)
Clojure concepts
Encourages Pure Functional approach
- use STM to change state
Functions as first class citizens
- functions as arguments as they return a value
Make JVM interoperation simple
- easy to use your existing Java applications
A better Lisp !
Sensible () usage
Sensible macro names
JVM Interoperability
Lisp is the 2nd oldest programming language still in use
Which LISP is your wingman ?
Common Lisp Clojure
Clojure is modular
Clojure for Java developers
Comparing Clojure
with Java
The dark side of Clojure
( x )( x )
The dark side of Clojure
( ( x ) )( ( x ) )
The dark side of Clojure
( ( ( x ) ) )( ( ( x ) ) )
The dark side of Clojure
( ( ( ( x ) ) ) )( ( ( ( x ) ) ) )
The dark side of Clojure
( ( ( ( ( x ) ) ) ) )( ( ( ( ( x ) ) ) ) )
()
verses
{ () };
Clojure verses Java syntax
([] (([])))
verses
{ ({([])}) };
Well actually more like....
Clojure for Java developers
Its all byte code in the end..
Any object in Clojure is just a regular java
object
Types inherit from:
java.lang.object
What class is that...
(class "Jr0cket")
=> java.lang.String
(class
(defn hello-world [name]
(str "Hello cruel world")))
=> clojure.lang.Var
Using (type …) you can discover either the metadata or class of something
Prefix notation
3 + 4 + 5 – 6 / 3
(+ 3 4 5 (- (/ 6 3)))
Java made simpler
// Java
import java.util.Date;
{
Date currentDate = new Date();
}
; Clojure
(import java.util.Date)
(new Date)
Ratio
Unique data type
Allow lazy evaluation
Avoid loss of
precision
(/ 2 4)
(/ 2.0 4)
(/ 1 3)
(/ 1.0 3)
(class (/ 1 3)
Prefix notation everywhere
(defn square-the-number [x]
(* x x))
Defining a data structure
( def my-data-structure [ data ] )
( def days-of-the-week
[“Monday” “Tuesday” “Wednesday”])
You can dynamically redefine what the name binds to, but the vector is immutable
Really simple data structure
(def jr0cket
{:first-name "John",
:last-name "Stevenson"})
Using a map to hold key-value pairs.
A good way to group data into a meaningful concept
Defining simple data
(def name data)
Calling Behaviour
(function-name data data)
Immutable
Data structures
List – Ordered collection
(list 1 3 5 7)
'(1 3 5 7)
(quote (1 3 5 7))
(1 2 3) ; 1 is not a function
Vectors – hashed ordered list
[:matrix-characters
[:neo :morpheus :trinity :smith]]
(first
[:neo :morpheus :trinity :smith])
(nth
[:matrix :babylon5 :firefly] 2)
(concat [:neo] [:trinity])
Maps – unordered key/values
{:a 1 :b 2}
{:a 1, :b 2}
{ :a 1 :b }
java.lang.ArrayIndexOutOfBounds
Exception: 3
{ :a 1 :b 2}
{:a 1, :b 2}
{:a {:a 1}}
{:a {:a 1}}
{{:a 1} :a}
{{:a 1} :a}
; idiom - put :a on the left
Lists are for code
and data
Vectors are for data
and arguments
Its not that black and white, but its a useful starting point when learning
Interacting
With
Java
Joda Time
(use 'clj-time.core)
(date-time 1986 10 14)
(hour (date-time 1986 10 14 22))
(from-time-zone (date-time 2012 10 17)
(time-zone-for-offset -8))
(after? (date-time 1986 10)
(date-time 1986 9))
(show-formatters)
Clojure for Java developers
Importing Java into Clojure
(ns drawing-demo
(:import [javax.swing Jpanel JFrame]
[java.awt Dimension]))
Calling Java GUI
(javax.swing.JOptionPane/showMessageDialog nil
"Hello Java Developers" )
do makes swing easy
Simplifying with doto
doto evaluates the first expression in a chain of expressions and saves it in a
temporary variable. It then inserts that variable as the first argument in each of the
following expressions. Finally, doto returns the value of the temporary variable.
Working with Java
Java Classes
● fullstop after class name
(JFrame. )
(Math/cos 3) ; static method call
Java methods
● fullstop before method name
(.getContentPane frame) ;;method name first
(. frame getContentPane) ;;object first
Get coding !
clojure.org
docs.clojure.org
All hail the REPL
An interactive shell for
clojure
Fast feedback loop
for clojure
Clojure for Java developers
Clojure for Java developers
Managing a Clojure
project
Maven
Just like any other Java project
Step 1)
Add Clojure library dependency to your
POM
Step 2)
Download the Internet !!!
Leiningen
lein new
lein deps
lein repl
lein jack-in
● Create a new Clojure project
● Download all dependencies
● Start the interactive shell (repl)
● Start a REPL server
leiningen.org
Clojure for Java developers
Eclipse & Clojure
= Counter Clockwise
Emacs
Clojure for Java developers
Clojure for Java developers
Light table
Kickstarter project to build a development environment,
focused on the developer experience
Clojure for Java developers
Functional Web
webnoir.org
Clojure calling Java web stuff
(let [conn]
(doto (HttpUrlConnection. Url)
(.setRequestMethod “POST”)
(.setDoOutput true)
(.setInstaneFollowRedirects
true))])
Deploy Clojure to the Cloud
lein new heroku my-web-app
Getting a little more functional
Recursive functions
● Functions that call
themselves
● Fractal coding
● Tail recursion
● Avoids blowing the
stack
● A trick as the JVM
does not support tail
recursion directly :-(
Recursion – managing memory
(defn recursive-counter [value]
(print value)
(if (< value 1000)
(recur (+ value 4))))
(recursive-counter 100)
Mutable State
Software Transactional Memory
Provides safe,
concurrent access to
memory
Agents allow
encapsulated access
to mutable resources
http://www.studiotonne.com/illustration/software-transactional-memory/
Atoms - Coding state changes
; Clojure atom code
(def mouseposition (atom [0 0]))
(let [[mx my] @mouseposition])
(reset! mouseposition [x y])
Database access
Clojure-contrib has sql
library
Korma - "Tasty SQL for
Clojure"
CongoMongo for
MongoDB
https://devcenter.heroku.com/articles/clojure-web-application
Getting Creative
with Clojure
Overtone: Music to your ears
Where to find out more...
clojure.org/
cheatsheet
Hacking Clojure challenges
Thank you
@jr0cket
London Clojurians
Google Group

More Related Content

ODP
Getting started with Clojure
John Stevenson
 
PDF
Fun with Functional Programming in Clojure
Codemotion
 
PDF
Clojure, Plain and Simple
Ben Mabey
 
KEY
Clojure Intro
thnetos
 
PDF
Clojure made-simple - John Stevenson
JAX London
 
PDF
Clojure for Java developers - Stockholm
Jan Kronquist
 
PDF
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
PDF
Kotlin @ Coupang Backend 2017
Sunghyouk Bae
 
Getting started with Clojure
John Stevenson
 
Fun with Functional Programming in Clojure
Codemotion
 
Clojure, Plain and Simple
Ben Mabey
 
Clojure Intro
thnetos
 
Clojure made-simple - John Stevenson
JAX London
 
Clojure for Java developers - Stockholm
Jan Kronquist
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Kotlin @ Coupang Backend 2017
Sunghyouk Bae
 

What's hot (20)

PPTX
Kotlin coroutines and spring framework
Sunghyouk Bae
 
PDF
JavaOne 2013 - Clojure for Java Developers
Jan Kronquist
 
PDF
Clojure in real life 17.10.2014
Metosin Oy
 
PDF
Exploring Clojurescript
Luke Donnet
 
PDF
From Java to Parellel Clojure - Clojure South 2019
Leonardo Borges
 
PDF
Introduction to clojure
Abbas Raza
 
PDF
Oscon Java Testing on the Fast Lane
Andres Almiray
 
PDF
Scala coated JVM
Stuart Roebuck
 
PDF
Clojure - A new Lisp
elliando dias
 
PDF
Seeking Clojure
chrisriceuk
 
PDF
Moose
ndronen
 
PPTX
Kotlin is charming; The reasons Java engineers should start Kotlin.
JustSystems Corporation
 
PPTX
Adventures in TclOO
Donal Fellows
 
PPTX
TclOO: Past Present Future
Donal Fellows
 
PPT
Scala introduction
Yardena Meymann
 
PDF
#살아있다 #자프링외길12년차 #코프링2개월생존기
Arawn Park
 
PDF
Kotlin: a better Java
Nils Breunese
 
PPTX
Kotlin – the future of android
DJ Rausch
 
PPTX
Making Java Groovy (JavaOne 2013)
Ken Kousen
 
PDF
Excuse me, sir, do you have a moment to talk about tests in Kotlin
leonsabr
 
Kotlin coroutines and spring framework
Sunghyouk Bae
 
JavaOne 2013 - Clojure for Java Developers
Jan Kronquist
 
Clojure in real life 17.10.2014
Metosin Oy
 
Exploring Clojurescript
Luke Donnet
 
From Java to Parellel Clojure - Clojure South 2019
Leonardo Borges
 
Introduction to clojure
Abbas Raza
 
Oscon Java Testing on the Fast Lane
Andres Almiray
 
Scala coated JVM
Stuart Roebuck
 
Clojure - A new Lisp
elliando dias
 
Seeking Clojure
chrisriceuk
 
Moose
ndronen
 
Kotlin is charming; The reasons Java engineers should start Kotlin.
JustSystems Corporation
 
Adventures in TclOO
Donal Fellows
 
TclOO: Past Present Future
Donal Fellows
 
Scala introduction
Yardena Meymann
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
Arawn Park
 
Kotlin: a better Java
Nils Breunese
 
Kotlin – the future of android
DJ Rausch
 
Making Java Groovy (JavaOne 2013)
Ken Kousen
 
Excuse me, sir, do you have a moment to talk about tests in Kotlin
leonsabr
 
Ad

Viewers also liked (20)

PDF
Clojure: an overview
Larry Diehl
 
PDF
Clojure: The Art of Abstraction
Alex Miller
 
PDF
Writing DSL in Clojure
Misha Kozik
 
PDF
DSL in Clojure
Misha Kozik
 
PDF
ETL in Clojure
Dmitriy Morozov
 
PDF
Clojure: Towards The Essence of Programming
Howard Lewis Ship
 
PDF
3 years with Clojure
Michael Klishin
 
KEY
Functional programming in clojure
Juan-Manuel Gimeno
 
PDF
Clojure, Web and Luminus
Edward Tsech
 
PDF
Intro to Java 8 Closures (Dainius Mezanskas)
Kaunas Java User Group
 
PDF
Functional Reactive Programming in Clojurescript
Leonardo Borges
 
PDF
JS Lab`16. Роман Лютиков: "ClojureScript, что ты такое?"
GeeksLab Odessa
 
PDF
Elixir talk
Cory Gwin
 
PDF
Clojure class
Aysylu Greenberg
 
PPTX
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Hakka Labs
 
PDF
Messaging With Erlang And Jabber
l xf
 
PDF
20 reasons why we don't need architects (@pavlobaron)
Pavlo Baron
 
PDF
Clojure values
Christophe Grand
 
PDF
High Performance Erlang
PerconaPerformance
 
KEY
Winning the Erlang Edit•Build•Test Cycle
Rusty Klophaus
 
Clojure: an overview
Larry Diehl
 
Clojure: The Art of Abstraction
Alex Miller
 
Writing DSL in Clojure
Misha Kozik
 
DSL in Clojure
Misha Kozik
 
ETL in Clojure
Dmitriy Morozov
 
Clojure: Towards The Essence of Programming
Howard Lewis Ship
 
3 years with Clojure
Michael Klishin
 
Functional programming in clojure
Juan-Manuel Gimeno
 
Clojure, Web and Luminus
Edward Tsech
 
Intro to Java 8 Closures (Dainius Mezanskas)
Kaunas Java User Group
 
Functional Reactive Programming in Clojurescript
Leonardo Borges
 
JS Lab`16. Роман Лютиков: "ClojureScript, что ты такое?"
GeeksLab Odessa
 
Elixir talk
Cory Gwin
 
Clojure class
Aysylu Greenberg
 
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Hakka Labs
 
Messaging With Erlang And Jabber
l xf
 
20 reasons why we don't need architects (@pavlobaron)
Pavlo Baron
 
Clojure values
Christophe Grand
 
High Performance Erlang
PerconaPerformance
 
Winning the Erlang Edit•Build•Test Cycle
Rusty Klophaus
 
Ad

Similar to Clojure for Java developers (20)

PPTX
Clojure Fundamentals Course For Beginners
Paddy Lock
 
PDF
55j7
swein2
 
PPTX
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
 
PPTX
Introduction to Ecmascript - ES6
Nilesh Jayanandana
 
PDF
Clojure - A practical LISP for the JVM
Matthias Nüßler
 
ODP
Clojure
alandipert
 
PDF
AJS UNIT-1 2021-converted.pdf
SreeVani74
 
PDF
Clojure and The Robot Apocalypse
elliando dias
 
PPTX
Concurrency Constructs Overview
stasimus
 
PPT
Introduction to java
Sujit Majety
 
PPTX
DevNexus 2018: Learn Java 8, lambdas and functional programming
Henri Tremblay
 
PDF
Short intro to scala and the play framework
Felipe
 
PDF
A Survey of Concurrency Constructs
Ted Leung
 
PDF
Scala and jvm_languages_praveen_technologist
pmanvi
 
PDF
Object Oriented Programming with Java Basic Syntax.pdf
BINJAD1
 
PPTX
JavaScript Beyond jQuery
Bobby Bryant
 
PPTX
Modern JavaScript Development @ DotNetToscana
Matteo Baglini
 
PDF
Java essentials for hadoop
Seo Gyansha
 
PDF
Java essentials for hadoop
KCC Software Ltd. & Easylearning.guru
 
Clojure Fundamentals Course For Beginners
Paddy Lock
 
55j7
swein2
 
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
 
Introduction to Ecmascript - ES6
Nilesh Jayanandana
 
Clojure - A practical LISP for the JVM
Matthias Nüßler
 
Clojure
alandipert
 
AJS UNIT-1 2021-converted.pdf
SreeVani74
 
Clojure and The Robot Apocalypse
elliando dias
 
Concurrency Constructs Overview
stasimus
 
Introduction to java
Sujit Majety
 
DevNexus 2018: Learn Java 8, lambdas and functional programming
Henri Tremblay
 
Short intro to scala and the play framework
Felipe
 
A Survey of Concurrency Constructs
Ted Leung
 
Scala and jvm_languages_praveen_technologist
pmanvi
 
Object Oriented Programming with Java Basic Syntax.pdf
BINJAD1
 
JavaScript Beyond jQuery
Bobby Bryant
 
Modern JavaScript Development @ DotNetToscana
Matteo Baglini
 
Java essentials for hadoop
Seo Gyansha
 
Java essentials for hadoop
KCC Software Ltd. & Easylearning.guru
 

More from John Stevenson (20)

PDF
ClojureX Conference 2017 - 10 amazing years of Clojure
John Stevenson
 
PDF
Confessions of a developer community builder
John Stevenson
 
PDF
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
John Stevenson
 
PDF
Introduction to Functional Reactive Web with Clojurescript
John Stevenson
 
PDF
Thinking Functionally with Clojure
John Stevenson
 
PDF
Communication improbable
John Stevenson
 
PDF
Getting into public speaking at conferences
John Stevenson
 
PDF
Functional web with clojure
John Stevenson
 
PDF
Get into Functional Programming with Clojure
John Stevenson
 
PDF
Guiding people into Clojure
John Stevenson
 
PDF
Git and github - Verson Control for the Modern Developer
John Stevenson
 
PDF
Get Functional Programming with Clojure
John Stevenson
 
PDF
So you want to run a developer event, are you crazy?
John Stevenson
 
PPTX
Trailhead live - Overview of Salesforce App Cloud
John Stevenson
 
PPTX
Introducing the Salesforce platform
John Stevenson
 
PPT
Dreamforce14 Metadata Management with Git Version Control
John Stevenson
 
PPT
Salesforce Summer of Hacks London - Introduction
John Stevenson
 
PPTX
Heroku Introduction: Scaling customer facing apps & services
John Stevenson
 
PPT
Developers guide to the Salesforce1 Platform
John Stevenson
 
PPTX
Developer week EMEA - Salesforce1 Mobile App overview
John Stevenson
 
ClojureX Conference 2017 - 10 amazing years of Clojure
John Stevenson
 
Confessions of a developer community builder
John Stevenson
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
John Stevenson
 
Introduction to Functional Reactive Web with Clojurescript
John Stevenson
 
Thinking Functionally with Clojure
John Stevenson
 
Communication improbable
John Stevenson
 
Getting into public speaking at conferences
John Stevenson
 
Functional web with clojure
John Stevenson
 
Get into Functional Programming with Clojure
John Stevenson
 
Guiding people into Clojure
John Stevenson
 
Git and github - Verson Control for the Modern Developer
John Stevenson
 
Get Functional Programming with Clojure
John Stevenson
 
So you want to run a developer event, are you crazy?
John Stevenson
 
Trailhead live - Overview of Salesforce App Cloud
John Stevenson
 
Introducing the Salesforce platform
John Stevenson
 
Dreamforce14 Metadata Management with Git Version Control
John Stevenson
 
Salesforce Summer of Hacks London - Introduction
John Stevenson
 
Heroku Introduction: Scaling customer facing apps & services
John Stevenson
 
Developers guide to the Salesforce1 Platform
John Stevenson
 
Developer week EMEA - Salesforce1 Mobile App overview
John Stevenson
 

Recently uploaded (20)

PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 

Clojure for Java developers