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 Job workflow.

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

Add Talend tJavaFlex to the workflow

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

Choose or add the Column Names

As you can see from the Components tab screenshot, it has three sections. You can divide the Java code or program by using the Start Code, Main Code, and End Code sections. 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 assign the values to two new columns we created in the earlier schema.

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

Go to Components Tab to write code

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.

run the Talend tJavaFlex job

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 the Sum array.

Write a Complex array code in Talend tJavaFlex

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 Talend tJavaFlex output.

Run the Talend tJavaFlex Job