Ram Pathan

Greenhorn
+ Follow
since May 18, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ram Pathan

I thought I did well but I am required to resubmit my assignment. I need to work on Deployment Diagram, Interaction Diagram and Risk & Mitigation Strategy.

For those of you who passed these sections can you share a web link that you used as reference for these?

@ Deployment Diagram - Did you guys provide 4 diagrams as mentioned here - http://www.uml-diagrams.org/deployment-diagrams-overview.html?





How can i make the main method return the value of i as 10 (i.e value modified in run method)
interface Hithere
{
public void hello();
}
public class test implements Runnable, Hithere
{
static Thread th;
int i;
public test()
{
System.out.println("Before run");
(new Thread("add")).start();
System.out.println("after run");
}
public static void main(String[] args)
{
t=new test();
System.out.println(t.i);
}
public void run()
{
i=10;
System.out.println("i am in run");
}
public void hello()
{
}
}
Thanks for your replies jessica,thomas and corey.
I understood the Behaviour of string class as follows -
CASE 1 )
String str1="a";
String str2="a"
str1==str2 //true
str1.equals(str2) //true
CASE 2)
String str1=new str1("a");
String str2=new str2("a");
str1==str2 //false
str1.equals(str2); //true
CASE 3)
String str1=new str1("a")
String str2="a"
str1==str2 //false
str1.equals(str2) //true
CASE 4) GENERAL
Object obj1=new Object();
Object obj2=new Object();
obj1==obj2 //false
equals needs to be overridden by the class !!
PLZ CORRECT ME IF I AM WRONG !!
==================================================
Just when i thought i got the concept right ...
I realised may be i didnt !!!
Look at these questions from mock exams .......
Q 1) What is the output of the following
StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2= new StringBuffer("Amit");
String ss1 = "Amit";
System.out.println(sb1==sb2); //false
System.out.println(sb1.equals(sb2)); //true
System.out.println(sb1.equals(ss1)); //true
System.out.println("Poddar".substring(3)); //dar
Ans:
a) false
false
false
dar
b) false
true
false
Poddar
c) Compiler Error
d) true
true
false
dar
Correct Answer is a)
MY QUESTION) WHY IS sb1.equals(sb2) FALSE ?? SO ALSO WHY IS sb1.equals(ss1) FALSE ??

