Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

September 14, 2009

Belzabar Questions (Flash and Java)

Flash (28 questions remain)

You can set the size, frame rate, and background color in:
Please select an answer
Document properties
Stage
Property inspector
Action panel
Timeline

Employment Assessment
Flash (27 questions remain)

Which of the following is not an Event Handler?
Please select an answer
load
enterframe
frameload
mousedown

Flash (26 questions remain)

You have just added a Motion Guide layer to your movie and have drawn a path in it. For an object's motion to follow a path, what must be attached to the path?

Please select an answer
The Streaming Graph
The bottom-most point of the object on every frame in the tween
The registration point of the symbol in the starting and ending keyframe
A second instance of the moving object in that frame.
There should not be anything attached to the path that would cause a motion error.

ployment Assessment
Flash (25 questions remain)

Which one of the following statements regarding tweening is true?
Please select an answer
Two or more tweened symbols should be placed on the same layer.
You cannot tween color changes, only the motion of an object.
An error occurs if you try to motion tween an instance of an object.
Alpha Transparency is controlled by using the Fade option.
Orientation, Rotation, and Easing are controlled in the Properties Panel.

Flash (24 questions remain)

Using the startDrag() action, a movie clip can be made draggable until when?
Please select an answer
Until the movie clip is dragged off of the visible portion of the stage
Until the stopDrag() action is used or another movie clip is made draggable
Until the movie clip is dragged over an object on a locked layer
Until the Constrain to Rectangle option is set
Until the mouse is released or double-clicked

Flash (23 questions remain)

Which one of the following commands converts a raster image into a vector image?

Please select an answer
The Color Effect command
The Scale and Rotate command
The Trace Bitmap command
The Optimize Shape command
The Add Shape Hint command

Flash (22 questions remain)

Which ActionScript method loads an MP3 file and plays the sound while downloading?

Please select an answer
loadSound("audio/mysounds.mp3",true);
attachSound("audio/mysounds.mp3");
loadSound("audio/mysounds.mp3",false);
loadMovie("audio/mysounds.mp3");
loadMovie("audio/mysounds.mp3",true);

Flash (21 questions remain)

On your main timeline, you have a MovieClip instance moving across the stage over a period of 100 frames. You would like to use the Output Window to view the pixel location of the instance for each frame of animation.

Which one of the following ActionScript functions outputs text to the Output Window?

Please select an answer
Debug.print()
output()
trace()
show()
System.write()

Flash (20 questions remain)

To create a new, blank movieclip on stage, which one of the following ActionScript commands do you use?

Please select an answer
createEmptyMovieClip("myNewClip",100);
attachMovie(null,"myNewClip",100);
duplicateMovieClip("myNewClip",100);
myNewClip.loadMovie(null);
myNewClip = new MovieClip();

Flash (19 questions remain)

What does this sample code represent?

if (myVar == ("Gordon"||"Vicki"||"Chuck")){
_root[myVar].gotoAndPlay(1);
}else{
_root.welcome.gotoAndPlay(1);
}

Please select an answer
function that detects the client's username information and moves the playhead of the main timeline depending on the value
A conditional action that checks the value of myVar and plays one of several movie clips depending on the value
A conditional action that moves the playhead of the main timeline to the Frame Label specified by the myVar variable
An array that sets the value of the myVar variable depending on the current frame
An ActionScript that causes an error because there are no valid targets specified

Java II (18 questions remain)

If you compile and execute an application with the following code in its main() method:

String s = new String( �Computer� );
if( s == �Computer� )
System.out.println( �Equal A� );
if( s.equals( �Computer� ) )
System.out.println( �Equal B� );

Please select an answer
It will not compile because the String class does not support the = = operator.
It will compile and run, but nothing is printed.
�Equal A� is the only thing that is printed.
�Equal B� is the only thing that is printed.
Both �Equal A� and �Equal B� are printed.

Java II (17 questions remain)

Consider the two statements:
1. boolean passingScore = false && grade == 70;
2. boolean passingScore = false & grade == 70;

The expression : grade == 70, is evaluated:

Please select an answer
in both 1 and 2
in neither 1 nor 2
in 1 but not 2
in 2 but not 1
invalid because false should be FALSE

Java II (16 questions remain)

