To use hid4java, you typically create a HidServicesSpecification, obtain HidServices via HidManager, and then start the services. You can add a listener to handle attach/detach events. Once started, you can retrieve a list of currently attached devices using getAttachedHidDevices().
// Configure to use custom specification
HidServicesSpecification hidServicesSpecification = new HidServicesSpecification();
// Use the v0.7.0 manual start feature to get immediate attach events
hidServicesSpecification.setAutoStart(false);
// Get HID services using custom specification
HidServices hidServices = HidManager.getHidServices(hidServicesSpecification);
hidServices.addHidServicesListener(this);
// Manually start the services to get attachment event
hidServices.start();
// Provide a list of attached devices
for (HidDevice hidDevice : hidServices.getAttachedHidDevices()) {
System.out.println(hidDevice);
}