The Java SDK doesn't support subscribing. The Java SDK is a relatively thin wrapper around the AWS services API (HTTPS). There is no API for subscribing: https://docs.aws.amazon.com/iot/latest/apireference/API_Operations_AWS_IoT_Data_Plane.html
To subscribe, you would need to connect to the AWS IoT Core MQTT broker. As Ryan_B has indicated elsewhere, one solution is to use the device SDK: https://github.com/aws/aws-iot-device-sdk-java-v2/tree/main/samples#basicpubsub
However, do you have need of receiving messages in real-time? It's not so common for web applications to connect directly to IoT Core. Solutions are often architected such that incoming device messages would typically flow through IoT Core to Rules Engine and then to another AWS service. Perhaps Kinesis, SQS or a storage service. Decoupling the application from the flow of incoming messages. The application would then retrieve the data from these other services, often through API gateway. Something like this: https://docs.aws.amazon.com/solutions/latest/smart-product-solution/architecture.html .
Amplify is also a popular choice: https://docs.amplify.aws/lib/pubsub/getting-started/q/platform/js/
Getting started with MQTT client in Java SDK?
Simulate a "thing" in Java?asked 6 months ago
Connecting to Athena using JDBC driver from a Spring Java applicationasked a year ago
How to communicate with GameLift Server with Java Client
Publish/Subscribe to IoT device messages via Java SDK?
FilterLogEventsRequest java sdkasked 6 months ago
How to send messages with GameLift Client in Java
Using Token Exchange Service with aws-iot-device-sdk-js-v2 and greengrassasked 10 months ago
Java IoT connection kit won't build...Accepted Answerasked 5 months ago
IoT Core API with Javaasked 3 months ago