Given the variable declarations below:
byte myByte;
int myInt;
long myLong;
char myChar;
float myFloat;
double myDouble;

Which one of the following assignments would need an explicit cast?

Please select an answer
myInt= myByte;
myInt= myLong;
myByte= 3;
myInt= myChar;
myFloat= 3;

Java II (15 questions remain)

Consider the code below:
arr[0] = new int[4];
arr[1] = new int[3];
arr[2] = new int[2];
arr[3] = new int[1];
for( int n = 0; n < 4; n++ ) System.out.println( /* what goes here? */ );
Which statement below, when inserted as the
body of the for loop, would print the number of values in each row?

Please select an answer
arr[n].length();
arr.size;
arr.size-1;
arr[n][size];
arr[n].length;

Java II (14 questions remain)

Given following code with line numbers:
31. // some code here
32. try {
33. // some code here
34. } catch (SomeException se) {
35. // some code here
36. } finalize {
37. // some code here
38. }
Under which circumstances will the code on line 37 be executed?
(Choose Correct Answer.)

Please select an answer
The instance gets garbage collected.
The code on line 33 throws an exception.
Compilation error
The code on line 31 throws an exception.
Will never get executed

Java II (13 questions remain)

Which Man class properly represents the relationship “Man has a best
friend who is a Dog�?
Please select an answer
class Man extends Dog { }
class Man implements Dog { }
class Man { private BestFriend dog; }
class Man { private Dog bestFriend; }
class Man { private Dog }
class Man { private BestFriend }

Java II (12 questions remain)

Which about the three java.lang classes String, StringBuilder, and StringBuffer is true

Please select an answer
All three classes have a length property.
Objects of type StringBuffer are thread-safe.
All three classes have overloaded append() methods.
The "+" is an overloaded operator for all three classes.
According to the API, StringBuffer will be faster than StringBuilder under most
The value of an instance of any of these three types can be modified through various methods in the API.

Java II (11 questions remain)

Which statement is true about comparing two instances of the same class, given that the equals() and hashCode() methods have been properly overridden? (Choose all that apply.)

Please select an answer
If the equals() method returns true, the hashCode() comparison == might return false.
If the equals() method returns false, the hashCode() comparison == might return true.
If the hashCode() comparison == returns true, the equals() method must return true.
If the hashCode() comparison != returns true, the equals() method might return true.
All of the above

Java II (10 questions remain)

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

Please select an answer
java.util.HashSet
java.util.LinkedHashSet
java.util.List
java.util.ArrayList
java.util.Vector
java.util.PriorityQueue

Java II (9 questions remain)

Given this method in a class:
21. public String toString() {
22. StringBuffer buffer = new StringBuffer();
23. buffer.append(’<’);
24. buffer.append(this.name);
25. buffer.append(’>’);
26. return buffer.toString();
27. }
Which is true?

Please select an answer
This code is NOT thread-safe.
The programmer can replace StringBuffer with StringBuilder with no other changes.
This code will perform well and converting the code to use StringBuilder will not enhance the performance.
This code will perform poorly. For better performance, the code should be rewritten: return “<“+ this.name + “>�;

Java II (8 questions remain)

Given 1. public class Threads3 implements Runnable {
2. public void run() {
3. );
4. }
5. public static void main(String[] args) {
6. Thread t = new Thread(new Threads3());
7. t.run();
8. t.run();
9. t.start();
10. }
11. }
What is the result?

Please select an answer
Compilation fails.
An exception is thrown at runtime.
The code executes and prints “running�.
The code executes and prints “runningrunning�.
The code executes and prints “runningrunningrunningâ€

Java II (7 questions remain)

Which is true?

Please select an answer
An encapsulated, public class promotes re-use.
Classes that share the same interface are always tightly encapsulated.
An encapsulated class allows subclasses to overload methods, but does NOT allow overriding methods.
All of the above

Java II (6 questions remain)

Which three occur during JSP page translation?

Please select an answer
JSP init method is called.
JSP page implementation class is created and compiled.
JSP page initializeMe() is called
JSP page is destroyed.
associated file tags are validated for syntax.

Java II (5 questions remain)

JSP page developer wants to add a comment to final output in browser.Which comment should be used:

Please select an answer

<%// this is a comment%>
<%-- this is a comment--%>
<%/* this is a comment*/%>

