Mock tests, Interview questions, Tutorials and Tech news
 
 

Archive

Archive for January, 2011

rownum alternative in myssql

January 30th, 2011 Vinay No comments

What is the alternative to rownum in mysql ?

Select * from table_name AND LIMIT 0,1

Alternative to rownum in hssql

SELECT  limit 0 1 * FROM table_name

Categories: Programming / tutorials Tags: ,

SCEA Certification Practice test – Part 1

January 29th, 2011 Vinay No comments

SCEA architect Certification (Part 1) CX 310-052 consists of objective questions and answers on various topics like security, Design patterns , EJb etc. There is practice test on part 1

SCEA Certification Practice test

Apart from this test, you will find other related tests which will will help you in preparation for SCEA.

There is another tests for Design patterns Design pattern practice test

One test on EJB, Enterprise java bean – EJB quiz

JSP and Servlet Quiz Read more…

Invocation of REST service from Java Script

January 29th, 2011 Vinay No comments

We had shown an example to create your REST service in Java using JERSEY Creating your first REST service using Jersey. In this post we will explain how to invoke REST service through Java Script

<html>

<head>

<script type=”text/javascript” charset=”utf-8″ src=”json2.js”></script>

<script type=”text/javascript” charset=”utf-8″ src=”jquery-1.4.4.min.js”></script>

<script>

var restDataResults;

function callMyFirstRestService()

{

var myRestService = null;

if (window.XMLHttpRequest) //for mozilla

{

myRestService = new XMLHttpRequest();

if ( typeof myRestService.overrideMimeType != ‘undefined’)

myRestService.overrideMimeType(‘application/json’);

} Read more…

Tomcat 7 introduces cross site scripting

January 28th, 2011 Vinay No comments

Good news for those of you who had been waiting on Tomcat 7. A stable release has been announced for Tomcat 7. There has been another feature which has made its way into Tomcat 7 and has been back ported into earlier versions of tomcat and that is cross domain scripting

We had talked  in details about cross domain scripting issues and how to fix it. Developers should be careful when using cross domain scripting.

Mark Thomas, SpringSource Employee and member of the Apache Security Committee, shares some of the insight behind the new cross-site script (XSS) protection feature introduced into Tomcat 7, 6 and 5 through this latest release effort.

In describing the problem, Mark explains:

Cross-site scripting (XSS) is the leading form of security vulnerabilities for web applications today. This vulnerability is found when attackers are able to inject client-side scripting into web pages by tricking the browser to trust scripts run from malicious hosts. These scripts usually access user and session information stored in cookies, and allow the hackers to forge trusted user behavior. The result can allow hijackers to control your user account, change your account settings, or redirect web traffic to malicious or false advertising sites. Recently, there has been an increase in high-profile cross-site scripting attacks on sites like Twitter and IBM’s DeveloperWorks, which illustrate how common these vulnerabilities exist on web sites both large and small.

To address this threat, a few cross-site scripting issues have been fixed in Tomcat 7. The ASF has used an unofficial, yet widely supported, extension to the Cookie specifications – httpOnly cookies. Read more…

Synchronous calls with REST Service

January 26th, 2011 Vinay No comments

In last posts , we had shown the example Creating your first REST service using Jersey. Then we introduced to making the Rest call from JavaScript.

The example which we had shown was for asynchronous request. Now let us assume that you want to make an asynchronous call . How will it work out ?

Option A : Let the call be asynchronous and put a while loop at the end

//Create a callback    for myRestService
myRestService.onreadystatechange = function()
{
if (myRestService.readyState == 4)
{
if(myRestService.status == 200)
{
// Retrieve the json object and work on it

var obj = JSON.parse(myRestService.responseText);

for(var i=0;i<obj.length;i++)
{
var item = obj[i];
$(“#restDataResults”).append(
‘<tr><td>’+ item.value1 + ‘</td>’ +
‘<td>’ + item.value2 + ‘</td>’ +

‘</tr>’);
}

done = true;
}
else if(myRestService.status == 404)
{
alert(‘Error occurred:’ + myRestService.responseText);
}else{
alert(“No resposne–Error”);
}
}
};

tempresults = myRestService.send(null);
while(done == false){

//wait here

}

In this case you will see a warning pop up in Firefox

A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.

Option Bfalse changes to true and we make synchronous calls

myRestService.open(“GET”, serviceUrl, true);

Now this works out well in IE but FF does not accept it.

Why it does not work ? Because we are still using the callback mechanism to get back the results

If we change it to regular method call , it will return results

Here is the code

<html>
<head>
<script type=”text/javascript” charset=”utf-8″ src=”json2.js”></script>
<script type=”text/javascript” charset=”utf-8″ src=”jquery-1.4.4.min.js”></script>
<script>

var restDataResults;
var done = false;

function callMyFirstRestService()
{
var myRestService = null;
if (window.XMLHttpRequest) //for mozilla
{
myRestService = new XMLHttpRequest();

if ( typeof myRestService.overrideMimeType != ‘undefined’)
myRestService.overrideMimeType(‘application/json’);
}
else if (window.ActiveXObject) //for IE
{
myRestService = new ActiveXObject(“Microsoft.XMLHTTP”);
}

//This is the url/ restApp is the web app deployed on tomcat.
var serviceUrl = “http://127.0.0.1:8080/restApp/webresources/paramater/1440″;

myRestService.open(“GET”, serviceUrl, false);
//synchronous calls
tempresults = myRestService.send();
var obj = JSON.parse(myRestService.responseText);

}

</script>
</head>
<body>
<h2>My First Rest Service</h2>

<p>My rest Service:
<input type=”button” id=”submitlookup” name=”submitlookup” value=”My First rest Service” onClick=”javascript:callMyFirstRestService();”/>
</p>

<div id=”divRestData” title=”My rest data”>
<table border=”1″>
<thead><tr>
<td width=’70′>Column A Heading</td>
<td width=’100′>Column B Heading</td>
</tr></thead>
<tbody id=’restDataResults’>
</tbody>
</table>
</div>
</body>
</html>

Hope you would have find this helpful.

Parsing JSON Results in Android

January 26th, 2011 androidGuru 5 comments

One of the common requirements for an android programmer is how to parse incoming JSON results from another web service or application into android. JSON is a data interchange format, and serves the same purpose as that of XML. XML is slowly being replaced by JSON because it’s easy to parse, light weight, and efficient too. We had talked about SOAP vs JSON earlier and not going to go into details again.

Let us focus on how to parse JSON results in Android.

We can parse JSON by 2 methods

i)  Using JSONObject and JSONTokener classes provided by Android SDK.
ii) Using external libraries. E.g GSON, Jackson etc.
(for more details refer http://json.org)

Let’s consider JSON data of the form:

{
“name”: “myName”,
“message”: ["myMessage1","myMessage2"],
“place”: “myPlace”,
“date”:  ”thisDate”
}

Parsing JSON data using JSONTokener


public
class main extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

try {

/* Inflate TextView from the layout */

TextView tv = (TextView)findViewById(R.id.TextView01);

/* JSON data considered as an example. Generally this data is obtained

from a web service.*/

String json = “{”

+ “  \”name\”: \”myName\”, ”

+ “  \”message\”: [\"myMessage1\",\"myMessage2\"],”

+ “  \”place\”: \”myPlace\”, ”

+ “  \”date\”: \”thisDate\” ”

+ “}”;

/* Create a JSON object and parse the required values */

JSONObject object = (JSONObject) new JSONTokener(json).nextValue();

String name = object.getString(“name”);

String place = object.getString(“place”);

String date = object.getString(“date”);

JSONArray message = object.getJSONArray(“message”);

tv.setText(“Name: “+ name +”\n\n”);

tv.append(“Place: “+ place +”\n\n”);

tv.append(“Date: “+ date +”\n\n”);

for(int i=0;i<message.length();i++)

{

tv.append(“Message: “+ message.getString(i) +”\n\n”);

}

} catch (JSONException e) {e.printStackTrace();}

catch(Exception ex){ex.printStackTrace();}

}

}

