Richard Pajerski  Software development and consulting

Merry Christmas

by Richard Pajerski


Posted on Monday December 25, 2023 at 12:00AM in General


The time is accomplished, and the kingdom of God is at hand: repent, and believe the gospel.  (St. Mark 1:15; Douay-Rheims version).

Image (public domain): The Nativity with the Prophets Isaiah and Ezekiel, Duccio di Buoninsegna.  Courtesy National Gallery of Art, Washington.


Three easy-to-use Java 17 features in Notes/Domino 14

by Richard Pajerski


Posted on Tuesday December 19, 2023 at 03:14PM in Technology


As I mentioned previously, having Java 17 available with the latest release of Notes/Domino has brought welcome changes for Java developers.  Just to scratch the surface a bit, here are three language-level niceties that we can immediately benefit from:


1.  Simplified access to file contents
2.  Local-variable type inference (var identifier)
3.  Text blocks


1.  Simplified access to file contents
Java has been (in)famous for offering a number of ways to open/read and write/close files.  As of Java 11, perhaps the simplest way to get text out of a file is:

Files.readString(Path p);



A two-liner in a local Java agent on a Windows 11 client:


import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

      try {

          Path p = Paths.get("C:\\Windows\\System32\\drivers\\etc\\hosts");
          System.out.println(Files.readString(p)); 
      } catch(Exception e) {
          e.printStackTrace();
      }
   }
}

Javadoc:  https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#readString(java.nio.file.Path)


2.  Local-variable type inference (var identifier)

The var type identifier has been available since Java 10 and is intended to help reduce "boilerplate" code:

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

      try {

         var s = getSession();
         var db = s.getCurrentDatabase();
         System.out.println("Db title: " + db.getTitle());

                /* Contrast:
                     Session s = getSession();
                     Database db = s.getCurrentDatabase();
                   */

      } catch(Exception e) {
          e.printStackTrace();
      }
   }
}

More: Using the Var Type Identifier


3.  Text blocks
In Java 15, Text Blocks were introduced.  In a more developed application, it's probably a better idea to store strings and text outside of source code, especially if they need to be regularly modified.  But using text blocks can be a time saver for quick testing, demos, etc. and provide improved source readability.

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

      try {

         var textBlock = """

                Using text blocks in Java source

                code simplifies text formatting

                and improves readability!

                """;


         System.out.println(textBlock);


      } catch(Exception e) {
          e.printStackTrace();
      }
   }
}


Note: To use these features, remember to adjust your compiler levels appropriately:


New context-specific Notes 14 client preferences options -- nice touch!

by Richard Pajerski


Posted on Thursday December 07, 2023 at 01:13PM in Technology


Notes 14 is now GA and an improved listing of the Notes "Additional options" (File > Preferences > Basic Notes Client Configuration) is an unexpected but very welcome feature!

Previously, all options were in one long list and so the context where each one applied was not always clear.  Now a categorical description precedes each option entry:




Nice touch, HCL and thank you!