Vidya Singh

Greenhorn
+ Follow
since Mar 21, 2007
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vidya Singh

It does not give any warning to me while compiling.
I would like to sell it for $100
14 years ago
src:http://technoheads.blogspot.com/
3) if ("string".toUpperCase() =="STRING")
{
System.out.println("Yes");
}
else System.out.println("No");

Ans -> No // if we use .equals() here , then we get �yes� . This is because , �string� and �STRING� are two separate object references pointing to two separate objects. == is used to compare whether two object references point to same object or not. .equals() compares the objects for their contents.
--------
The explaination seems not correct as if i change the code to
if ("STRING".toUpperCase() =="STRING")
{
System.out.println("Yes");
}
else System.out.println("No");
then the answer is Yes. So, doesn't STRING".toUpperCase() as seperate object than STRING
Thanks for explaining. So, that means if you explicitly defines any constructor, then default constructor does not come into picture, and one has explicitly define a default constructor.
Ques 3 :
Consider the following class definition:
1. public class Test extends Base {
2. public Test(int j) {
3. }
4. public Test(int j, int k) {
5. super(j, k);
6. }
7. }

Which of the following forms of constructor must exist explicitly in the definition of the Base class?


(1) Base() { }
(2) Base(int j) { }
(3) Base(int j, int k) { }
(4) Base(int j, int k, int l) { }


Answer : 1,3
Explanation :
1 and 3 are correct. In the constructor at lines 2 and 3, there is no explicit call to either this() or super(), which means that the compiler will generate a call to the zero argument superclass constructor, as in 1. The explicit call to super() at line 5 requires that the Base class must have a 7.constructor as in 3. This has two consequences. First, 3 must be one of the required constructors and therefore one of the answers.Second, the Base class must have at least that constructor defined explicitly, so the default constructor is not generated, but must be added explicitly. Therefore the constructor of 1 is also required and must be a correct answer.At no point in the Test class is there a call to either a superclass constructor with one or three arguments, so 2 and 4 need not explicitly exist.
-----------

I do not understand why constructor Base() { } is necessary, and default constructor is mentioned explicitly
src:http://technoheads.blogspot.com/

Class finalization can be done by implementing the following method:static void classFinalize() throws Throwable;True Or False?
(1)True
(2)False
Answer : 2
Explanation : PREVIOUSLY: If a class declares a class method classFinalize that takes no arguments and returns no result: static void classFinalize() throws Throwable { . . . } then this method will be invoked before the class is unloaded . Like thefinalize method for objects, this method will be automatically invoked only once. This method may optionally be declared private, protected, or public. NOW: Class finalization has been removed from the Java language. Thefunctionality of JLS 12.7 is subsumed by instance finalization (JLS 12.6).Here is a rationale for this decision. http://java.sun.com/docs/books/jls/class-finalization-rationale.htmlSimilar thing has happend toclass unloading: A class or interface may be unloaded if and only if its class loader is unreachable (the definition of unreachable is given in JLS 12.6.1). Classes loaded by
the bootstrap loader may not be unloaded

Question: what is meant by class finalization and instance finalization.
[ May 09, 2008: Message edited by: Jesper Young ]
src:
http://technoheads.blogspot.com/
class test
{
public static void main(String[] args)
{
test inst_test = new test();
int i1 = 2000;
int i2 = 2000;
int i3 = 2;
int i4 = 2;
Integer Ithree = new Integer(2); // 1
Integer Ifour = new Integer(2); // 2
System.out.println( Ithree == Ifour );
inst_test.method( i3 , i4 );
inst_test.method( i1 , i2 );

}
public void method( Integer i , Integer eye )
{
System.out.println(i == eye );
}
}

a. true false true
b. false true false
c. false false false
d. true true false
e. Compile error

Answer 2:
b: false true false. lthree and lfour are two seperate objects. if the lines 1 and 2 were
lthree = 2 and lfour = 2 the result would have been true. This is when the objects are created in the pool. When the references I and eye in the pool are compared 2==2 results in true and 2000==2000 is false since it exceeds 127.
--

I do not understand--When the references I and eye in the pool are compared 2==2 results in true and 2000==2000 is false since it exceeds 127.
[ May 09, 2008: Message edited by: Jesper Young ]
Src:http://devesh2k1.googlepages.com/home

How many objects will be eligible for GC just after the method returns?
public void compute(Object p)
{
Object a = new Object();
int x = 100;
String str = "abc";
}
Answer: 1
Explanation: Objects passed to the method are never garbage collected in (or right after) that method. So p cannot be GCed. x is not an object. "abc" is a string literal which goes to the string pool and is not GCed. So, only a is eligible for GC.
-----------

what about the String. Str is also garbage collected, so answer should be 2.
[ May 09, 2008: Message edited by: Jesper Young ]
Hi,

I would like to sell scjp voucher with 2 retake exam expiring 06/22/08 valid only in US. If anyone interested please reply to post

Vidya
[ May 14, 2008: Message edited by: Vidya Singh ]
14 years ago
from k&b, Given:

public class Letters extends Thread {
private String name;
public Letters(String name) {
this.name = name;
}

public void write () {
System.out.print(name);
System.out.print(name);
}
public static void main(String[] args) {
new Letters("X").start();
new Letters("Y").start();
}
}

We want to guarantee that the output can be either XXYY or YYXX, but never XYXY or any other combination. Which of the following method definitions could be added to the Letters class to make this guarantee? (Choose all that apply.)

public void run() { write(); }

public synchronized void run() { write(); }

public static synchronized void run() { write(); }

public void run() { synchronized(this) { write(); } }

public void run() { synchronized(Letters.class) { write(); } }

public void run () { synchronized (System.out) { write (); } }

public void run() { synchronized(System.out.class) { write(); } }

Ans is:
public void run() { synchronized(Letters.class) { write(); } }
public void run () { synchronized (System.out) { write (); } }

I would like to know why answer cannot include
public static synchronized void run() { write(); }
public void run() { synchronized(this) { write(); } }

I guess, public static synchronized void run() is not correct as we do not have static variable in the class, not sure though.
Any explanation appreciated.
Thanks. I guess i got confused.
src: www.javablackbelt.com

public class test {
public static void main(String[] arg) {
Long val = 4444444L;

if (val > 10) {
System.out.println(">10");
} else {
System.out.println("not sure");
}
}
}

Choices:
>10
not sure
Compilation error at line 3
Compilation error at line 4
None of the above

Ans: >10

I thought answer should be "not sure", as 4444444L would be greater than 10.Please suggest.
source: Voodoo Exam
Question :
What is the value of

~ Integer.MAX_VALUE

Options :

a . 1
b . 0
c . - 1
d . Integer.MIN_VALUE

the answer is d (using Some binary math -)

i would like to know how. also what would be value for Integer.MAX_VALUE
and Integer.MIN_VALUE. Also, is it platform dependent

Thanks,
Vidya
The answer b is incorrect, as it gives error "you cannot make static reference to the non static feild main".
I guess the answer is there is no problem with code (though it is not printing anything).