Q 2) What is the output (Assuming written inside main)
String s1 = new String("amit");
System.out.println(s1.replace('m','r')); //arit
System.out.println(s1); //amit
String s3="arit"; //arit
String s4="arit"; //arit
String s2 = s1.replace('m','r'); //arit
System.out.println(s2==s3); //true
System.out.println(s3==s4); //true
a) arit
amit
false
true
b) arit
arit
false
true
c) amit
amit
false
true
d) arit
amit
true
true
Correct answer is a) s3==s4 is true because java points both s3 and s4 to same memory location in string pool
MY QUESTION -> WHY IS S2==S3 FALSE ??
--------------------------------------------------
Hi
can someone let me know how == and equals work
in the following cases ?
String a1= new String("a")
String a2= new String("a")
Stirng a3=String("a")
String a4=String("a")
Stirng a5="a"
String a6="a"
a1==a2
a1.equals(a2)
a3=a4
a3equals(a4)
a5==a6
a5.equals(a6)
a1==a3
a1.equals(a3)
a1=a5
a1equals(a5)
Will the ans remain same if all the above were
StringBufferclasses instead of string objects ?
How can you say that strings are immutable
when you can do an operation like
String motto="Program Once"
motto=motto+"execute everywhere"
motto=motto.concat("dont bet oin it!");
(Plz refer Mughal and rasmussen page 311)
Question 1)
What will happend when you attempt to compile and run the following code?
public class Tux extends Thread
{
static String sName = "vandeleur";
public static void main(String argv[])
{
Tux t = new Tux();
t.piggy(sName);
System.out.println(sName);
}
public void piggy(String sName)
{
sName = sName + " wiggy";
start();
}
public void run()
{
for(int i=0;i < 4; i++)
{
sName = sName + " " + i;
}
}
}
1) Compile time error
2) Compilation and output of "vandeleur wiggy"
3) Compilation and output of "vandeleur wiggy 0 1 2 3"
4) Compilation and probably output of "vandeleur" but possible output of "vandeleur 0 1 2 3"
MyDoubts
Q1)True that Run() is a callback function but can it be considered here as an inner function to void piggy(String) because start() which is responsible for it being called is with in the scope of this function??
Q2)Answer to the above question happens to be 4 but will sName (being static) remain uneffected by the statement preceding start() ?
Q3)Is it a hard and fast rule that run should always be public void run() ?? (Am i correct if i answer it like ... since i dont call it i cannot change its signature ??)
Q4)Would sName have been defined in Run() if it werent declared static ?
------------------------------------------------------------------------------------------------------------
Question 2)
Which of the following most closely describes a bitset collection?
1) A class that contains groups of unique sequences of bits
2) A method for flipping individual bits in instance of a primitive type
3) An array of boolean primitives that indicate zeros or ones
4) A collection for storing bits as on-off information, like a vector of bits
MyDoubts
Q1)What is a bitset collection?
------------------------------------------------------------------------------------------------------------
Question 3)How do you change the current layout manager for a container
1) Use the setLayout method
2) Once created you cannot change the current layout manager of a component
3) Use the setLayoutManager method
4) Use the updateLayout method
MyDoubts
Q1) Say I add components to a container using a specified Layout and then when i change the
layout what happens to the components will they be rearranged according to the new component ?
------------------------------------------------------------------------------------------------------------
Question 4) What will happen when you attempt to compile and run the following code
Question->
import java.io.*;
class Base{
public static void amethod()throws FileNotFoundException{}
}
public class ExcepDemo extends Base{
public static void main(String argv[]){
ExcepDemo e = new ExcepDemo();
}
public static void amethod(){}
protected ExcepDemo(){
try{
DataInputStream din = new DataInputStream(System.in);
System.out.println("Pausing");
din.readChar();
System.out.println("Continuing");
this.amethod();
}catch(IOException ioe) {}
}
}
1)Compile time error caused by protected constructor
2) Compile time error caused by amethod not declaring Exception
3) Runtime error caused by amethod not declaring Exception
4) Compile and run with output of "Pausing" and "Continuing" after a key is hit
Mydoubts
Answer to this question has been given as 4 but when static methods of a class cannot be
overridden then how can the answer be 4 ?
------------------------------------------------------------------------------------------------------------
Question 5)
Which of the following statements about threading are true
1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a synchronized method of an object
4) Thread scheduling algorithms are platform dependent
Mydoubts
Wht does he mean by obtaining mutually exclusive lock on any object?
------------------------------------------------------------------------------------------------------------
Question 6)
Which of the following statements are true?
1) The garbage collection algorithm in Java is vendor implemented
2) The size of primitives is platform dependent
3) The default type for a numerical literal with decimal component is a float.
4) You can modify the value in an Instance of the Integer class with the setValue method
Mydoubts
Ans has been given as 1 .... Why is answer 2 wrong ?? when size of int on unix and dos isnt the same.
------------------------------------------------------------------------------------------------------------
Question 7)
Which of the following statements are true?
1) A method cannot be overloaded to be less public in a child class
2) To be overridden a method must have the same name and parameter types
3) To be overridden a method must have the same name, parameter and return types
4) An overridden method must have the same name, parameter names and parameter types
answer Given (3) To be overriden a method must have the same name, parameter and return types
Reson - Option 1 is a sneaky one in that it should read overriden not overloaded. An overriden
method must also have the same return type. Parameter names are purely a programmer
convenience and are not a factor in either overloading and overriding. Parameter order
is a factor however.
MyDoubt
But method overriding can widen the scope of a method then y is 1 wrong ?
------------------------------------------------------------------------------------------------------------
Question 8)
Given the following class
public class ZeroPrint{
public static void main(String argv[]){
int i =0;
//Here
}
}
Which of the following lines if placed after the comment //Here will print out 0.
1) System.out.println(i++);
2) System.out.println(i+'0');
3) System.out.println(i);
4) System.out.println(i--);
Answer to Question 8)
1) System.out.println(i++);
3) System.out.println(i);
4) System.out.println(i==);
The options for this question might look suspiciously easy if you are not aware of the effects of
the post-increment operators. The ++ and == operations for examples 1 and 4 only come into
effect after the output operations, ie after whatever else is done to them on that line of
code. Option 2 should be fairly obvious as you should know that the single quote characters
indicate a char value, ie storing the character rather than the numberical value for 0.
MyDoubt
y is option 2 wrong ?