Monday, March 26, 2012

Basic Java Interview Questions & Answers



1) Which statement(s) declare an array of string objects?

String[] s

String []s

String[ s]

String []s

2) Which of the following is true about constructor and method ?

Constructor have its own name,and return type, innvoked using new operator

Function has its own name, a return type and is invoked using the dot operator

Constructor has name of class and no return type, and is innvoked using new operator

3) Basic I/O is performed by which class?

Security Manager

Math

Run time

System

None of these above

3 ) An example of polymorphism :

Inner Class

Method Over Loading

Method over ridding

annonymouse class

4) Which is primitive type :

byte

String

Float

5) 1.4.56+ "1.2" returns

String 5.76

Long 5

Double 5.76

String "4.561.2"

6) Asssuming that we have not provided any arguments on the command line, the first element of the string array in the main method contains:

The name of the programe

null

empty

the input for the program

7) How do you implement polymorphism in java?

Method over loading

Method over overridding through the java inter faces

Method over overridding through inheritance

8) What is the output of the following code
int arrayint[][]=new int[10][20]
int arrayint1[][]={{1,2},{1,4},{6,5}}

10 & 3

20 & 2

20 & 3

20 & 6

9) consider the following code sample
if(a!=null&&a.length()>0){ ...}
what will happen if replace && with &?

Logical error

Null pointer exception

There is no output

None of the above

10) there are two classes class A and class B. If class A what to inform B some important information it uses which of the following method(s)

notify(),notifyall(),wait()

notify(),notifyall()

notifyall(),wait()

None of the above

11) when do we get a default constructor

When the class has no other constructor

When we define at least one constructor

When we define a class

None of the above

12) which of the following will output -6?

System.out.println(Math.floor(-6.7))

System.out.println(Math.ceil(-6.7))

System.out.println(Math.Min(-6.7))

System.out.println(Math.round(-6.7))

13) Which of the following are methods of math class

Absolute()

log()

cosine()

sine()

None of the above

14) when two or more objects are added as listeners of the same event,which listerner will inovked first to handle the event?

First object that was added as listener

Last object that was added as listener

There is no way to determine which listener will be invoked first

it is impossible to have more than one listener for a given event

15) character literals are stored as unicode characters :

true

False







please correct me if i am make any mistake :(

Tuesday, February 28, 2012

Best Web site to learn about internet

www.20thingsilearned.com/

its also from google's product :)

Thursday, February 23, 2012

ELSON'S DESIGN INDEX: Re: MICROSOFT CAMPAIGN

ELSON'S DESIGN INDEX: Re: MICROSOFT CAMPAIGN

Google map pointed to current location

<pre>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>HTML5 Demo: geolocation</title>
<link rel="stylesheet" href="css/html5demos.css">
<script src="js/h5utils.js"></script></head>
<body>
<section id="wrapper">
<header>

</header>
<meta name="viewport" content="width=620" />

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<article>
<p>Finding your location: <span id="status">checking...</span></p>
</article>
<script>

function success(position) {
var s = document.querySelector('#status');

if (s.className == 'success') {
// not sure why we're hitting this twice in FF, I think it's to do with a cached result coming back
return;
}

s.innerHTML = "";
s.className = 'success';

var mapcanvas = document.createElement('div');
mapcanvas.id = 'mapcanvas';
mapcanvas.style.height = '400px';
mapcanvas.style.width = '560px';
document.querySelector('article').appendChild(mapcanvas);

var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);

var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"You are here!"
});
}

function error(msg) {
var s = document.querySelector('#status');
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'fail';
// console.log(arguments);
}

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}

</script>

</section>

<script src="js/prettify.packed.js"></script>
<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
try {
var pageTracker = _gat._getTracker("UA-1656750-18");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>

</pre>

Wednesday, February 22, 2012

Unzip a file using java

______________________________________________
Here i am giving the code to unzip a zip file
______________________________________________

import java.io.*;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Unzipfl {
public static void main(String[] args) throws Exception {
String zipname = "wavw.zip"; //File name of zip archieve
File f = new File(zipname.split("\\.")[0]);
f.mkdir();
ZipFile zipFile = new ZipFile(zipname);
Enumeration enumeration = zipFile.entries();
while (enumeration.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
System.out.println("Unzipping: " + zipEntry.getName());
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
int size;
byte[] buffer = new byte[2048];



System.out.println("name ="+zipEntry.getName()+"zip file name "+zipname);

BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream((zipname.split("\\.")[0])+"\\"+zipEntry.getName()), buffer.length);
while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, size);
}
bos.flush();
bos.close();
bis.close();
}
}
}

Monday, February 20, 2012

Consume Json from url using jquery

