In the query builder ,you can query and get Json query link and use in the java code to call the link and return the results to compare.
http://localhost:4502/bin/querybuilder.json?p.limit=-1&path=%2fcontent%2fwe-retail%2fus%2fen%2fmen&type=cq%3apage (add authorization)
"success":true,"result...