Hello, if you need to search in a java class there is class called AssetReferenceSearch . It's constructor takes the node (content node of the page ) to search under , path where the assets are stored (can be /content/dam ) and Resource Resolver.
Reference : http://wemcode.wemblog.com/get_asset_reference_in_page
String Pagepath = "/content/we-retail/en"; //This would be your page path
Resource r = resourceResolver.getResource(Pagepath+"/"+JcrConstants.JCR_CONTENT);
Node n = r.adaptTo(Node.class);
AssetReferenceSearch ref = new AssetReferenceSearch(n,DamConstants.MOUNTPOINT_ASSETS,resourceResolver);
Map<String,Asset> allref = new HashMap<String,Asset>();
allref.putAll(ref.search());
for (Map.Entry<String, Asset> entry : allref.entrySet()) {
String val = entry.getKey();
out.println(val+"<br>"); // Path of all Asset ref in page
Asset asset = entry.getValue();
}