This is my json structure
__________________________________________________________
{
"Data": [
{ "CurrentDistance": 8,
"Id": "78faf314-3a13-4496-b9d0-73f6737de6c5",
"IsOpen": false,

"Location":

{

"Address": "103 Dominion Road",

"Latitude": -36.871656,

"Longitude": 174.752011

},

"Name": "Champion Bakehouse"

}


], "ErrorMessage": null, "Success": true

}
__________________________________________________________

Here is the html file to consume json using jquery

____________________________________________________________
<!DOCTYPE html>
<html>
<head>
<style>img{ height: 100px; float: left; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="images">

</div>
<script>
function sn()
{
alert('@ sn() ');
$.getJSON("http://mYweBsite/Location.svc/GetNear?callback=?",


{
//parametres for json
format: 'jsonp',
latitude:-36.871641,
longitude:174.752108,
keyword:'Champion',
onlywithspecials:true
},
function(data) {
alert('heloo @ Function '+data);
$.each(data.Data, function(i,Data){


content = '<br/>Current Distance :' + Data.CurrentDistance + '';
content=content+'<br/> ID : '+Data.Id+'<br/>Address :'+Data.Location.Address;
content=content+'<br/>Name :'+Data.Name+'';
$(content).appendTo("#product_list");
});
});
}</script>

<div id="product_list"></div>
<input type="button" value="call fn " onClick="sn();"/>

</body>
</html>

____________________________________________________________

sample code for Upload file to Apache Jackrabbit

package rabbit;


import java.io.FileInputStream;
import java.io.InputStream;

import javax.jcr.Repository;
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;


import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.core.TransientRepository;
public class upload_rule
{


public static void main(String[] args) throws Exception
{
Repository repository = new TransientRepository();


// Code For Creating workspace in jackrabbit
//((org.apache.jackrabbit.core.WorkspaceImpl)workspace).createWorkspace("MyWorkSpace");



Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()),"MyWorkSpace");
try
{

//take the file as inputstream here i fetch from "E"drive and file name rules.xls from directory arunpaul
InputStream fileStream = new FileInputStream("E:\\arunpaulk\\rules.xls");

//creating a node to save file data here i create node named "test_data"

Node root = session.getRootNode().addNode("test_data");

// Store content
Node traffic = root.addNode("traffic_data");
Node info = traffic.addNode("trafficInfo_compulsory_rules");
info.addMixin(JcrConstants.MIX_VERSIONABLE); //to set versions
info.setProperty("jcr:content", fileStream);
System.out.println("DataSaved");
session.save();

String user = session.getUserID();
System.out.println("Your in WorkSpace : "+session.getWorkspace().getName());
System.out.println("You Logd in as "+user);
System.out.println("Data out :"+info.getProperty("jcr:content").getStream().read());

//((org.apache.jackrabbit.core.WorkspaceImpl)workspace).createWorkspace("eFerns");
/* String name = repository.getDescriptor(Repository.REP_NAME_DESC);
System.out.println("Logged in as " + user + " to a " + name + " repository.");
System.out.println(node.getPath());
*/

// System.out.println(info.getProperty("trafficInfo").getString());
System.out.println(info.getBaseVersion().getName()+": version Name");
System.out.println(info.getBaseVersion().getPath()+": path");


}
finally
{
session.logout();
}
}
}

Convert GWT application to GXT sencha application

1.download eclipse helios form corresponding sites

2.go to help and choose install new software

3.go to code.google.com and select getting started check the prerequisites (Strict to the instruction manual)

4. then select setup for eclipse and copy paste the link to install software's http textbox

5.tick the hide box

6.press next button

7. next ----> accept the terms FINISH

8. check any prerequisites for gxt[ eclipse 6 and jdk 6 ( oct-2011 ) ].

9.Download the latest Ext GWT release (currently2.2.0).

http://www.sencha.com/products/gwt/download.php

10. wait for to complete the installing process in eclipse.

11.install the designer

12. Make userlib by using the downloaded gxt[ in that rename the file gxt2.22 as gxt and add that gxt jar file to user lib]

13.create a java project with gwt support. (Specify the path of Extracted(already downloaded file will extract to specific path in my case its c:\))

CREATE A PROJECT WITH GWT SUPPORT 2ND BUTTON BELOW THE FILE

GIVE PROJECT NAME------>NEXT--------->TICK THE CREATE TIC BOX ON TOP AND CHANGE THE NAME OF IMAGEVIEWER IF NECESSARY DONT FORGET CHOOSE GXT(EXT GWT)


14.copy all the files from [C:\gxt-2.2.5\resources] resources and paste it into war file of your project

15.Open the html file in war and add the following line in tag




16.OPen the xml file from client check this file is exsisting else add theis file