• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Clojure/Java Interop "Hello World"

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best chance I have of getting Clojure into my company is to introduce it via small helper APIs that can be called by regular Java code. For example, I imagine tree/node manipulation would be much simpler to code in Clojure. But it would only be useful if POJ (plain ol' Java) could interact with it to perform CRUD.

Is there a good document that shows how to:
1) Write Clojure code that can be accessed by POJ?
2) Access that code via POJ?

In other words, is there a "Hello World" for Clojure/Java interop.

Thanks!
Sean
 
Rancher
Posts: 379
22
Mac OS X Monad Clojure Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a Hello World example here:

http://clojure.org/compilation

To create functions callable from Java you need to remember that the first argument is 'this' (which is implicitly passed to Java methods).

Hopefully someone can point you to more specific Java interop examples but once you have your first function working, it's pretty much plain sailing from then on (in my experience).
 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show them simple yet important examples like how to iterate over a data structures in Clojure, this will make them cry immediately as they will recall how million times they wrote for loops in Java.
You can also solve the sleeping barber shop algorithm in Clojure to show them how elegant the concurrency programming in Clojure really is.
 
Sean Crotty
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sean Corfield wrote:There's a Hello World example here:

http://clojure.org/compilation

To create functions callable from Java you need to remember that the first argument is 'this' (which is implicitly passed to Java methods).

Hopefully someone can point you to more specific Java interop examples but once you have your first function working, it's pretty much plain sailing from then on (in my experience).


Thanks, Sean. That is a very helpful link!
 
Straws are for suckers. Now suck on this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic