SCRIPTING / CATATAN</>↗Scripting20 Jul 2009
package org.kodejava.script; import javax.script.ScriptEngineManager; import javax.script.ScriptEngineFactory; import java.util.List; public class GetSupportedScriptingEngine { public static void main(String[] args) { // Creating an instance of ScriptEngineManager an get the list // of available ScriptEngineFactory. ScriptEngineManager manager = new ScriptEngineManager(); List<ScriptEngineFactory> factories = manager.getEngineFactories(); for (ScriptEngineFactory factory : fa...
SCRIPTING / CATATAN</>↗Scripting19 Jul 2009
This example shows how to get an instance of ScriptEngine by the engine name. Below we are trying to obtain the GraalVM JavaScript engine. package org.kodejava.script; import javax.script.ScriptEngineManager; import javax.script.ScriptEngine; import javax.script.ScriptException; public class GettingScriptEngineByName { public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); // Obtain an instance of ScriptEngine using the […]
SCRIPTING / CATATAN</>↗Scripting18 Jul 2009
The code below will evaluate a simple JavaScript that produces a “Hello World” message. To evaluate the script, the ScriptEngine provides us with some overloaded eval() methods, for instance an eval() methods that accept the script in string or in Reader object. package org.kodejava.script; import javax.script.ScriptEngineManager; import javax.script.ScriptEngine; import javax.script.ScriptException; public class EvaluatingScript { public […]
SCRIPTING / CATATAN</>↗Scripting14 Jul 2009
This example demonstrates how to create a JavaScript interpreter or the ScriptEngine to run JavaScript in Java. The classes related to scripting is packaged under the javax.script.* package. In this example we show you how to create the JavaScript engine by using the engine extension. package org.kodejava.script; import javax.script.ScriptEngineManager; import javax.script.ScriptEngine; public class GettingJavaScriptEngine { […]
CORE API / CATATAN</>↗Core API12 Jul 2009
package org.kodejava.util; import java.util.SortedSet; import java.util.TreeSet; public class LastSetElement { public static void main(String[] args) { SortedSet<String> numbers = new TreeSet<>(); numbers.add("One"); numbers.add("Two"); numbers.add("Three"); numbers.add("Four"); numbers.add("Five"); // SortedSet orders the items it contains. We can get the last // item from the set using the last() method. The last item // will be "Two". String […]
CORE API / CATATAN</>↗Core API09 Jul 2009
package org.kodejava.util; import java.util.TreeSet; import java.util.SortedSet; public class FirstSetElement { public static void main(String[] args) { SortedSet<String> numbers = new TreeSet<>(); numbers.add("One"); numbers.add("Two"); numbers.add("Three"); numbers.add("Four"); numbers.add("Five"); // SortedSet orders the items it contains. We can get the first // item from the SortedSet using the first() method. The fist item // will be "Five". String […]