Eclipse Platform Plug-in Development

Notes for the eclipse plugin development. References: Wizards and Dialogs Eclipse fragment projects - Tutorial Refer 1. New Project Creation Wizards Every plugin, fragment, feature and update site is represented by a single project in the workspace and allow PDE(Plugin Development Environment) to validate their manifest file(s). File > New > Project... > Plug-in Development Use a Plugin Project if we’re building new functionality. Use a Fragment Project if we need to modify an existing plugin without changing its core code. ...

February 5, 2025 · 8 min · Phong Nguyen

Java JNA

Explain how to use the Java Native Access library (JRA) to access native libraries. References: Using JNA to Access Native Dynamic Libraries 1. Introduction Sometimes we need to use native code to implement some functionality: Reusing legacy code written in C/C++ or any other language able to create native code. Accessing system-specific functionality not available in the standard Java runtime. Trace-offs: Can’t directly use static libraries Slower when compared to handcrafted JNI code. => JNA today is probably the best available choice to access native code from Java. 2. JNA Project Setup Add JNA dependency to the project’s pom.xml (latest version of jna-platform) <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna-platform</artifactId> <version>5.6.0</version> </dependency> 3. Using JNA Step1: Create a Java interface that extends JNA’s Library interface to describe the methods and types used when calling the target native code. Step2: Pass this interface to JNA which returns a concrete implementation of this interface that we use to invoke native methods. 3.1. Example 1: Calling methods from the C Standard Library CMath.java import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Platform; public interface CMath extends Library { CMath INSTANCE = Native.load(Platform.isWindows() ? "msvcrt" : "c", CMath.class); double cosh(double value); } load() method takes two arguments, the return a concrete implementation of this interface, allowing to call any of its methods. The dynamic lib name The Java interface describing the methods that we’ll use We don’t have to add the .so (Linux) or .dll(Window) extension as they’are implied. Also, for Linux-based systems, we don’t need to specific the lib prefix. Main.java public class Main { public static void main(String[] args) { System.out.println(CMath.INSTANCE.cosh(180)); } } 3.2. Example 2: Basic types Mapping char => byte short => short wchar_t => char int => int long => com.sun.jna.NativeLong long long => long float => float double => double char * => String JNA provides the NativeLong type, which uses the proper type depending on the system’architecture. 3.3. Structures and Unions Given this C struct and union struct foo_t { int field1; int field2; char *field3; }; union foo_u { String foo; double bar; }; Java peer class would be @FieldOrder({"field1","field2","field3"}) public class FooType extends Structure { int field1; int field2; String field3; }; public class MyUnion extends Union { public String foo; public double bar; }; MyUnion u = new MyUnion(); u.foo = "test"; u.setType(String.class); lib.some_method(u); Java requires the @FiledOrder annotation so it can properly serialize data into a memory buffer before using it as an argument to the target method.

November 21, 2024 · 2 min · Phong Nguyen

Java Basic IO

Explain how to use basic I/O. References: Basic I/O Reading and writing files in Java (Input/Output) - Tutorial 1. I/O Streams An I/O Stream represents and input source or an output destination. A stream is a sequence of data. input stream: is used to read data from source, once item at a time. outputs stream: is used to write data to a destination, once item |at a time. --stream--> 0101010101... ----------> java.io package ...

November 14, 2024 · 6 min · Phong Nguyen

Java Platform Standard Edition

Java is a programming language created by James Gosling from Sun Microsystems (Sun) in 1991. Java allows to write a program and run it on multiple operating systems. References: Java Platform Standard Edition 8 Documentation Introduction to Java programming - Tutorial 1. Introduction to Java Oracle has two products implement Java SE: JDK (Java SE Development Kit): is a superset of JRE. JRE (Java SE Runtime Environment): provides the libraries, the Java Virtual Machine (JVM) and other components. 1.1. Development Process with Java Source code is first written in .java file. Those source files are then compiled into .class files by the Java compiler( javac). A .class file contains bytecodes(the machine language of the Java VM). The .class file will be run by Java tool as an instance of the Java VM. The Java virtual machine (JVM) is a software implementation of a computer that executes programs like a real machine. Because the Java VM is available on many different OS, the same .class files are capable of running on many OS too. ...

