I would suggest using a library like http://restfb.com/ or http://facebook4j.org/ to talk to the Facebook API from your Java application.
With RestFB it would look something like the following:
FacebookClient publicOnlyFacebookClient = new DefaultFacebookClient();
Connection<Notification> notifications =
facebookClient.fetchConnection("me/notifications", Notification.class,
Parameter.with("fields","title"));
Via notifications.getData() you have access to the notifications and can count them.