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

Monday, December 3, 2012

Setting java, java_home path for all users in unix

Setting java, java_home path for all users in unix

 
first check if there is a path set in /etc/profile file...
other wise you can set
 
Set JAVA_HOME / PATH for all user:


You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
# vi /etc/profile
Next setup PATH / JAVA_PATH variables as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Save and close the file. Once again you need to type the following command to activate the path settings immediately:
# source /etc/profile

Agile Scrum Sprint

In product development, a scrum sprint is a set period of time during which specific work has to be completed and made ready for review.

Each sprint begins with a planning meeting. During the meeting, the product owner (the person requesting the work) and the development team agree upon exactly what work will be accomplished during the sprint. The development team has the final say when it comes to determining how much work can realistically be accomplished during the sprint, and the product owner has the final say on what criteria needs to be met for the work to be approved and accepted.

The duration of a sprint is determined by the scrum master or development team owner, the team's facilitator. Once the team reaches a consensus for how many days a sprint should last, all future sprints should be the same. Traditionally, a sprint lasts 30 days.

After a sprint begins, the product owner must step back and let the team do their work. During the sprint, the team holds daily stand up meeting to discuss progress and brainstorm solutions to challenges. The project owner may attend these meetings as an observer but is not allowed to participate unless it is to answer questions. The project owner may not make requests for changes during a sprint and only the scrum master has the power to interrupt or stop the sprint.


At the end of the sprint, the team presents its completed work to the project owner and the project owner uses the criteria established at the sprint planning meeting to either accept or reject the work.

Sunday, December 2, 2012

Difference Between cursor and ref cursor


Difference Between cursor and ref cursor:


Ref cursor are variable of type cursor. Once you will declare a Ref cursore you can place any cursor in that ref cousor. In short words you can say ref cursors are holder of of any type of cursor.

if you will see the below code rc is a ref cursor and c is a cursor. rc is opened with different sql queries later but c (normal cursor) which is fixed.

other differences are there also.

> ref cursors can sent to the client. in word of java you can say ref cursors are result sets you can pass to other sub programs
>you cannot declare ref cursor out side procedure.
> A ref cursor can be passed to subroutine to subroutine but normal cursors cannot passed.


Important difference is that 

Static sql (not using a ref cursor) is much more efficient then using ref cursors and that use of ref cursors should be limited to 

-  when returning result sets to clients

 - when there is NO other efficient/effective means of achieving the goal






Declare
   type rc is ref cursor;
   
   cursor c is select * from dual;

   l_cursor rc;
begin
   if ( to_char(sysdate,'dd') = 30 ) then
     open l_cursor for 'select * from emp';
   elsif ( to_char(sysdate,'dd') = 29 ) then
     open l_cursor for select * from dept;
   else
     open l_cursor for select * from dual;
   end if;
   open c;
end;
/
 
 

Monday, November 26, 2012

^M: not found error in unix

^M: not found error in unix

 I was executing a shell script file through the nohup command. while executing the file i got the ^M: not found error in unix command prompt.

Then i started searching why i am getting this error. after making several googling, i got to know that this is due to i created this shell script file in windows (eclipse) OS. 

Normally when we create any file in windows and move/upload it to unix it append ^M in every line in the unix platform. it causes the error. now you need to remove these ^M character from the  shell script to work it properly. You can do that i several ways

1. opening the script file VI editor and manually removing these extra charactors
2. using dos2unix command
3.....


Wednesday, November 7, 2012

Date and Time matching in Where clause in Oracle



Date and Time matching in Where clause in Oracle:

It is trick when you want to match date or  date and time in where clause of you oracle sql query.
some time the original field may will be in date, time or some other field. and when you will put date type data with different format in where clause of you sql query it will mismatch and will not provide you the result you want.

You can avoid this kind of problem by using the to_date(date, format) in you where clause and the original field name as usual.

Below is an example:

select *
from table_name
where assoc_id = '6492349324'
and begin_date = TO_DATE('01-APR-2012', 'DD-MON-YYYY')  --what ever will be the data type of begin_date
and end_date = TO_DATE('01-JUL-2012', 'DD-MON-YYYY')    --the query will only match the date out of it


In the above query any date type data can be matched.



Tuesday, October 23, 2012

Passing Objects as parameters in PHP


Objects are Passed by reference by default:

By default the php objects are passed by reference below example will make it more clear. that is why when we copy object it property's are pointing to the same reference

