Deck JAVA 8 ( Nashorn )
Quiz yourself by thinking what should be in
each of the black spaces below before clicking
on it to display the answer.
Help!
|
|
||||
---|---|---|---|---|---|
Acessando classes Java | jjs> Packages.MyPackage
[JavaPackage MyPackage]
jjs> Packages.MyPackage.MyClass
[JavaClass MyPackage.MyClass]
🗑
|
||||
Criando objetos Java | jjs> var HashMap = Java.type("java.util.HashMap")
jjs> var mapDef = new HashMap()
jjs> var map100 = new HashMap(100)
🗑
|
||||
Usando Java Beans | jjs> var Date = Java.type("java.util.Date")
jjs> var date = new Date()
jjs> date.year + 1900
2013
jjs> date.year = 2014 - 1900
114
jjs> date.year + 1900
2014
🗑
|
||||
Criando um mecanismo de scrip Nashorn | ScriptEngine engine = factory.getEngineByName("nashorn");
🗑
|
||||
Trabalhando com números Java | jjs> var intNum = 10
jjs> intNum.class
class java.lang.Integer
jjs> var dblNum = Number(intNum)
jjs> dblNum.class
class java.lang.Double
🗑
|
||||
Extensão de classe em Java | var Run = Java.type("java.lang.Runnable");
var MyRun = Java.extend(Run, {
run: function() {
print("Run in separate thread");
}
});
var Thread = Java.type("java.lang.Thread");
var th = new Thread(new MyRun());
🗑
|
||||
Habilitar extensões de script em shell(UNIX) | jjs -scripting
🗑
|
||||
Here Document | $ jjs -scripting heredocs.js
So...
foo = bar
and the current time is
Thu Aug 01 2013 16:21:16 GMT+0200 (CEST)
$
🗑
|
||||
Shell invocations | var lines =
'ls -lsa'.split("\n");
for each (var line in lines) {
print("|> " + line);
}
🗑
|
||||
Nashorn interpreta as coleções Java como arrays | jjs> var ArrayList = Java.type("java.util.ArrayList")
jjs> var alist = new ArrayList()
jjs> alist.add("a")
true
jjs> alist.add("b")
true
jjs> alist.add("c")
true
jjs> alist[1]
b
jjs> for each (var i in alist) print(i)
a
b
c
🗑
|
||||
Strings são interpretadas pelo Nashorn como objetos java.lang.String | jjs> var a = "abc"
jjs> a.class
class java.lang.String
jjs> var b = a + "def"
jjs> b.class
class jdk.nashorn.internal.runtime.ConsString
jjs> var c = String(b)
jjs> c.class
class java.lang.String
🗑
|
||||
Objetos Globais $ARG | >> jjs -scripting -- arg1 arg2 arg3
jjs> $ARG
arg1,arg2,arg3
jjs> $ARG[1]
arg2
🗑
|
||||
Objetos Globais $ENV | jjs> $ENV.USER
johndoe
jjs> $ENV.PWD
/foo/bar
🗑
|
||||
Objetos Globais $EXEC() | jjs> $EXEC("ls -l")
total 0
drwxr-xr-x+ 1 johndoe staff 4096 Aug 18 11:03 dir
-rwxrw-r-- 1 johndoe staff 168 Aug 19 17:44 file.txt
jjs>
🗑
|
||||
load()Essa função carrega e avalia um script de um caminho, URL, ou um objeto. | jjs> load("/foo/bar/script.js")
jjs> load("http://example.com/script.js")
🗑
|
||||
A função Java.type pode ser usada para se obter referências precisas do tipo Java | var LinkedList = Java.type(
"java.util.LinkedList");
var primitiveInt = Java.type(
"int");
var arrayOfInts = Java.type(
"int[]");
🗑
|
||||
Interpretar uma aplicação de script JavaFX com o Nashorn, usando o mando jjs com a opção -fx | jjs -fx JavaFXscript.js
🗑
|
||||
Funções | function sqr(x) x * x;
print(sqr(3));
🗑
|
Review the information in the table. When you are ready to quiz yourself you can hide individual columns or the entire table. Then you can click on the empty cells to reveal the answer. Try to recall what will be displayed before clicking the empty cell.
To hide a column, click on the column name.
To hide the entire table, click on the "Hide All" button.
You may also shuffle the rows of the table by clicking on the "Shuffle" button.
Or sort by any of the columns using the down arrow next to any column heading.
If you know all the data on any row, you can temporarily remove it by tapping the trash can to the right of the row.
To hide a column, click on the column name.
To hide the entire table, click on the "Hide All" button.
You may also shuffle the rows of the table by clicking on the "Shuffle" button.
Or sort by any of the columns using the down arrow next to any column heading.
If you know all the data on any row, you can temporarily remove it by tapping the trash can to the right of the row.
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.
Normal Size Small Size show me how
Normal Size Small Size show me how
Created by:
marcelotmr
Popular Computers sets