Hub
Pricing About
NodeNode / Manipulator

Java Snippet (simple)

ScriptingJava
Drag & drop
Like

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.

Node details

Input ports
  1. Type: Table
    Any input table
    Input table.
Output ports
  1. Type: Table
    Appended table
    Input table with an additional calculated column or one column replaced.

Extension

The Java Snippet (simple) node is part of this extension:

  1. Go to item

Related workflows & nodes

  1. Go to item
  2. Go to item
  3. Go to item

KNIME
Open for Innovation

KNIME AG
Talacker 50
8001 Zurich, Switzerland
  • Software
  • Getting started
  • Documentation
  • Courses + Certification
  • Solutions
  • KNIME Hub
  • KNIME Forum
  • Blog
  • Events
  • Partner
  • Developers
  • KNIME Home
  • Careers
  • Contact us
Download KNIME Analytics Platform Read more about KNIME Business Hub
© 2025 KNIME AG. All rights reserved.
  • Trademarks
  • Imprint
  • Privacy
  • Terms & Conditions
  • Data Processing Agreement
  • Credits