Friday, November 13, 2015

OO Hello World - Nashorn



Hello world in Nashorn is here! An ECMAScript/JavaScript engine implemented by Oracle.

"The Nashorn engine is an implementation of the ECMAScript Edition 5.1 Language Specification. It was fully developed in the Java language as part of the Nashorn project. The code is based on the new features of the Da Vinci Machine, which is the reference implementation of Java Specification Request (JSR) 292: Supporting Dynamically Typed Languages on the Java Platform. 

The Nashorn engine is included in the Java SE Development Kit (JDK). You can invoke Nashorn from a Java application using the Java Scripting API to interpret embedded scripts, or you can pass the script to the jjs or jrunscript tool." Taken from https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/intro.html


By the way, you can see my previous post here: http://carlosqt.blogspot.com/2010/06/oo-hello-world.html where I give some details on WHY these "OO Hello World series" samples.

Version 1 (Minimal):
The minimum you need to type to get your program compiled and running.
function Greet(name) {
 this.name = name.charAt(0).toUpperCase() + name.slice(1, name.length); 
 this.salute = function() {
  print("Hello " + this.name + "!");
 }
}

// Greet the world!
var g = new Greet("world");
g.salute();

Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.
function Greet(name) {
 this.name = name.charAt(0).toUpperCase() + name.slice(1, name.length); 
}

Greet.prototype.salute = function() {
 print("Hello " + this.name + "!");
}

var g = new Greet("world");
g.salute();

The Program Output:





  



Nashorn Info:
“Nashorn is a JavaScript engine developed in the Java programming language by Oracle. It is based on the Da Vinci Machine (JSR 292) and has been released with Java 8.” Taken from: https://en.wikipedia.org/wiki/Nashorn_(JavaScript_engine)

Appeared:
2014
Current Version:
Nashorn 1.8 JavaScript 5.1  (latest version in "Languages" page
Developed by:
Oracle
Creator:
Oracle
Influenced by:
JavaScript (Brendan Eich)
Predecessor Language
Rhino
Predecessor Appeared
1997
Predecessor Creator
Oracle
Runtime Target:
JDK
Latest Framework Target:
8
Mono Target:
N/A
Allows Unmanaged Code:
No
Source Code Extension:
“.js”
Keywords:

Case Sensitive:
Yes
Free Version Available:
Yes
Open Source:
Yes
Standard:
JSR292 ECMA-262
Latest IDE Support:
Any text editor for JavaScript
https://netbeans.org
Language Reference:
Extra Info:


4 comments:

  1. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    Security Services in Chennai

    ReplyDelete
  2. keep sharing your information regularly for my future reference. This content creates a new hope and inspiration with in me
    Invisalign Treatment In Chennai

    ReplyDelete
  3. Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
    SEO Company in Chennai

    ReplyDelete
  4. I just see the post i am so happy the post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.

    Digital Marketing Course in Chennai

    ReplyDelete