Configure HTML/JavaScript

Monday, April 11, 2016

How to remove java 1.8 from class path and set java 1.7 in windows 10



Windows 10 degrading from java 1.8 to java 1.7


I have been developing a project which is on google app engine and java sdk 1.7. When I upgraded to windows 10 from my windows 7 machine, the by default java verion was jre 1.8 and when ever I have bed executing any task, the version miss matching was happening.

JDK:

 jdk and jre are 2 different thing. The jdk is responsible to compile your java code using javac compailer and generate .class file which contains java byte code which is executed in jvm(java virtual machine)

JRE:

jre is something which execute the class file and guve you the result. any operating system gives you jre not jdk as jre executes most of the internal java codes


How to chge default windows 10 jre version from java 1.8 to 1.7



In windw 10, the C:\Windows\System32 (c:\Windows\SysWOW64 folder if you have x64 system [Win 7 64 bits]) folder contains java.exe, javaw.exe and javaws.exe which is dafault java execution and any call path you will set for the java will not over ride it as these are highest priority in windows.To set you default path to java jre 1.7 you need to delete them. may be you can take a backup in case you want to come back to jre 1.8.then what ever class path jre and jdk is available, it will point to you java version in your machine.


Sunday, August 3, 2014

Making Http call from core java - different ways

There are many ways we make http calls to web server in many situation. We application server always receives requests in many forms and send back response in many forms.

Now a days there are a lots of framework, library available to kame http call easy to the web server like Spring, Struts, Ajax, etc.

 But if the requirement is simple and need just a simple and light weight http call to the server, you will not like to use these heavy library which comes will many extra functionality which you dont need. In this case the best way is to use the inbuild hava http functionality to get response data from the web server.

below are few example which will help you to understand batter

Using HttpConnect

conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestMethod(method);
conn.setRequestProperty("X-DocuSign-Authentication", httpAuthHeader);
conn.setRequestProperty("Accept", "application/json");
if (method.equalsIgnoreCase("POST")) {
  conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  conn.setRequestProperty("Content-Length", Integer.toString(body.length()));
            conn.setDoOutput(true);
}


status = conn.getResponseCode(); // triggers the request
if (status != 200) { //// 200 = OK 
    errorParse(conn, status);
    return;
}

InputStream is = conn.getInputStream();

Another way is using HttpPost
  try {
   // 1. create HttpClient
   HttpClient httpclient = new DefaultHttpClient();

   // 2. make POST request to the given URL
   HttpPost httpPost = new HttpPost(authUrl);

   String json = "";

   // 3. build jsonObject
   JSONObject jsonObject = new JSONObject();
   jsonObject.accumulate("phone", "phone");

   // 4. convert JSONObject to JSON to String
   json = jsonObject.toString();

   // 5. set json to StringEntity
   StringEntity se = new StringEntity(json);

   // 6. set httpPost Entity
   httpPost.setEntity(se);

   // 7. Set some headers to inform server about the type of the
   // content
   httpPost.addHeader("Accept", "application/json");
   httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");

   // 8. Execute
   HttpResponse httpResponse = httpclient.execute(httpPost);

   // 9. receive response as inputStream
   inputStream = httpResponse.getEntity().getContent();
   String response = getResponseBody(inputStream);
   
   System.out.println(response);

  } catch (ClientProtocolException e) {
   System.out.println("ClientProtocolException : " + e.getLocalizedMessage());
  } catch (IOException e) {
   System.out.println("IOException:" + e.getLocalizedMessage());
  } catch (Exception e) {
   System.out.println("Exception:" + e.getLocalizedMessage());
  }

Thursday, January 9, 2014

Updating column 1 or column 2 with value of same column value or different column value of same table

Some time we need to change values of columns of same row of a table.

update  table_name set column1 = column2

you can also put some arithmetic calculation and update table as well. the above query will take the value of column2 and will store it in the column1 of the same row of same table.

Friday, October 25, 2013

UNIX Command file lists order by file size

below command will list all files in a folder order by file size.

ls -l | sort +4rn |awk '{print $9, $5}'

Saturday, March 30, 2013

json serialization

What is JSON

Json stands for JavaScript Object Notification. it represents data in object format so that javascript and understand it easily and manipulate it easily

it looks like as below:
[{"id":"83","text":"sales crescent"},{"id":"88","text":"sales grey bar"}]
 its just a simple array of two json object

keep in mind that, if you will find [] symbol it means it's a array of object. that means one or more then one json object may be there inside the space

like bellow
var mathTen = 
[{
"name": "Aniruddha Das",
"email": "someemailaddress@gmail.com
"valuepaids": [{"id":"83","text":"sales crescent"},{"id":"88","text":"sales grey bar"}]
}]

you can also iterate this object by using jQuery.each() ot any normal javascript loop.

