Talend tJavaFlex

The Talend tJavaFlex components provide a code editor to write your own personalized or custom Java code. We can use this Talend tJavaFlex to integrate the Java code inside the Talend Job workflow.

In this section, we use a simple Java program to display the array in tLogRow. First, drag and drop the tJavaFlex component into the job design.

Talend tJavaFlex 1

As you can see from the Components tab screenshot, it has three sections. You can use these Start Code, Main Code, and End code sections to divide the Java code or program.

Talend tJavaFlex 2

First, let me click on the Edit Schema button and add SNo of integer type and Languages of string type columns. 

Talend tJavaFlex 3

For the Talend demonstration purpose, we are declaring a string array of different programming languages. Here, we also used the println statement to print a simple start message. You may notice that we used the tLogRow to display the output.

Next, we use the for loop to iterate the array and assigned the values to two new columns that we created in the earlier schema.

Within the end code section, we used another println statement to print the end message.

Talend tJavaFlex 4

The Java code that we used is

// start part of your Java code
System.out.println("-----Java Code Start Point-----");
String [] arr = {"C", "C++", "C#", "Java", "Python", "JavaScript"}

// here is the main part of the component,
// a piece of code executed in the row
// loop
for(i = 0; i < arr.length; i++)
{
row1.SNo = i;
row1.Languages = arr[i];

// end of the component, outside/closing the loop
}
System.out.println("-----Java Code Start Point-----");

Let me run this Talend tJavaFlex job.

Talend tJavaFlex 5

Let me show you another example of the Talend tJavaFlex component. First, let me change the schema and add Array_a, Array_b, and Sum_of_aAndb columns of integer type.

Next, we declared 2 two dimensional arrays of integer type. Within the for loop, we assigned those values to two arrays Array_a and Array_b. Next, we also performed the arithmetic operation of the sum of those two arrays and assigned those values to Sum array.

Talend tJavaFlex 6

Java Code

// start part of your Java code
System.out.println("-----Java Code Start Point-----");
int[][] a = { {15, 25, 35}, {45, 55, 65} };
int[][] b = {{12, 22, 32}, {55, 25, 85} };
int rows, columns;

// here is the main part of the component,
// a piece of code executed in the row
// loop
for(rows = 0; rows < a.length; rows++) {
	for(columns = 0; columns < a[0].length; columns++) { 
		row1.Array_a = a[rows][columns];
		row1.Array_b = b[rows][columns];
		row1.Sum_of_aAndb = a[rows][columns] + b[rows][columns];

// end of the component, outside/closing the loop
	}			
}
System.out.println("-----Java Code Start Point-----");

You can see the tJavaFlex output.

Talend tJavaFlex 7