November 12, 2024 · 5 min · Phong Nguyen

Model Context Protocol (MCP)

1. Introduce Modern applications are integrating with Large Language Models (LLMs) to build AI solution. The AI model’s response will be more context-ware if we provide it external source like databases, file systems, pictures ,… MCP provides a standard way to connect AI-powered applications with external data sources. 2. Model Context Protocol Components overview: MCP follows a client-server architecture, that included: MCP provides two transport channels, with many transport types: ...

February 10, 2026 · 2 min · Phong Nguyen

GTK4

Gtk4 with Cpp. References: Gtk 1. Introduction Gtk4 is a widget toolkit for creating graphical user interface (UI). It works on many UNIX-like platform, Windows and Macos. 2. Setup the environment Note: - This is the guides for Windows machine using Windows Subsystem for Linux (WSL). - [W]: The action will be performed on Windows Machine. - [U]: The action will be performed on WSL (in my case, it named "Ubuntu") on the host Windows Machine. - (Guides: ...): The reference link that I refer the step. - (Not try yet): This is referred from the guides but I was not in that case, so that I could not try. ------------------------------- A. Installing from packages ------------------------------- 1. [L] Install required packages. 1.1. [L] Debian/Ubuntu: sudo apt install libgtk-4-1 libgtk-4-dev gtk-4-examples 2. [L] Verify installation. 2.1. [L] gtk version - Run: pkg-config --modversion gtk4 2.2. [L] examples - Run: gtk4-demo ------------------------------- B. (Optional) Build from Source ------------------------------- 1. [L] Install build tools. 1.1. [L] sudo apt install build-essential meson ninja-build \ libglib2.0-dev libpango1.0-dev libgdk-pixbuf-2.0-dev \ libatk1.0-dev libepoxy-dev libgirepository1.0-dev 2. [L] Clone GTK source. 2.1. [L] git clone https://gitlab.gnome.org/GNOME/gtk.git 2.2. [L] cd gtk 3. [L] Build with Meson + Ninja. 3.1. [L] meson setup builddir 3.2. [L] ninja -C builddir 4. [L] (Optional) Install system-wide. 4.1. [L] sudo ninja -C builddir install 3. HelloWorld Create a new file named hello-world-gtk4.c with following content: #include <gtk/gtk.h> static void print_hello (GtkWidget *widget, gpointer data) { g_print ("Hello World\n"); } static void activate (GtkApplication *app, gpointer user_data) { GtkWidget *window; GtkWidget *button; window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "Hello"); gtk_window_set_default_size (GTK_WINDOW (window), 200, 200); button = gtk_button_new_with_label ("Hello World"); g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL); gtk_window_set_child (GTK_WINDOW (window), button); gtk_window_present (GTK_WINDOW (window)); } int main (int argc, char **argv) { GtkApplication *app; int status; app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return status; } - Hints: ...

August 21, 2025 · 2 min · Phong Nguyen

