# User Defined Java Class

{% hint style="info" %}
Demonstration to illustrate the Modified JavaScript Value step. We're going to use: 'Replace' function to substitute characters in a string.

In this workshop, you will:

* Configure the following steps:
  * User Defined Java Class
    {% endhint %}

<figure><img src="https://3680356391-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZpCSy6Skj215f4oWypdc%2Fuploads%2Fgit-blob-625c09ea0bd12d691a5621f5e4f4996af4b49c2c%2FUDJC%20-%20calender.png?alt=media" alt=""><figcaption><p>User Defined Java Class</p></figcaption></figure>

***

{% tabs %}
{% tab title="First Tab" %}

{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="1. Generate rows" %}

{% endtab %}

{% tab title="2. UDJC" %}
{% hint style="info" %}
This Java code is part of a class or method that processes rows of data.

Let's break it down:

1. Import Statements:

   ```java
   import java.util.*;
   ```

   These statements import the `java.util` package, which includes various utility classes like `Calendar`.
2. Private Fields:

   ```java
   private int yearIndex;
   private Calendar calendar;
   ```

   These are private instance fields of the class. `yearIndex` is an integer, and `calendar` is an instance of the `Calendar` class.
3. `processRow` Method: This method is used to process rows of data. It takes two parameters, `StepMetaInterface smi` and `StepDataInterface sdi`, and it may throw a `KettleException`.
   * It checks if there is a row available for processing using `getRow()`. If there is no row, it marks the output as done and returns `false`.
   * The `if (first)` block initializes some variables the first time this method is called. It finds the index of a field named "YEAR" in the input data, creates a `Calendar` instance, and clears it.
   * It resizes the `outputRowData` array to match the output row's metadata size.
   * It extracts the year value from the input row using `getInteger` and calculates the Easter date using the `easterDate` method.
   * It adds the Easter date to the output row data and puts it into the output stream using `putRow`.
4. `easterDate` Method: This method calculates the date of Easter for a given year using the algorithm to determine the date of Easter Sunday.
   * It takes the year as a parameter.
   * It performs several mathematical calculations to determine the day, month, and year of Easter based on the input year.
   * Finally, it sets the calculated date in the `calendar` instance and returns the `Date` object representing the Easter date.

Overall, this code is part of a data processing routine, and the `easterDate` method calculates the date of Easter for a given year using a well-known algorithm for determining Easter's date.
{% endhint %}

<figure><img src="https://3680356391-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZpCSy6Skj215f4oWypdc%2Fuploads%2Fgit-blob-f8ef7fd11bb637cd50a5084d1c1cf6c9fa42fa77%2FUDJC.png?alt=media" alt=""><figcaption><p>User Defined Java Class - Calender</p></figcaption></figure>
{% endtab %}
{% endtabs %}
