Try The Code below To get a Searc Result from Your Java Code:
package com.atspl;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import org.json.JSONArray; // JSON library from http://www.json.org/java/
import org.json.JSONObject;
public class GoogleQuery {
// Put your website here
private final String HTTP_REFERER = "http://www.example.com/";
public GoogleQuery() {
makeQuery("Sk. ARif Ahmed");
makeQuery("info:http://skarifahmed.blogspot.com/");
makeQuery("site:skarifahmed.blogspot.com");
}
private void makeQuery(String query) {
System.out.println(" Querying for " + query);
try
{
// Convert spaces to +, etc. to make a valid URL
query = URLEncoder.encode(query, "UTF-8");
URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web?start=0&rsz=large&v=1.0&q=" + query);
URLConnection connection = url.openConnection();
connection.addRequestProperty("Referer", HTTP_REFERER);
// Get the JSON response
String line;
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
while((line = reader.readLine()) != null) {
builder.append(line);
}
String response = builder.toString();
JSONObject json = new JSONObject(response);
System.out.println("Total results = " +
json.getJSONObject("responseData")
.getJSONObject("cursor")
.getString("estimatedResultCount"));
JSONArray ja = json.getJSONObject("responseData")
.getJSONArray("results");
System.out.println(" Results:");
for (int i = 0; i < ja.length(); i++) {
System.out.print((i+1) + ". ");
JSONObject j = ja.getJSONObject(i);
System.out.println(j.getString("titleNoFormatting"));
System.out.println(j.getString("url"));
}
}
catch (Exception e) {
System.err.println("Something went wrong...");
e.printStackTrace();
}
}
public static void main(String args[]) {
new GoogleQuery();
}
}
Original Post:
http://www.ajaxlines.com/ajax/stuff/article/using_google_is_ajax_search_api_with_java.php
Wednesday, April 29, 2009
Thursday, April 2, 2009
Power Of Java Script
Java Script is most powerful and magical language.
There are some doc which can help you.
There Is Another good Starter kit:
There are some doc which can help you.
There Is Another good Starter kit:
UML-The Guide to easy Development
Those Who are logical and don't like repetition of codding, are invited to the world
Of UML.
Links:
Netbeans & UML
Another Example:
Of UML.
Links:
Netbeans & UML
Another Example:
A simple Java Framework
Use Torque and maven or Ant to get the DAO and DTOs and use netbeans for the uml diagram.
Subscribe to:
Posts (Atom)