Java II (4 questions remain)

Request Dispatcher can be obtained from which two objects:

Please select an answer
ServletConfig
HttpServletRequest
HttpServletResponse
Session

Java II (3 questions remain)

Which class does not need ac commection to be alive

Please select an answer
RowSet
ResultSet
All of the above
None of above

Java II (2 questions remain)

which is correct web application deployment descriptor element for defining servlet initializing parameter

Please select an answer
" "
""
""
""

Java II (1 questions remain)

Given:
10. interface A { void x(); }
11. class B implements Ab { public void x() { } public voidy() { } }
12. class C extends B { public void x() {} }
And:
20. java.util.List list = new java.util.ArrayList();
21. list.add(new B());
22. list.add(new C());
23. for (Ab a:list) {
24. a.x();
25. a.y();;
26. }
What is the result?

Please select an answer
The code runs with no output.
An exception is thrown at runtime.
Compilation fails because of an error in line 20.
Compilation fails because of an error in line 21.
Compilation fails because of an error in line 23.
Compilation fails because of an error in line 25.

Good Questions

Q: Why methods like wait() , notify(), notifyAll() are present in Object class and not in Runnable Interface?
Ans : http://www.coderanch.com/t/234332/Threads-Synchronization/java/why-does-Object-class-have

Puzzles (Probability Questions)

Q: Find the probability of getting a number with 7 between 100 and 999 (both inclusive).
Ans : 252/900
between 100 to 200, there are 19 numbers ..
19*8 = 152
+ 100 numbers in b/w 700 to 799.


Q: What is the number of comparisons in the worst case to merge two sorted lists containing n elements each?

A. 2n
B. 2n-1
C. 2n+1
D. 2n-2

Ans : 2n-1

Cyclomatic complexity (or conditional complexity) is a software metric (measurement). It was developed by Thomas J. McCabe Sr. in 1976 and is used to measure the complexity of a program. It directly measures the number of linearly independent paths through a program's source code. For instance, if the source code contained no decision points such as IF statements or FOR loops, the complexity would be 1, since there is only a single path through the code. If the code had a single IF statement containing a single condition there would be two paths through the code, one path where the IF statement is evaluated as TRUE and one path where the IF statement is evaluated as FALSE.

Mathematically, the cyclomatic complexity of a structured program[note 1] is defined with reference to a directed graph containing the basic blocks of the program, with an edge between two basic blocks if control may pass from the first to the second (the control flow graph of the program). The complexity is then defined as:[2]

M = E - N + 2P

where

M = cyclomatic complexity
E = the number of edges of the graph
N = the number of nodes of the graph
P = the number of connected components.

The same function as above, shown as a strongly-connected control flow graph, for calculation via the alternative method. For this graph, E = 10, N = 8 and P = 1, so the cyclomatic complexity of the program is still 3.

An alternative formulation is to use a graph in which each exit point is connected back to the entry point. In this case, the graph is said to be strongly connected, and the cyclomatic complexity of the program is equal to the cyclomatic number of its graph (also known as the first Betti number), which is defined as:[2]

M = E - N + P

This may be seen as calculating the number of linearly independent cycles that exist in the graph, i.e. those cycles that do not contain other cycles within themselves. Note that because each exit point loops back to the entry point, there is at least one such cycle for each exit point.

For a single program (or subroutine or method), P is always equal to 1. Cyclomatic complexity may, however, be applied to several such programs or subprograms at the same time (e.g., to all of the methods in a class), and in these cases P will be equal to the number of programs in question, as each subprogram will appear as a disconnected subset of the graph.

It can be shown that the cyclomatic complexity of any structured program with only one entrance point and one exit point is equal to the number of decision points (i.e., 'if' statements or conditional loops) contained in that program plus one.[2][3]

Cyclomatic complexity may be extended to a program with multiple exit points; in this case it is equal to:

p - s + 2

where p is the number of decision points in the program, and s is the number of exit points

XOR of two numbers a and b can be found :
a^b or a|b & !(a&b)

August 25, 2009

Three ants puzzle

There are three ants at the three corners of a regular
triangle. Each ant starts moving on a straight line toward
another, randomly chosen corner. What is the probability
that none of the ants collide?
2 comments:

Anonymous said...