Read more…

Categories: Programming / tutorials Tags: ,

Creating a Custom Widget in android

January 20th, 2011 androidGuru 3 comments

Apart from using text box buttons and widgets provided in android widget tool kit we can create custom UI that suits the user needs. In this post , I will explain how to to create a custom widgetstep by step.

Custom views can be created by using two classes “View” and “SurfaceView”. Both classes are used exactly the same way, but surface encapsulated by SurfaceView supports OpenGL ES library (Using OpenGL we can draw 2D and 3D objects). Also, all application views run in the main application thread, whenever you want to update View’s UI rapidly the code blocks the GUI thread.  But SurfaceView can update from the background thread. Thus SurfaceView is most commonly used in gaming and applications with heavy graphics.

To start drawing custom widgets 3basic drawing components are required

1)    Canvas : provides surface for drawing your widgets

2)    Paint: While physically drawing a picture we make use of paint brushes of different sizes and different brushes for different colors. Similarly Paint object is used to draw widgets of different colors and textures.

3)    Bitmap: Bitmap is the surface under the canvas. It holds the raw pixel values of the images draw on the canvas. While drawing on the canvas we do not color individual pixels we draw upon continuous area, the corresponding pixel values are then placed on the Bitmap.

Apart from this developers are provided with different methods to draw on the canvas.

Some of the commonly used methods are described below:

1)    drawCircle: draws circle on the canvas.

2)    drawRect: to draw a rectangle on the  canvas.

3)    drawLine: Draws a line on the canvas.

4)    drawOval: Draws an oval bounded by specified rectangle.

5)    drawBitmap: to draw bitmap on the canvas.

6)    drawPicture: to draw picture object within specified rectangle.

7)    drawText: Draws a string on the canvas.

Now lets start creating over own widgets.

Step 1: Create a View class.

public class MyView extends View{

}

Step 2: Your class may require 3 different constructors. So lets create it. Read more…

Categories: Programming / tutorials Tags:

Tools to monitor your website

January 19th, 2011 Vinay No comments

Here are some tools that can help you diagnose website issues:

Categories: Tech news Tags: ,
Get Adobe Flash playerPlugin by wpburn.com wordpress themes