class {
    public 
$foo 1;

$a = new A;$b $a;     // $a and $b are copies of the same identifier
             // ($a) = ($b) = 
$b->foo 2;
echo 
$a->foo."\n";  //this will output 2 as the reference is copied
                    //$a and $b is point to the same location

$c = new A;$d = &$c;    // $c and $d are references
             // ($c,$d) = 
$d->foo 2;
echo 
$c->foo."\n";

$e = new A;

function 
foo($obj) {
    
// ($obj) = ($e) = 
    
$obj->foo 2;
}
foo($e);
echo 
$e->foo."\n";
?>

the output of the above sample example will
2
2
2



/*
 * Created on Oct 24, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

 class ClassTesting {
 
  private $foo;
 
  function __construct($foo){
  $this->foo = $foo;
  }
 
  private function ent($foo){
  $this->foo = $foo;
  }
 
  public function ret($obj){
  $obj->foo = 'this';
  var_dump($obj->foo);
  }
 }

 $x = new ClassTesting("man");
 $a = new ClassTesting("dog");
 $x->ret($a);

?>

Monday, October 8, 2012

Log file location in Linux

Linux log file location:


you can find various logs related to the linux in the following folder

/var/log/

Under this there are many files contains different types of logs of the system. like syslog contains system related logs

it looks like below:


  • /var/log/message: General message and system related stuff
  • /var/log/auth.log: Authenication logs
  • /var/log/kern.log: Kernel logs
  • /var/log/cron.log: Crond logs (cron job)
  • /var/log/maillog: Mail server logs
  • /var/log/qmail/ : Qmail log directory (more files inside this directory)
  • /var/log/httpd/: Apache access and error logs directory
  • /var/log/lighttpd: Lighttpd access and error logs directory
  • /var/log/boot.log : System boot log
  • /var/log/mysqld.log: MySQL database server log file
  • /var/log/secure: Authentication log
  • /var/log/utmp or /var/log/wtmp : Login records file
  • /var/log/yum.log: Yum log files

Monday, October 1, 2012

Checkbox Value in java or php

Getting Checkbox Value in backend in java or php:


While sending checkbox value from front end HTML to java or php few thinks we need to take care.

1. unchacked checkbox value will not available in the backend(java/php)
2. unchecked checkboxattribute will not available in the java end. if there is a checkbox named 'chck1' and its not checked in the html end. it will not available in the java end. when you will write request.hetAttribute("check1"); it will through an error as these will not a attribute in the request array.


please add anything if i am missing.




Tuesday, September 25, 2012

Java String class, Constructs and methods

Java String Class:

Constructs
Java string class have many constructs to handle java strings. this constructs takes different parameters to handle java string in different manners.

String s = new String(); //string empty constructs

char chars[] = { 'a', 'b', 'c' };
String s = new String(chars);
System.out.println(s.length());  //out put will abc

Methods:

it also provides many methods to handle strings. one of the simplest method is length method. it will return the length of the string.

String s = new String(chars);
System.out.println(s.length());

Other methods are their to handle string. please refer complete reference java for the complete details.

StringBuffer class:

it provides many methods to handle advanced string. like you can append string at a special position. you can insert string, etc



// Demonstrate append().
class appendDemo {
public static void main(String args[]) {
String s;
int a = 42;
StringBuffer sb = new StringBuffer(40);
s = sb.append("a = ").append(a).append("!").toString();
System.out.println(s);
}
}
The output of this example is shown here:
a = 42!



Sunday, September 23, 2012

Relocating Skills

Relocating Skills:


Relocation is the most frequently happenings in our dally life. Most of us relocate every day like relocating from home to work place <> work place office. relocating to vacation spot, hospital for a out door visit, etc.



Relocation like changing you living place is required more concentration. this types of relocation changes many factors of our daily life.

Mainly we relocate due to our job changes. in this case we relocate from one position to another with lot of changes with us. if the job position changed then new position roles. new friends, new environment , etc. we need special care in this situation as we most of us ignore these situation and hopes to automatically to be arranged.


Few things we always need to think while relocating is specially thoughts should not be changed

JSP tags

JSP tags:

JSP tags are mainly divided into three parts.
1. Directive(page,include,tag libs)

  • Page (to include java library and other things)
  • Include ()
  • Tag library

2. Scripting(declaraion,scriptlet,expression)

  • Declaration
  • Scriptlet (original java code which embded inside html code with help of <%%>)
  • Expression

3. Action


 the easy way to remember is



JSP tags->Directive(page,include,tag libs)->scripting(declaraion,scriptlet,expression)->Action

description:

JSP tags
     ->Directive(page,include,tag libs)
     ->scripting(declaraion,scriptlet,expression)
     ->Action




Monday, July 11, 2011

Greate article to Develop your personal managemen skill


Great article to Develop your personal management skill:


Developing a company culture can be a challenge for any business, but especially for ones that employ remote workers. However, it’s crucial for long-term success to have a strong set of values and principles to give your company a unique character that your staff can believe in.
Despite the difficulty of distance, it is possible to grow a company culture when your staff are dotted around the world. You just have to work a little harder at it.
We’ve spoken to two HR experts to bring you five ways to develop and sustain a company culture for remote teams. Have a read and share your thoughts and ideas in the comments below.

1. Write a Mission Statement


It’s not enough to have vague guidelines — you need to have a strong mission statement backed up by a company philosophy that outlines your entire ethos.
Your mission statement should be short and memorable, and it should use your philosophy to expand and explain. In addition to sharing it with staff during the initiation process, put the statement on your company website for all to see and refer to at any time.
Also, you should internally share company goals for the future. Whether these are based on success metrics or less measurable aims, these insights provide the team with direction and empower staff to make educated decisions.

2. Hire the Right People


To develop a strong company culture, every member of staff — from the CEO down to an intern — has to be on board with the philosophy. Add questions into your interview process to determine whether candidates are on the same wave-length as the company.
This is especially important for remote workers, as these teammates will have minimal supervision. You need to match your workers with your company culture. By employing people with the “right” values form the get-go, you’ll have a lot less work ahead of you in making your culture a success across state and even international borders.
In addition, you need to be sure that candidates can cope with remote working. “To aid creation of a virtual culture, and also to help employees decide whether remote team working is for them, it is recommended that organizations first educate themselves and their employees in what the positive and negative implications are,” advises Hilary Blackmore, a chartered occupational psychologist.
“In this way, continuity can be supported for those who subsequently decide to move to a remote working arrangement, as it will help them conceptualize the shift in identity that may be required, reducing the risk of threat.”

3. Create a Close-Knit Team


A close team with shared values is always going to be more motivated than a loose collection of loners. It’s your challenge to try and get your remote team as tight-knit as possible, despite the miles between them.
“Despite the fact that remote workers like the freedom of their work, they still like to be included in the team. There are a number of ways this can be done. If the team members are relatively new and don’t know each other, you can have them do a presentation on themselves to show their interests, family, hobbies and passions,” suggests Michael D. Haberman, SPHR, vice president of Omega HR Solutions.
“One company manager had his employees send a photo of their work area at home and they had a contest with the team members trying to guess whose work area was whose.”

4. Give Your Staff Independence


Give your staff as much autonomy as possible. By letting them make their own decisions based on knowledge of your company philosophy, the corporate principles will be cemented far more effectively than if they just read them and have decisions made for them by more senior staff. Don’t micro-manage.
“There are many ways a manager can still micro-manage a remote team. Instant messaging, phone calls, tracking computer time, times in system, etc. all constitute micro-managing. And that sends the wrong message. Remote teams need to be measured on productivity. Are they getting the work done? If the answer is yes, then leave them alone. If the remote worker is the type of person who needs micro-managing, then the manager made a poor selection choice in that employee,” says Haberman.

5. Recognize and Reward


If one of your staff members does something that is a great example of your company culture, then be sure to highlight this action. Whether you mention it on a team call, write about it on the company blog or just send a group email, recognizing and rewarding staff is a great way to boost morale and keep your company culture strong.

Thursday, April 28, 2011

Function to get next Database ID

the bellow function will give you the next auto increament id of your database primary key.

function getNextID($field_id){
$db =& JFactory::getDBO();
$sql = "SELECT max(id) FROM jos_table WHERE field_name=$name";
$db->setQuery($sql);
$acl_num = $db->loadResult();
if($acl_num<>null){
return ($acl_num + 1);
}else{
return 0;
}
}

in reference to:

"Some time we need to see some string type data of different rows in comma separated or other separated in a single field. for this type of implementation mysql have a function GROUP_CONCAT(field_value) . we can add GROUP BY cluse to get comma separated values in different cases."
- Techinical tips for practical uses (view on Google Sidewiki)

Thursday, February 10, 2011

Getting row values in comma separated using GROUP by or other queries in MySQL

Hi,

Some time we need to see some string type data of different rows in comma separated or other separated in a single field. for this type of implementation mysql have a function GROUP_CONCAT(field_value) . we can add GROUP BY cluse to get comma separated values in different cases.

Example:

GROUP_CONCAT([DISTINCT] expr [,expr ...]
[ORDER BY {unsigned_integer | col_name | expr}
[ASC | DESC] [,col_name ...]]
[SEPARATOR str_val])

mysql> SELECT student_name,
-> GROUP_CONCAT(test_score)
-> FROM student
-> GROUP BY student_name;

in reference to: Aniruddh (view on Google Sidewiki)

Thursday, January 20, 2011

Searching non alpha numeric character through REGEX through PHP

Hi,
you can search non-alpha numeric characters by simple adding a negation regex charactor in the regex string (^).

below is the Example

preg_replace('/[^A-Za-z0-9_]/', '', 'D"usseldorfer H"auptstrasse');

Thanks

in reference to: Aniruddh (view on Google Sidewiki)