Benjamin-Philip

Benjamin-Philip

NIFs vs Jinterface

What’s the difference between NIFs and Jinterface?

From what I can tell, NIFs are for implementing a function natively, with C or, Rust along with Rustler.

Jinterface provides support for using a Java Service along with an Erlang service, by providing classes and methods to create new nodes, new processes and pass and receive messages. Additionally it provides classes for working with Erlang datatypes from within Java.

Apart from the fact that NIFs target native languages, or pretty much anything that implements a C ABI, and that Jinterface targets languages on the JVM, what exactly is the difference between the 2? How could I use a function implemented in Java from Elixir (JNI + NIFs?)?

Most Liked

mpope

mpope

You cannot call a Java function from Erlang directly. However, you communicate to a Java process from Erlang through a Port process (the name is confusing). This is a separate process that the Erlang VM spawns locally. You can use something like a fat jar and spawn the port process when your own application starts. However Ports are a bit tricky to work with directly. An alternative is to use the library Exile. Exile provides some great protections that you’d otherwise need to add yourself.

With the Port you can use the JInterface library’s message serialization code to create responses that Erlang can directly decode, or rely on something more ‘modern’ like a protobuf or JSON blob. Ports are flexible.

Where Next?

Popular in Questions Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New

We're in Beta

About us Mission Statement