BASIC / NOTES</>↗Basic04 Aug 2009
To get the constants name of an enumeration you can use the values() method of the enumeration type. This method return an array that contains a list of enumeration constants. package org.kodejava.basic; public enum Month { JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER } package org.kodejava.basic; public class EnumValuesTest { […]
BASIC / NOTES</>↗Basic04 Aug 2009
In the following example you’ll see how to add a constructor to an enum type value. Because an enum is just another class type it can have constructors, fields and methods just like any other classes. Below we define a constructor that accept a string value of color code. Because our enum now have a […]
BASIC / NOTES</>↗Basic04 Aug 2009
This example show you how to use enumeration or enum type in a switch statement. package org.kodejava.basic; public enum RainbowColor { RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET } package org.kodejava.basic; public class EnumSwitch { public static void main(String[] args) { RainbowColor color = RainbowColor.INDIGO; EnumSwitch es = new EnumSwitch(); String colorCode = es.getColorCode(color); System.out.println("ColorCode […]
BASIC / NOTES</>↗Basic01 Aug 2009
Enumeration is a list of named constants. Every most commonly used programming languages support this feature. But in Java it is officially supported since version 5.0. In Java programming language an enumeration defines a class type. Because an enumeration is a class it can have a constructors, methods, and instance variables. To create an enumeration […]
SCRIPTING / NOTES</>↗Scripting31 Jul 2009
Here you can see how to import a Java class so that you can use the class, creates an instance of it in the scripting environment. We want to print out the current date on the console. For this we need to import the Date class that’s packaged under the java.util package. In the script […]
SCRIPTING / NOTES</>↗Scripting28 Jul 2009
This example show how to modify Java object from scripting environment. Below we manipulate a collection of string data. To pass data into the scripting engine we use a key-value binding to the script engine. package org.kodejava.script; import javax.script.Bindings; import javax.script.ScriptContext; import javax.script.ScriptEngineManager; import javax.script.ScriptEngine; import javax.script.ScriptException; import java.util.List; import java.util.ArrayList; public class M...