# Programming a Java Snippet node

**URL:** <https://forum.knime.com/t/programming-a-java-snippet-node/81288>\
**Category:** KNIME Analytics Platform\
**Created:** [July 23, 2024, 9:35pm UTC](https://forum.knime.com/t/programming-a-java-snippet-node/81288 "2024-07-23T21:35:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![takbb](https://forum-cdn.knime.com/user_avatar/forum.knime.com/takbb/32/57077_2.png) [@takbb](https://forum.knime.com/u/takbb)\
**Post date:** [July 23, 2024, 10:19pm UTC](https://forum.knime.com/t/programming-a-java-snippet-node/81288/2 "2024-07-23T22:19:24Z")

</div>

Hi @Guglielmo , I haven’t tried looking at the suggestions that the AI assistant will make for java snippets, but the code won’t work because unfortunately this is not the way java snippets work.

Take a look at the first 5 paragraphs of the following post which apply equally here, and gives some background about why it won’t work…

> [@Java Snippet iterate row calculation with String Similarity](https://forum.knime.com/t/java-snippet-iterate-row-calculation-with-string-similarity/81136/3):
>
> Hi @mauuuuu5 , I took a look at your java code, and what I realised is you are misunderstanding how the java snippet works. You are assuming that the java snippet is called once and that you can then iterate over all the rows in the table. Unfortunately it doesn’t behave that way, The java snippet code in the section entitled “// Your custom variables:” is invoked once when the node is executed but has no direct access to the table data. The snippet code in the section entitled “// Enter you…

The java snippet can only process a single row at a time and is called once for each row in the dataset, sequentially.

A java snippet therefore _cannot_ access all rows at the same time in a single invocation. It cannot sort the rows and it is not capable of either increasing the number of rows or reducing the number of rows in the resultant dataset.

It is a powerful node but not suitable for the type of operations you are trying to perform. The python nodes, on the other hand, can do all those things. I hope that helps.

There are some things that it can do though to assist with cumulative calculations though… See

> [@Java snippets have long memories!...](https://forum.knime.com/t/java-snippets-have-long-memories/33125):
>
> Hi all, Before you get reading what is maybe a tl;dr… I should say this isn’t asking a question or raising a problem, but is just a discussion/interest point related to java snippets! wink For some of you, what I am writing here won’t come as a surprise, but I thought it worth writing as it might avoid the mistake I made, and it also can potentially be quite useful. While playing with Java snippets I was surprised to stumble on some interesting behaviour. I had “incorrectly” initialised th…

---

_[View the full topic](https://forum.knime.com/t/programming-a-java-snippet-node/81288)._