25%. From the ant's perspective each can go left or right. There are 8 poss combinations - LLL, LLR, LRL, RLL, LRR, RLR, RRL, and RRR. You can also work that out by raising 2 (the number of choices) to the power of 3 (the number of choosers) = 2 x 2 x 2 = 8. In only 2 of these cases (LLL and RRR will there be no collisions, so 2 / 8 = 0.25

Secret Squïrrel
March 9, 2008 6:34 AM
Neeraj said...

There are two directions tomove for each ant
Thus total 2x2x2 =8 movements in different directions
out of these only two result in non - collisions of any of the ant - either all clockwise or all counter clockwise
Thus rest 6 result in at leaat 1 collission.
Thus probablility of non collision = 2/8=1/4=0.25


Reference : http://puzzles4you.blogspot.com/2008/03/three-ants.html

Three ants puzzle

There are three ants at the three corners of a regular
triangle. Each ant starts moving on a straight line toward
another, randomly chosen corner. What is the probability
that none of the ants collide?

25%. From the ant's perspective each can go left or right. There are 8 poss combinations - LLL, LLR, LRL, RLL, LRR, RLR, RRL, and RRR. You can also work that out by raising 2 (the number of choices) to the power of 3 (the number of choosers) = 2 x 2 x 2 = 8. In only 2 of these cases (LLL and RRR will there be no collisions, so 2 / 8 = 0.25

There are two directions to move for each ant
Thus total 2x2x2 =8 movements in different directions
out of these only two result in non - collisions of any of the ant - either all clockwise or all counter clockwise
Thus rest 6 result in at leaat 1 collission.
Thus probablility of non collision = 2/8=1/4=0.25


Reference : http://puzzles4you.blogspot.com/2008/03/three-ants.html

How many such points on the earth

Q Find all the points on the globe from which if you travel 1km south, then 1 km east and then 1 km north; you end up at the same point from which you started.

Hints:
1. There is an infinite amount of such points.
2. The answer is 100% true, no tricks - so don't waste your time searching for any.


Ans : Half the answer is this:
There is some place on the globe, where the perimeter of the earth is exactly 1 km. If you start walking from any point which is 1 km north of that ring, and walk 1 km south, you'll end up on the 1 km perimeter. You'll then go 1 km east which will take you all the way around the globe and then you'll go 1 km north and end up in the starting point.

This is the answer which many people give, but it's not full. It gives us a stip (or a ring) of points with this property, but there is also an infinite amount of such strips (or rings):
The full answer, as given by UnToha, is that the perimeter of the walk around the globe doesn't have to be 1 km. It can be any factor of 1 km so that when walking 1 km east, you'll walk some K times around the globe (where K has to be an integer), thus making several complete trips around the globe. This gives us an infinite amount of rings, each having an infinite amount of points, all of which have this strange property.

reference : http://neworder.box.sk/forum/viewtopic.php?id=40242

java.lang.String

Q : If we create a custom class String in the directory structure like java.lang and import it in our class. Which version of String class would be imported : Custom class or Standard Library class ??

Ans : Java has been coded such that it would pick its Standard library class only even if we define class with same name and same package structure.
So the class might compile but would give a runtime exception if we try to invoke a method which we defined in our custom class n which is not present in the std library class.

e.g.
package java.lang;

public final class String {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

public String toString(){
return "Custom Java Class";
}

public static void myMethod(){
System.out.println("My custom java class");
}

}


and a class

import java.lang.String;
public class StringTesting {

/**
* @param args
*/
public static void main(String[] args) {
String str = new String();
java.lang.String.myMethod();
}

}


the code will compile coz at the compile time , its referring to the custom java class , but at run time, the standard java class would be loaded and since it doesnt have myMethod(), it would generate run time exception.

This is because when our custom java.lang.String class is referenced, the class loader checks if this has already been loaded and it finds that a class with the same fully classified class name has already been loaded (which is the one provided by java) and so does not load the custom java.lang.String class

August 24, 2009

Command to see decompiler output

javap -s -verbose -l com.xyz.collection.IteratorException >op.txt

Nice Question

class Test {

static int m(byte a, int b) { return a+b; }

static int m(short a, short b) { return a-b; }

public static void main(String[] args) {

System.out.println(m(12, 2));// compile-time error

}

}