Java Snippet (simple)


This node allows you to execute arbitrary java code to create a new column or to replace an existing one. Enter the java code in the text area. To address certain input values of the table use $name_of_col$ (a double click on the elements in the column list will insert a the place holder at the current cursor position). For instance, the sum of the first two columns is $col_1$ + $col_2$ (replace col_1 and col_2 by the name of the columns). Please also specify the return type with one of the radio buttons. You can also use more complex statements such as if-else switches. For instance, to bin a numeric column you could enter code as follows and check the String return type:

  String bin;
  if ($col_1$ < 0.5) {
    bin  = "Very small";
  } else if ($col_1$ < 2.0) {
    bin  = "Small";
  } else if ($col_1$ < 10.0) {
    bin  = "Medium";
  } else if ($col_1$ < 20) {
    bin  = "Large";
  } else {
    bin  = "Very Large";
  return bin; 

You can also use static methods of java utility classes, e.g. to get a column with random values, simply enter Math.random() and check the double return type.

It is also possible to use external java libraries (that is, libraries that are not part of java boot classpath). In order to include such external jar or zip files, add their location in the "Additional Libraries" tab using the control buttons.

Exceptions in the snippet are caught by the framework and will result in a missing value for the current row. If the snippet throws an exception of class Abort (an inner class that is available to each snippet without further import statements), the entire execution will halt, using the exception message as error that is presented to the user.

Input Ports

  1. Type: Data Input table.

Output Ports

  1. Type: Data Input table with an additional calculated column or one column replaced.

Find here

Scripting > Java

Make sure to have this extension installed:


Update site for KNIME Analytics Platform 3.7:
KNIME Analytics Platform 3.7 Update Site

How to install extensions