Here you can find some examples on how to use bitly4j:
First of all you'll need to gather from http://bitly.com/a/account#oauthapps client_id and client_secret.
After having both client_id and client_secret, you just need to code in following ways.
1.- Authorize
First operation that you'll need to execute, as you'll need to obtain your apiKey and login from bit.ly using this method.
Bitly4j impl= new Bitly4jImpl();
AuthResponse res = impl.getAuthToken(client_id, client_secret, code, url_call_back);
2.- Shorten
Assuming http://bit.ly is the url we want to shorten:
Bitly4j impl= new Bitly4jImpl();
ShortenResponse resl = impl.shortenUrl(apiKey, login, "http://bit.ly");
3.- Expand
Assuming GGr90x is the hash for http://bit.ly shortenned url, we can get expanded url by coding:
Bitly4j impl= new Bitly4jImpl();
String [] urls={"http://bit.ly/GGr90x"};
ExpandResponse resl = impl.expand(apiKey, login, urls, null);
Or by using an array of hashes:
Bitly4j impl= new Bitly4jImpl();
String [] hashes={"GGr90x"};
ExpandResponse resl = impl.expand(apiKey, login, null, hashes);
4.- InfoUrl
Bitly4j impl= new Bitly4jImpl();
InfoResponse resl = impl.infoUrl(apiKey, login, shortUrl);
Objects AuthResponse, ShortenResponse, ExpandResponse, InfoResponse are defined on javadoc that you can download.