String 1. C-Style String A C-Style string is any null-terminated byte string, where this is a sequence of nonzero bytes followed by a byte with zero (0) value (the terminating null character). The terminating null character is represented as the character literal ’\0’; The length of an NTBS is the number of elements that precede the terminating null character. An empty NTBS has a length of zero. The size of an NTBS is the size of the entire array, including the terminating null character. A single quotes (') are used to identify character literals. A double quotes ('') are used to identify string literals. String literals are stored in your program image, usually in a read-only section (.data), 1.1. Create a String // *1. Ptr char* strMessagePtr= "abc"; // sizeof(strMessage) = 32 or 64 (ptr) strMessagePtr[0] = 1; // error, ptr to const // *2. Arrays char strMessage[] = "abc"; // sizeof(strMessage ) = 4 strMessage[1] = 'a'; // OK For strMessage, the memory for the array is allocated on the stack at runtime. The compiler initializes it from the string literal. At runtime, the program memory copies the string literal into the array For strMessagePtr, only the address of the string literal is held on the stack, and there is no copying of string literal. 1.2. Characters Null: \0, 0x00, NULL Carriage Return And New Line: \r\n Case switching: 'A' ^ ' ' & 'a' ^ ' ' Special: \\, Escape sequences: Name Symbol Meaning Alert \a Makes an alert, such as a beep Backspace \b Moves the cursor back one space Formfeed \f Moves the cursor to next logical page Newline \n Moves cursor to next line Carriage return \r Moves cursor to beginning of line Horizontal tab \t Prints a horizontal tab Vertical tab \v Prints a vertical tab Single quote \' Prints a single quote Double quote \" Prints a double quote Backslash \\ Prints a backslash Question mark \? Prints a question mark (no longer relevant) Octal number \{number} Translates into char represented by octal Hex number \x{number} Translates into char represented by hex number 1.3. C String Libraries Copying strings : strcpy, strncpy Concatenating strings: strcat, strncat Comparing strings: strcmp, strncmp Parsing strings: strtok, strcspn Length: strlen Examples: #include <stdio.h> #include <string.h> int main() { // ------------------------------- // 1. Copying strings // ------------------------------- char src[] = "Hello"; char dst[20]; strcpy(dst, src); // copy full string // dst = "Hello" strncpy(dst, "World", 3); // copy only 3 chars dst[3] = '\0'; // ensure null-termination // dst = "Wor" // ------------------------------- // 2. Concatenating strings // ------------------------------- char text[20] = "Hi"; strcat(text, " there"); // append full string // text = "Hi there" strncat(text, "!!!", 2); // append only 2 chars // text = "Hi there!!" // ------------------------------- // 3. Comparing strings // ------------------------------- int r1 = strcmp("abc", "abc"); // r1 = 0 (equal) int r2 = strcmp("abc", "abd"); // r2 < 0 (abc < abd) int r3 = strncmp("abcdef", "abcxyz", 3); // r3 = 0 (first 3 chars equal) // ------------------------------- // 4. Parsing strings // ------------------------------- char line[] = "A,B,C"; char* token = strtok(line, ","); // first token: "A" while (token != NULL) { printf("token: %s\n", token); token = strtok(NULL, ","); } // strcspn: find first occurrence of any chars in reject set char sample[] = "hello123world"; size_t pos = strcspn(sample, "0123456789"); // pos = 5 (first digit is at index 5) // ------------------------------- // 5. Length // ------------------------------- size_t len = strlen("abc"); // len = 3 return 0; } 1.4. String/Numbers Conversion Integer to String: itoa() (non-standard) String to Double: atof() String to Double (with error checking): strtod() String to Long (with base + error checking): strtol() e.g. #include <stdio.h> #include <stdlib.h> // atof, strtod, strtol #include <string.h> // itoa (non-standard on some compilers) int main() { // ------------------------------- // 1. Integer → String (itoa) // ------------------------------- char buf[32]; itoa(1234, buf, 10); // convert integer to string in base 10 // buf = "1234" itoa(255, buf, 16); // convert to hex // buf = "ff" // ------------------------------- // 2. String → Double (atof) // ------------------------------- double d1 = atof("3.14159"); // d1 = 3.14159 double d2 = atof("12.5xyz"); // d2 = 12.5 (atof stops at non-numeric chars) // ------------------------------- // 3. String → Double (strtod) // ------------------------------- char* end; double d3 = strtod("45.67abc", &end); // d3 = 45.67 // end -> "abc" // ------------------------------- // 4. String → Long (strtol) // ------------------------------- long v1 = strtol("1234", NULL, 10); // v1 = 1234 (decimal) long v2 = strtol("FF", NULL, 16); // v2 = 255 (hex → decimal) char* end2; long v3 = strtol("100xyz", &end2, 10); // v3 = 100 // end2 -> "xyz" return 0; } 2. C++ String Strings are objects that represent sequences of characters. ...

7 min · Theme PaperMod