DOP Underscore

If you tried accessing my post last week you were not able to do so. Sorry about that. I use WordPress and apparently it had a problem with the JetPack plugin. I started using WordPress on a different blog about a decade ago. Since then I have changed my main computer three times. It seems that each time you get a new computer some stuff is left behind. In my case I lost some connection information which prevented me from accessing the site hosting the WordPress blog and addressing it.

That said; it seems that when an issue is detected in a WordPress site that prevents a blog from functioning, the admin receives a daily message with instructions to help mitigate the problem. With the help of my son who was kind enough to retrieve credentials for this blog, I was able to mitigate the issue and get the blog up and running. Sorry about the inconvenience.

The main subject for this post is to create a Maven project to load the Underscore-java library to get ready to experiment with it and Lodash and give a try to Data Oriented Programming (DOP). I did some experimentation with C# and was not able to find much on the web. If you happen to have access to a .NET package that implements Lodash or Underscore-csharp (I just made this name up), please let me know. I would like to experiment with it.

You can learn more about underscore-java here.

I went ahead and downloaded the underscore-java software from GitHub to my C:\ drive.

The documentation shows a Maven dependency for your pom.xml file which makes the creation of a Java Maven project the way to start experimenting with DOP.

Folder:				C:\Users\johnc\workspace18\DopUnderscore
IDE:  				VSCode

Extension:			Maven for Java	v0.40.4
					Manage Maven projects, execute goals, generate project from archetype, 
					improve user experience for Java developers.

I created a project to hold the Maven project that we will create shortly. For this project I will use Visual Studio Code IDE. I have used it in several Maven projects and it is simple to use. That said; you have to load the specified extension for VSCode.

At this point I need to disclose that I am a Microsoft employee working on the Azure cloud in the group that deals with generating and maintaining billing meters.

Create project:										View -> Command Palette... -> Maven: Create Maven Project
													Select an archetype...	maven-archetype-quickstart

Select version of maven-archetype-quickstart:		1.4

Input groupId of your project:						com.canessa <Enter>

Input articact Id of your project:					learn

Folder:												C:\Users\johnc\workspace18\DopUnderscore

Define value for property 'version' 1.0-SNAPSHOT:	<Enter>

Confirm properties configuration:					<Enter>

[INFO] Scanning for projects...
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] --- maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository not defined. Using the one from [org.apache.maven.archetypes:maven-archetype-quickstart:1.4] found in catalog remote
[INFO] Using property: groupId = com.canessa
[INFO] Using property: artifactId = learn
Define value for property 'version' 1.0-SNAPSHOT: : 
[INFO] Using property: package = com.canessa
Confirm properties configuration:
groupId: com.canessa
artifactId: learn
version: 1.0-SNAPSHOT
package: com.canessa
 Y: : 	<Enter>

We need to create a Maven project using VSCode. My responses to the different prompts are documented by the previous screen capture.

After the Java-Maven project is created we can take a look at the folder/directory structure.

# **** open a command prmpt ****
Microsoft Windows [Version 10.0.22621.1265]
(c) Microsoft Corporation. All rights reserved.

# **** ****
cd workspace18
cd DopUnderscore

# **** ****
02/20/2023  08:23 AM    <DIR>          learn

# **** ****
cd learn

# **** ****
02/20/2023  08:21 AM             2,720 pom.xml
02/20/2023  08:21 AM    <DIR>          src
02/20/2023  08:23 AM    <DIR>          target

# *** open pom.xml and insert lines to support the undersacore-java library ****

We use a command console and get to the DopUnderscore folder which I choose to name and use for this project. Of course you can use the name of our choice.

Of interest at this point is to edit the pom.xml file to include the dependency information to the underscore-java library that we want to use.

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="" xmlns:xsi=""


  <!-- FIXME change it to the project's website -->



    <!-- add to use the Underscore-java library -->


    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
        <!-- clean lifecycle, see -->
        <!-- default lifecycle, jar packaging: see -->
        <!-- site lifecycle, see -->

The “C:\Users\johnc\workspace18\DopUnderscore\learn\pom.xml” file has been edited to include underscore-java library. I added a comment to mark the start of the edited lines.

package com.canessa;

import com.github.underscore.U;

 * Main entry point.
public class App 
    public static void main( String[] args )
        System.out.println( "**** Experiment with the underscore-java library ****");

        // **** ****
        U.Builder builder = U.objectBuilder()
            .add("firstName", "James")
            .add("lastName", "Bond")
            .add("age", 57)
            .add("address", U.arrayBuilder()
                    .add("streetAddress", "85 Albert Embankment")
                    .add("city", "London")
                    .add("cityId", "SE11")
                    .add("state", "5AW")
                    .add("postalCode", "00007")))

            .add("phoneNumber", U.arrayBuilder()
                    .add("type", "home")
                    .add("number", "007-007-0007"))
                    .add("type", "fax")
                    .add("number", "700-700-7000")));

        // ???? ????
        System.out.println("main <<< builder.toJson:\n" + builder.toJson());

        // ???? ????
        System.out.println("main <<< builder.toXml:\n" + builder.toXml());

This is the updated contents of the file “C:\Users\johnc\workspace18\DopUnderscore\learn\src\main\java\com\canessa\” that was generated by VSCode.

In it we make use of two library calls that convert a data structure to JSON and XML formats. The reason was to make sure we are able to access the library and that the results are sensible, which they are.

Following is the current output generated by this program:

**** Experiment with the underscore-java library ****

main <<< builder.toJson:
  "firstName": "James",
  "lastName": "Bond",
  "age": 57,
  "address": [
      "streetAddress": "85 Albert Embankment",
      "city": "London",
      "cityId": "SE11",
      "state": "5AW",
      "postalCode": "00007"
  "phoneNumber": [
      "type": "home",
      "number": "007-007-0007"
      "type": "fax",
      "number": "700-700-7000"

main <<< builder.toXml:
<?xml version="1.0" encoding="UTF-8"?>
  <age number="true">57</age>
  <address array="true">
    <streetAddress>85 Albert Embankment</streetAddress>

At this point we are ready to experiment with the actual underscore-java library which we will do in the next post.

I wanted to add a post on ChatGPT but ran out of time. Will try to generate an associated post next weekend.

If interested in the code for this post, you may find it in GitHub at DopUnderscore.

Keep in mind that one of the best ways to learn is to read and experiment until the subject matter is well understood and you are able to explain it to others.



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.