here variable mathTen contain a array of json. again inside mathTen there valuepaids node which contains a array of json object.

there are ways to manipulate these json object hierarchy inside in side javascript code (i am not mentioning here as we can do that , i think so :) )

Where we need json serialization:

We need json serialization where we want to pass json from one place to another. like from one environment to another. like while sending json data from java/php/asp.net codes to javascript code thorugh ajax call.

Or sending json data as parameter from a dynamically created javascript function

But in some situations we need to create dynamic html codes and pass as json as as parameters if we are creating dynamic javascript functions in that like below
var yuyu = [{"id":"83","text":"sales crescent"},{"id":"88","text":"sales grey bar"}];
indObj=[{"id":"83","text":"sales crescent"}];


$("#divAllIndividuals")
            .append("+indObj[0].id+"','"+JSON.stringify(yuyu)+"','"+JSON.stringify(indObj)+"','"+indObj[0].text+"') title=\"Delete Entry\">\"");

there json variable (yuyu and indObj) will no more will be json in the called function if you will not serialize these function here. here the serialize concept come


what is json serialization:

Json serialization is nothing but it convert json object to string so that you can easily send that string from one environment to another or you can pass that string as parameter from a dynamically created javascript function.

Use of json serialization:

to serialize a json object we can use JSON.stringify() as we did in the above created dynamically created javascript function. this function will convert json object to string.

Again we have to deserialize the json object string in the called function  (if we are calling in as parameter in dynamic javascript function) or if we are receiving it from other language like java/php/asp.net.

to deserilize json object string we need to call JSON.parse(); it will again convert josn object string to json object so that we can use json nodes in your program.

var indObj = $.parseJSON(jsonpassedvariablehere);


that it. now you can send json data from anywhere in your program and can use that anywhere in your program by serialize and deserialize the objects

Thanks 

Friday, February 15, 2013

What is the difference between visibility:hidden and display:none


visibility:hidden and display:none are not synonims.

display:none means that the the tag in question will not appear on the page at all (although you can still interact with it through the dom). There will be no space allocated for it between the other tags. 


Visibility:hidden means that unlike display:none, the tag is not visible, but space is allocated for it on the page. so for example

Monday, January 28, 2013

JSON: creating json in java and rendering javascript (JAVA string to JSON in javascript)

java string to json in javascript:


This is a common problem while we are transferring data from one technology to other technology. Specially encoding and decoding are concern while different format of data is required in different environment.

In my current piece of work i was required to create a JSON string in java and pass it to view (jsp) page where with the help of JavaScript (jQuery) data render need to perform.

common problem face

  • How to create a json data string in core java classes.
  • how to transfer json data from java to jsp 
  • How to convert normal java string to json object in javascript.  

Java does not understand json so for creating json in java various library are available. I picked simplest way like, I created a java string as like as json data and pass that string to the javascript. In the javascript end i converted that java string in to javascript string (by adding a null string like;var newval =  ""+strVariable). then with the help of jQuery.parseJSON() i converted it to the json object and renders. Below is the code which will describe in the details.

Ajax call from JSP:



       $(document).ready(function () {
        $.ajax({
        method:"GET",
        url: "user-struts action.action",
        //data: "variableifany="+$("#variableifany").val(),
        success: function(dataUser) {
//converting java string to javascript sting
//by adding null string ("") to the returned java string
        var yuyu = $.parseJSON(""+dataUser);
//simple testing of json object by calling jquery each function
$.each(yuyu, function(key, val) {
alert(val["id"]+"-"+val["text"]);
});
         
                     $("#divtoplace").select2({
                    multiple: true,
                       query: function (query){
                         var data = {results: []};
                         $.each(yuyu, function(){
                             if(query.term.length == 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0 ){
                                 data.results.push({id: this.id, text: this.text });
                             }
                         });
                         query.callback(data);
                     }
                    });
         
        },
   error: function(XMLHttpRequest, textStatus, errorThrown){
       alert("errorThrown="+errorThrown+
        '----zipcodesuccessError=' + textStatus+"----response text = "+XMLHttpRequest.responseText);
   }
        });


JAVA class code: 

String userJson = "[";
                map= new userList().users();
for (Map.Entry entry : map.entrySet()) {
userJson += "{ \"id\": \""+entry.getKey()+"\", \"text\": \""+entry.getValue()+"\" },";
}
userJson = userJson.substring(0, userJson.length()-1)+"]";
System.out.println("jsodata="+userJson);
inputStream=new StringBufferInputStream(userJson);
return SUCCESS;



Important points to remember:

  • while creating json string in java do remember to match the json format like 
  • do remember to convert from java string to javascript string
  • now parse the javascript string to json object.
  • now your json object is ready to user.

Thanks