SCRIPTING / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 […]
CORE API / NOTES</>↗Core API06 Jul 2009
To obtains all annotations for classes, methods, constructors, or fields we use the getAnnotations()method. This method returns an array of Annotation In the following example we tried to read all annotations from the sayHi() method. First we need to obtain the method object itself. Because the sayHi() method has parameters, we need to pass not […]
CORE API / NOTES</>↗Core API05 Jul 2009
This example demonstrate how to obtain annotations of a class and methods. We use the reflection API to get class and method information from where we can read information about annotation attached to the class or the method. package org.kodejava.lang.annotation; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @HelloAnnotation(value = "Hello", greetTo = "Universe") public class GettingAnnotation { public […]