Welcome to my blog, hope you enjoy reading
RSS

Monday 25 March 2013

Cannot connect wireless internet with 12.10 on lenovo G580


Lenovo G580 Atheros AR8132 ethernet Ubuntu 12.10

To get Atheros AR8132 gigabit ethernet in Lenovo G580 laptop, in UBUNTU 12.10; 
Download it and keep it on  Desktop...
Now open a terminal and type in the following...
The following applies for both 32-bit and 64-bit users...

cd ~/Desktop

tar -xzvf atheros_AR8132_Lenovo_G580.tar.gz

cd  atheros_AR8132_Lenovo_G580

chmod +x ./install.sh

./install.sh
Share

Wednesday 20 March 2013

How to Dual Boot Windows 7 with Ubuntu 12.10


How to Dual Boot Windows 7 with Ubuntu 12.10



 See this link  click here
Share

Monday 18 March 2013

JSon Client Code

JSon Client Code



package com.javanotes2all.client;

import java.util.Set;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONBoolean;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define onModuleLoad().
 */
public class Test implements EntryPoint {

	public void onModuleLoad() {		
		String firstJSON="{'wz':'123','java':111,'other':['zhangsan','lisi'],'obj':{'name':'jam','age':18,'married':true,'child':null,'likes':['cat','dog']}}";
		JSONValue value=JSONParser.parse(firstJSON);
		System.out.println(value.toString());
		JSONObject o1= value.isObject();
		
		JSONValue v1=o1.get("wz");
		System.out.println("v1  "+v1.isString());
		
		JSONValue v2=o1.get("java");
		System.out.println("v2  "+v2.isNumber());
		
		JSONValue v3=o1.get("other");
		System.out.println("v3  "+v3.isArray());

		JSONObject object=new JSONObject();
		object.put("a", JSONBoolean.getInstance(true));
		object.put("b", new JSONString("yes"));
		object.put("c", new JSONNumber(1.23));
		object.put("d",JSONNull.getInstance());
		System.out.println("v6  "+object.toString());
 
		JSONArray v33=v3.isArray();
		int arraylength=v33.size();
		v33.set(arraylength, new JSONString("wangwu"));
		System.out.println("v3  "+v3.isArray());
		
		JSONObject v4=o1.get("obj").isObject();
		System.out.println("v4  "+v4.toString());
		System.out.println("v44 "+v4.get("name").isString());
		
		String jsJSON=jsmethod();
		JSONObject jsobj=JSONParser.parse(jsJSON).isObject();
		System.out.println("v5  "+jsobj);
		System.out.println("v55 "+jsobj.get("name").isString());
		
		RootPanel.get().add(new Label("success!!!"));
	}
	
	public native String jsmethod()/*-{
		var code="{'name':'Tom','age':18.0,'married':true}";
		
		return code;
	}-*/;
	
}

Share

Saturday 16 March 2013

Serialize and Deserialize Java Objects

Serialize and Deserialize Java Objects

I create a Phone object and serialize it. Then I change the data in the object. Next, the old object is read back and compared to the changed object. The output should be something like this.

Phone Entry: prabhu - 1234567890
Phone Entry: prabhu - 0987654321
Phone Entry: prabhu - 1234567890
Share

Monday 11 March 2013

How to Swap Two Numbers without Temp or Third variable

How to swap two numbers without temp variable

approach 1:

int a = 10;
int b = 20;

System.out.println("value of a and b before swapping, a: " + a +" b: " + b);

//swapping value of two numbers without using temp variable
a = a+ b; //now a is 30 and b is 20
b = a -b; //now a is 30 but b is 10 (original value of a)
a = a -b; //now a is 20 and b is 10, numbers are swapped

System.out.println("value of a and b after swapping, a: " + a +" b: " + b);

Output:
value of a and b before swapping, a: 10 b: 20
value of a and b after swapping, a: 20 b: 10


Share

Friday 8 March 2013

Regular expression for comma separated numbers


Regular expression for string

  1. For double value with % symbol

package com.javanotes2all.java.string;

public class RegulerExpresion {

 public static void main(String[] args) 
 {
  String s="10.0%";
  if(s.trim().matches(".?[0-9]+(.[0-9]+)*\\%?"))
  {
   System.out.println("valid string");
  }else
   System.out.println("invalid string");
 }
}


   

Share

Tuesday 5 March 2013

Send JSON-Object as POST in RequestBuilder

Send JSON-Object as POST in RequestBuilder

At client-side:

JSONArray devicedata=new JSONArray();

devicedata.set(0,"zero");

devicedata.set(1, "one");

devicedata.set(2, two);

try
{
 String url=localhost:8080/requestsend/servlet;
 RequestBuilder builder=new RequestBuilder(RequestBuilder.POST, url);
//adding the post data
 builder.setRequestData(devicedata.toString());
 builder.setCallback(new RequestCallback() 
{
 @Override
 public void onResponseReceived(Request request, Response response) 
{
  popup.setVisible(false);
  JSONValue value=JSONParser.parse(response.getText());
  JSONObject jobj=value.isObject();
  if(jobj.get("status").isString().stringValue().equalsIgnoreCase("success"))
    {
    }
  @Override
  public void onError(Request request, Throwable exception) 
  {
     Window.alert("Error occurred" + exception.getMessage());
  }
 });
builder.send();
}catch(Exception e)
{
}



At Server Side:

String s=req.getReader().readLine();
JSONArray jarray=new JSONArray(s);
Share

convert ArrayList to JSONArray


Convert ArrayList to JSONArray

ArrayList<String> list = new ArrayList<String>();
    list.add("abc");
    list.add("xyz");
    JSONArray jsArray = new JSONArray(list);

see api click here


How to add string into JsonArray



 JSONArray list = new JSONArray();
 list.put("abc");
 list.put("xyz");
Share