 I'm Stefan. I'm probably older than the rest of the people here in the room. I work as a software engineer for IBM, currently in service delivery during the day. During the night, I work on IBM Verse. Hashtag it could be worse. That's our email product. It's currently written in Dojo, which led me to the conclusion I must have been a really, really bad boy in my last life to get that punishment. When people talk about V8, what comes to my mind is something like that one. That's a V8. So I was looking, I said, are there alternatives and options do you have? I said, okay, let's have a look when I want to run JavaScript. What are my options, actually? Then have a look at Nassan, which is kind of funny because I'm German and I know what it means. A little bit of thought on performance. And then the main attraction is I want to talk a little bit about WordX, which is one of the implementations how to run JavaScript on the JVM. So there's a number of options of V8 everybody else, by their monkey chakra or whatever. What you see in the last column is that they run in all different environments. And the V8 actually was a little bit shoehorned into running on the operating system out of Chrome, like they liberate the JVM, liberate the JavaScript runtime engine. But it's not the only game in town. Oops, okay. Is that the right slide? No, that's the right slide. Okay. We had, starting with a project in Mozilla, the first JavaScript engine in the JVM called Rhino. And in Java 8 Oracle rewrote the whole thing and called it Nassan, which is German for Rhino. And which is kind of funny because, like I say, it's not fully up to date. So ECM-A 5.1, it's mostly called inside of JVM-based applications. All the blue things, when you look up the slides later, there are links to the respective sources behind. And the most interesting part that it's spawned from hell, I mean, you can spawn threads in Java script to run multi-threaded natively. So you have access to the command line using a J-run script or JJ-JS. The interesting part, it has full access to all sorts of Java classes, but it's not really part of the NPM universe. I'm a little worried about that in a second. So how does it look like? I need to sit down and look at my glasses terminal. So I can go and say JJ-S and I get a prompt similar to when you just type node. And then I can say, like, say, Rx equals 7. Oops. Oh, I shouldn't do colons, OK. Rx equals 7. And the big difference is, like I say, you know, in Node.js you get undefined and here you don't get any prompt back. But that's the same thing. And then you say, OK, I do print X while boring. And the nice little thing is you don't need to type in control C. You have a proper exit function. Yeah. So of course you can go and write a Java script program. I got a few ready-made here. So hello world. No, you know. First, let's have a look how it looks like. Hello world.js. Oh, I gave it away already. Sorry. When you run JJ-S, hello world, let's use the usually on the node one. Then I get the reference error console not defined. Yeah. Console.log is not available in the JVM. So you have to cheat a little bit and you see the cheating capability up here. I said, if I don't have a console, then at least load the console. And console.js, which is kind of funny as well. Ups, can't console.js. Actually, simply use this. Can you see that? Java lang system out front line. Which is kind of hilarious on one side and the other side. It shows you simple. I said, hey, anything that is in Java can be used in there. Which is kind of already points in the direction for the use cases. We said, okay, I want to go and introduce my fellow old backs in the company to do a little bit more dynamic languages. Part demo. We got five million lines of Java code. That's your entry into the system. So that's one of the main points there. So where's my presentation over here? Can you execute the Java program using this? Yep. Yep. Sure. That it. You can. That's fine. You can. From the Java script you run in nas on. You can run a Java program from a Java program. You can run a nas on script. So up to you. So. And then that was what we just say. Like say, no JS. We know. Console the lock. Hello world. In nas on, it's print and then universal one is you have this little funny little thing that says, okay, console. You simply emulate the console JS. So the other thing is what I find pretty cool is when you put at the beginning of your line, you put your point to the JS, you can use Java script as normal shell scripts and run them on the command line. Like your bash scripts as well, which is kind of. They were there first before no JS. And then to your question a little bit in Java, you get these script engine manager and then you say get engine by name, which then goes and picks, executes the Java script. And inside you see this land Java lot. You get a class and you can call any method of the class. I haven't tried running a sub mine before, but I don't see a reason why it wouldn't work. So of course, like said, no JS, JavaScript runtime on its own is boring. So you need classes and nas on and NPM are no friends. They're a little bit like the German and the French. We had two world wars before we started to become friends. It's still not sorted out. Any friendship? So there is a number of... There's a reason why I'm used to German and the French example. There's a number of modules around where nas on was shoe on into support NPM and like a world war, there are a lot of dead bodies at the end of the day. No doing is dead. NPM is dead. Nas on common JS I think is still around. Nobody knows because it's sponsored by Oracle and we all know like say our friends in Oracle, if there's no database license to be sold, they're not so interested. I shouldn't say that. So the other point that comes up quite regularly is, hey, what's about performance? We all love VA because it's nice and performance. And then you see nas on. That's how long it takes. Long is bad. Short is better. And this is the V8. The funny little thing, cold and warm, you've seen the two lines with the initialized JavaScript engine. The whole thing is like a good old car takes a while to warm up. I remember when I grew up in Germany, I had one of these Mercedes diesel, baby talk dirty to me diesel. And in the winter, it took 10 minutes before you could move. Similar with the NASA engine, I said, it takes a while to start. It's almost like a Zen engine. Oh, let's do something. But when you look closer, what's quite interesting, and as I said, the blue lines are all the links to the sources. They ran a comparison of what happens if I do things many, many, many times. The yellow one is still node, the king on the block. But then you realize once the initial delay in the startup is gone, then the performance is actually, the average performance, actually quite OK. So depending on what you do, the performance penalty might not be that bad. One interesting aspect, which is especially in that article, they realized they watched the CPUs and they figured out that NASA automatically is starting to use multiple CPU cores. Well, like I said, you're in an OGS program, you actually have to do quite a bit of exercises before your application takes advantage of multiple cores. Reading, I'm not going to click on it. There are two links to this huge web performance test where they had all these applications where a NASA-based framework, which I'm going to introduce in a second, came out top for a number of the tasks in there. Which brings me to my favorite little toy. What? WordX. Irony, Irony, WordX is a tool that runs on the JVM, and if you install it, you use NPM. That's kind of hilarious. Now, you can use Maven to install it, you can use Gradle to install it, and a few other things. Well, like I found, since I got Node.js anywhere in the machine, I found that quite easy to do so. It's mainly sponsored by Red Hat, so that's people who don't do open source as a hobby. So not like Oracle or IBM, but no, we do a lot of that. And the interesting thing is, two or three things, it is polyglot. So for me, it was easy in the beginning, I wrote my stuff in Java, and then I switched over a little bit of JavaScript and I doubled a little bit with Ruby. And you can write different modules in different languages and then you can talk to each other. The modules are called verticals. Now you can guess how would you call the test modules. A little bit more laugh at least. There are a bunch of blueprints and examples there, so there's quite extensive documentation. And I had to pick, based on the time, one feature I really like, and what I like is the event bus. So what you can do is you write your little vertical and then you test the vertical properly. And it has an event bus, so I can go and publish a message on an event bus, and there can be any number of subscribers who react to that, and then you get a message back. The interesting part on that one is that the event bus, that can be the same machine, it can be a different task, it can be a cluster of machines, and it's still the same code. It's just a start-up option. When you want to run anything WordX, you have a WordX command line, WordX run, starts an application in the foreground, WordX start starts an application in the background. So you can go WordX start one after the other. The only thing that I haven't figured out yet, I didn't bother, is where does it write the console log if you run it in the background. Let's have a quick look. I forgot my names again, so I say WordX run, and then I say hello world server. So it takes a moment, so that's the contemplation second, and they said, okay, succeeded in deploying the vertical, and I think I put it on 8080, proper people to curl. Curl, local, host, 8080, and it says hello from WordX. Let's have a quick look at the code. I have that on the thing. So it looks suspiciously familiar, create HTTP server, request handler. The only difference is you don't get request response next, like in Express. You only have a request object, and the request object has a dot response. But the general principle is like, if you've done anything in Express, you will find yourself very familiar in the WordX environment as well. So that's an easy one. The next one, I say what I told, event bus. I can write, I take the event bus, I said I'm a consumer to some address, I handle a message, I do something with a message body that can be string, that can be a JSON array, a JSON object, whatever, and then I can actually reply to that. And as a sender, I simply say event bus publish, it's like whoever takes it, or event bus send, first one who listens to the address gets it. For instance, you've got like say, 10 database connections sitting on 10 machines, and you say event bus send, one will get it and process it so you nicely can scale out your capabilities. Let me just show you the one. So I have which one it was, event bus one. So in this one, again you get this little moment to where it waits, the example code is all on the guitar, and my sender says okay, I fire all the requests, this one comes in from the processing, and then I say reject the proof, reject the proof that basically I throw a random number whether you can do it or not. So not very exciting, let's have a quick look at the code. So I just go and says okay, I use here event bus set pre-ordered, so I have something that is 10,000, so that's every 10 seconds, it creates a request and it sends it up. And then it says okay, and so it has fired, and a little bit up, not more than showing you that, I have the receiving function which then proceeds the result. I have a second variation of that, so event bus number two, that's the same thing roughly, the only difference is that I also start a web server, so it deploys a vertical, every 10 seconds it will send a request out over the bus to the receiver, but I also can go and say okay, I say color gloss, I want ice cream, and then it says approved, you can have ice cream. Because that's uneasy down there, there is a bunch of stuff coming up, let's have a look a little bit at this code, look no bio license message. Sorry, I buy you one. Yes, samples, gosh, gosh, gosh, and they are there. I learned this trick, what was that? Control plus, yeah. Yeah. So you see that in line number five, I said I need the event bus, in line number six, I said I want to listen to the following address, it's very fancy, it's just a string. Of course I say being used to Java stuff with a lot of dots in between, I use the Java package type of name, but you could say the fancy string I want to listen to, then I said okay handle that, get me the message body, in this case checking is really asked, then I approve it, otherwise I throw a random number and I reject it. And that's the whole thing, what I need to do. Whether it's on the same task, whether it's on the same machine, or whether it's on a different machine, it doesn't matter, it's only a matter of how I start the vertical. So when I said I want to run it across multiple machines, then I need to start the vertical with a minus cluster option. So they can listen to each other. The interesting thing about Event Bus, there's libraries available that extend the Event Bus into client-side JavaScript. So you can go and say subscribe under the hood, use soccer dial, you can subscribe to a message from an Event Bus on the server side in your client-side application. So that's pretty cool, I like that a lot. Quick one, just for the complete sake. So... not this one. So it's wordx.il. Now let's see, that's the website where the stuff is at home. And what I found quite helpful is that you've got the documentation and then you've got, I'll say okay, core web data access and what have you, in all languages. So they have building modules for the usual databases, nice asynchronous modules, Mongo, all the relational databases. You keep checking me. Does it work? They have already made JWT, so for your authentication you just can issue a session token. They have all sorts of other stuff there. And then when you go there and say okay, like I want to learn about the core, then you get the little lecture on core is here, where is it? I should simply look at this one, it's easier for me. You get the little lecture on asynchronous and the event pass and writing TCP servers and datagrams and DNS and whatever. So there's a lot of stuff in there. But I also like very close to the idea how we work in JavaScript. Everything is a stream. So you have a stream API where you can make sure that all your applications don't depend on filling in the buffer and then spitting out the complete result. So especially the HTTP clients, both the client as well as the server have stream APIs. So you don't run out of memory so fast. Yup. Back to the slides. All was done. Use cases. I mentioned that before. You have a Java shop and they kind of dabble and say oh, especially with strong administrators. Node.js on my server over my dead cold body. I've heard that a number of times. Actually, it's funny. In IBM we use a lot of Node.js. So if IBM does it, actually, shouldn't we have a problem to get that code? So you get in there. The second thing is like, we see that a little bit in the financial industry, they have huge code bases, very customized Java code. They said, how do I integrate that easily? So you said, okay. With WordX, you can do that relatively painlessly. And then you want to scale out. You torch a lot of calls. Yeah. That's roughly what I wanted to torture with. What I want to introduce to you. Questions? Can you like objects of the Java class inside as a JavaScript? Sure. It's called new. It's called new. It's called new, right? What happens about the prototypical inheritance in Java style? So of course, you have to be a little bit careful. So one of the things is when you go and call Java messes you will be in trouble for anything where you have like say one call that takes 27 different data types. So the NASA engine will try to figure out okay, so what I have there looks like a string, quarks like a string, so I call the string version of it. But he said okay, I have an object as in parameter and it's kind of hmm, is that an object is on the string. So it's not a blind flight so you have to be very, very clear what you want to do. And what I've done a number of times is like say writing a little wrapper to say okay, my Java wrapper has exactly one function. So I said like say execute something as string. Execute something as request, execute something as color to make sure that I don't get into trouble with the overloading that is the kind of the send in the gearbox between JavaScript and Java. Stuff like pointers and things that are just not available. Pointers in Java? If you do that the boogeyman will get you. That's it. No, you don't do pointers in Java. No, we don't right see that. So it's very simple what's not available you need to encapsulate. Where is it? So also be very, very clear like say there's more languages around like that wrap that emulate a JavaScript in Java and I have seen people who jump between Java objects and JavaScript back for back for back for and then they're surprised by their performance sucks. So keep them nicely next to each other like East and West Berlin there was a bridge in the middle one bridge and then they took the wall away. It's horrible. You're very into JVM. Can you use the JavaScript there also to integrate with other languages that are running in JVM? So what the WordX guys did so they got Ruby, Groovy, JavaScript and Java they have when you look in their repository they have the message around if you want to compile it for other languages the adapters they have the instructions there. I know if I'm not mistaken in WordX version 2 they had bindings for JSON as a Python on Java as well as for Scala so if you love Scala it shouldn't be a big deal to go and extend WordX there. Okay, more questions? I know you won't be happy. In general if you just take something in the world that's written in JSON through the JVM using this. So what you need to say what's quite interesting is what the article guys did on the project Avalon which points a little bit in the direction they have a list of JavaScript modules from NPM they found that were working. So any NPM module you'd want to try that requires a native library so you have to replace that piece of code with respective Java methods. What's quite interesting before Netflix actually drank the complete Node.js Kool-Aid they were very actively and I guess they still do that actively using WordX for some of their processing on the Java side. That was basically the the entry drug into the script world by not leaving the JVM which they understood very very well behind. Any more questions? Thank you so much.