Hi and welcome👋.

I’m Phong.

On this blog, I write about topics related to my work.Why writing? Because writing helps me think - there is no better tool for organizing a long line of thought.

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

Eclipse Apache Maven-Tycho

Introducing about Maven and how to use Maven Tycho plugin to build plugins into the SNAPSHOT Refer1 Refer2 Refer3 1. Apache Maven Apache Maven is an powerful build tool primary for Java software projects. It is implemented in Java which makes it platform-independent. 1.1. Setup Env Install maven: https://maven.apache.org/download.cgi Verify: mvn --version Config proxy (ONLY IF NEED): C:\Users${username}.m2\settings.xml or ${maven_home}\apache-maven-3.9.10\conf\settings.xml <settings> <proxies> <proxy> <id>example-proxy</id> <active>true</active> <protocol>http</protocol> <host>proxy.example.com</host> <port>8080</port> <username>proxyuser</username> <password>somepassword</password> <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts> </proxy> </proxies> </settings> 1.2. Concepts Need the pom file defines: identifiers for the project to be build/ properties relevant for build configuration/ plugins which providefunctionality for the build via a build section. /library and project dependencies via the dependencies section Each project have its onw pom file but What is pom file ? https://maven.apache.org/pom.html Example: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> // version of the pom file <groupId>com.vogella.maven.first</groupId> // group id -> maven will build the package: <groupId>:<artifactId>:<version> <artifactId>com.vogella.maven.first</artifactId> // project id <version>1.0-SNAPSHOT</version> // project version <name>com.vogella.maven.first</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>11</maven.compiler.source> // java version <maven.compiler.target>11</maven.compiler.target> </properties> </project> A Maven project uses the groupId, artifactId, version (also knows as GAV) and the packaging property to uniquely identify a Maven component. ...

June 26, 2025 · 2 min · Phong Nguyen

Markdown Syntax Guide

Introduction Markdown is a lightweight markup language that use to add formatting elements to plaintext documents. Table of contents 1. Heading: To create heading, add one to six # symbols before your heading. The number of # will determine the size of heading. Syntax # H1 ## H2 ### H3 #### H4 ##### H5 ###### H6 Preview H1 H2 H3 H4 H5 H6 2. Emphasis: You can add emphasis by making text bold or italic. ...

August 9, 2024 · 2 min · Phong Nguyen

CMake Guide

1. Introduction It’s a meta-build system generator. How it works: We write high-level instructions in a CMakeLists.txt file (platform-agnostic).Then CMake generates build system files for the platform we choose: On Linux/Unix → generates Makefile (for make) or build.ninja (for ninja). On Windows → generates Visual Studio solutions (.sln). On macOS → can generate Xcode projects. 2. Setup Linux: Install: sudo apt install cmake , Verify: cmake --version 3. How to work with CMake Create CMakeLists.txt and resources file Create and cd to project-build folder & Run cmake <dir-contain-CMakeLists.txt> (cmake ../) to set up & generate build system. Run cmake --build <dir-contain-buildsystem> ( cmake --build ./) to actually build/compile the project. Run the target build (e.g. ./targetName) 3.1. CMakeLists.txt ...

August 21, 2025 · 1 min · Phong Nguyen

Makefile Guide

Introduction It’s a build tool (specifically, make is a build automation utility). How it works: Reads a file called Makefile that describes rules for how to build source files into targets (executables, libraries, etc.). GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program’s source files. Make get its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from the other files. When you write a program, you should write a makefile for it, so that it is possible to use Make to build and install the program. ...

August 9, 2024 · 11 min · Phong Nguyen

Java OSGi Service

Explain how to use the OSGi Service Refer1 Refer2 Refer3 Refer4 1. Introduction OSGi Services are essentially Java objects that provide a specific functionality or interface, and other components,plugins can dynamically discover and use these services. Multiple plugins can provide a service implementation for the service interface. Plugins can access the service implementation via the service interface. E.g. When you want to create modular that can be added or removed at runtime, you can use the OSGi service. ...

