Sanjeev Gupta

Greenhorn
+ Follow
since Mar 08, 2001
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 Sanjeev Gupta

Can anybody suggest as to which is the best book for each of these topics?
Thanks.
Could somebody, who has used JWhiz give his experience with the JWhiz mocks and are they really helpful vis-a-vis the free mocks available on the net?
Thanks Seema, I somehow overlooked the 'return'. The eyes have to be really open!
Given the following code :
import java.io.*;
import java.net.*;

public class Base{

private void test() {

try {
String a = null;
String b = "b";
// Complex processing

if(a==null)
throw new MalformedURLException("test");
if(b ==null)
throw new EOFException("test");
// Complex processing

System.out.println("End of try block");

}
catch (MalformedURLException e) {
System.out.println("Caught MalformedURLException");
return;
}
catch (EOFException e) {
System.out.println("Caught EOFException");
return;
}
finally {
System.out.println("End finally");
}
System.out.println("End processing");
}

static public void main(String[] a) {
new Base().test();
}

}
Could somebody explain why "End Processing" is not printed out?
Thanks.
Thanks Nitin and Jane, that clarifies!
Well, chapter 4 of 'Thinking in Java' clearly states that the garbage collector works only for objects created with 'new'. But Ravindra seems to be confident about his explanation. I do not have Khalid's book. I would request one of the moderators to step in and clear the things (or should I say, the 'garbage')!
Hi Sona,
All variables are referring to string literals. As string literals are not garbage collected, all options are incorrect.
If there were an object created with the 'new' operator, that would have been garbage collected.
The question is from Khalid's free mock exam . It does not explain any answers.
Which operators will always evaluate all operands?
a) | |
b) +
c) &&
d) %
e) ?:
The correct answer given is 'b' and 'd'. According to me 'e' should also be correct. Somebody please throw some light on this.
Thanks tvs, that was helpful.
Which is the earliest line in the following code after which the object created on the line marked (0) will be a candidate for being garbage collected, assuming no compiler optimizations are done?
public class Q76a9 {
static String f() {
String a = "hello";
String b = "bye"; // (0)
String c = b + "!"; // (1)
String d = b;
b = a; // (2)
d = a; // (3)
return c; // (4)
}
public static void main(String args[]) {
String msg = f();
System.out.println(msg); // (5)
}
}
a) The line marked (1)
b) The line marked (2)
c) The line marked (3)
d) The line marked (4)
e) The line marked (5)
Hi Nitin,
Could you please tell me your source of definition of '&&'?
[This message has been edited by Sanjeev Gupta (edited March 31, 2001).]
The short circuit operators work as follows:
1. In case of '&&', if the first expression is true, then only the second expression is checked. This is because in an 'AND'logical operation, both expressions have to be true for the result to be true. If the first expression were false, the compiler knows that the result cannot be true. Therefore, it 'shortcircuits' the second expression and does not evaluate it.
2. In case of '| |', ... well I think you now know it.
[This message has been edited by Sanjeev Gupta (edited March 31, 2001).]
When the Derived22 object, d, is created, the following sequence takes place:
1. Instance variables in the Base22 class and those in the Derived22 class are initialised to their default values(x,y, and z are initialised to 0).
2. The Base22 class constructor is called. This calls the init() function. Since the object 'this' is now of the Derived22 class, its init() method is called.
3. Inside the init() method, the values are assigned which are :- y = 4, z = 5.
4. Once the Base22 class initialisation has been done, the Derived22 class initialisation is started.
5. In this process, any explicit assignments done to the instance variables is carried out. As z has been assigned 3, this is carried out. But y has not been given any explicit value. It therefore keeps its earlier value of 4. That's how
you get the result.
This means that references to a member inner class, like any member variable, can occur before the definition of the inner class in the program. However, the same is not true for local inner classes(local inner classes, like local variables, are those that are defined inside a method).
General rules for object construction (in the order of implementation) may be summarised as follows:
1. Static variables in the super class are initialised.
2. Static variables in the child class are initialised.
3. Instance variables in the super class are initialised.
4. Super class constructor(s) are executed.
5. Instance variables in the child class are initialised.
6. Child class constructors are executed.
Note - Static variable initialisation is done only once, when the class is loaded. Instance variable initialisation is done each time an object is created.
You may work your way out with the help of above rules - it is easy. Since there are no static variables, lines 1 & 2 do not apply in this particular case.