February 10, 2025 · 6 min · Phong Nguyen

Java NPE

Some stuffs related to NPE Refer1 Refer2 1. Optional This class will be an container object which may or may not contain a non-null value Examples: // Potential dangers of null String version = computer.getSoundcard().getUSB().getVersion(); // Solution 1: Ugly due to the nested checks, decreasing the readability String version = "UNKNOWN"; if(computer != null){ Soundcard soundcard = computer.getSoundcard(); if(soundcard != null){ USB usb = soundcard.getUSB(); if(usb != null){ version = usb.getVersion(); } } } // Solution 2(JavaSE7): String version = computer?.getSoundcard()?.getUSB()?.getVersion(); String version = computer?.getSoundcard()?.getUSB()?.getVersion() ?: "UNKNOWN"; // Solution 3 (JavaSE8) public class Computer { private Optional<Soundcard> soundcard; public Optional<Soundcard> getSoundcard() { ... } ... } public class Soundcard { private Optional<USB> usb; public Optional<USB> getUSB() { ... } } public class USB{ public String getVersion(){ ... } } String name = computer.flatMap(Computer::getSoundcard) .flatMap(Soundcard::getUSB) .map(USB::getVersion) .orElse("UNKNOWN"); 1.1 Creating Optional objects - Optional.of(var)/ Optional.ofNullable(var) SoundCard soundCard = new SoundCard(); Optional<SoundCard> sc = Optional.of(soundCard); // NPE if soundCard is null Optional<SoundCard> sc = Optional.ofNullable(soundCard); // may hold a null value 1.2. Check presenting - .ifPresent(//) // ugly code SoundCard soundcard = ...; if(soundcard != null){ System.out.println(soundcard); } // solution 1 SoundCard soundcard = ...; if(soundcard != null){ System.out.println(soundcard); } // solution 2 if(soundcard.isPresent()){ System.out.println(soundcard.get()); } 1.3. Default - .orElse/ .orElseThrow // ugly code Soundcard soundcard = maybeSoundcard != null ? maybeSoundcard : new Soundcard("basic_sound_card"); // solution 1 Soundcard soundcard = maybeSoundcard.orElse(new Soundcard("defaut")); // default value Soundcard soundcard = maybeSoundCard.orElseThrow(IllegalStateException::new); // default throw E … ...

February 27, 2025 · 2 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 Extension Points - Extensions

Explain how to use the Extension Point and Extensions. Refer1 Refer2 Refer3 1. Introduction Extensions are the central mechanism for contribute behavior to the platform. We used it to contribute functionality to a certain type of API. Extension points define new functions points for the platform that other plug-ins can plug into. E.g. When you want to create modular that can be added or removed at runtime, you can use the OSGi service. These extensions and extension points are defined via the plugin.xml file. ...

February 27, 2025 · 3 min · Phong Nguyen

DSF

Explain how to use the DSF. Refer1 1. Introduction Scenario: Debugger View Fetching Data Context: We want to show variable values in the Variables View as the user steps through the code. 1.1. Asynchronous Req: When the user steps through the program, the debugger needs to fetch variable values from the target (like a remote system). This operation might take a few milliseconds or more, depending on the connection. If we block the UI thread, the UI freezes. Solution: Use an asynchronous method to fetch variable data void getVariableValue(String varName, DataRequestMonitor<String> rm) { // Imagine this takes time (e.g., contacting GDB or a remote debugger) // Simulate async call executor.execute(() -> { String value = remoteFetchValue(varName); // Slow operation rm.setData(value); rm.done(); }); } Why Async? Prevents blocking the UI. Allows the Eclipse debug framework to continue updating other views. 1.2. Synchronous We want to implement a feature like evaluate expression that requires the value immediately. We don’t want to rewrite your entire logic using async callbacks just to get the result of getVariableValue(). ...

May 13, 2025 · 8 min · Phong Nguyen