Lovleen Gupta

Ranch Hand
+ Follow
since Feb 26, 2007
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lovleen Gupta

Originally posted by Steven Young:
Option 4 is the only one that adds an Object. All other options are adding a primitive integer. Collections can only have objects, so primitives need to be wrapped in an object,

Right..But due to autoboxing feature in SCJP 5.0 .. will option 3 not be valid as well?
Which of the following will successfully create an instance of the Vector class and add an element?

1) Vector v=new Vector(99);

2) Vector v=new Vector();

3) Vector v=new Vector();

4 Vector v=new Vector(100);

Why is the answer to this is option (4) and not option (3)?

Please help.
Whats the difference between runtime error and compile time error?
Is runtime error and exception and the same thing?

Please clarify.


Originally posted by Chandra Bhatt:
Hi Guptajee,

Suppose,if exception is thrown, you want to make return statement,
and no other statement execution of the method to proceed. But finally
will execute for sure unless you write System.exit(1) or something that
terminates the program. Suppose you dont write "return -1;" in your catch
clause, even after exception comes, a line that may outside of the try catch
clause will execute and may yield undesirable result. So you wrote "return -1" there.

Got it?


So, in this program, why is -1 printed and not 0?
Please explain.

[ April 12, 2007: Message edited by: Lovleen Gupta ]
Whats the use of having a return statement in a catch or finally block?
Basically, how does the rpogram flow, once it encounters a return statement?
For exp, in the program below, what will be the output if "Hello.txt" doesn't exist:

All rightie..
Thanks Souren.

Originally posted by Sourin K. Sen:
Just think about it. What's the purpose of a static import ? To import the static members of a particular class.

When you write you are telling the compiler that you want to import all the static members of Integer class so that you can call them directly without having to write "Integer." infront of them.

But when you try to write you are actually telling the compiler to import a static top level class & if you remember, top level classes can never be static which means that you cannot ever import a top level class which is static. But by writing the preceding you are trying to do just that & hence the compiler wont allow you to do so.


All right, Sourin..Got your point..
But why does it then work in case of import static System.out?
rigth you are..its working..
but my question is why will it not work if we do import static java.lang.Integer instead of java.lang.Integer.* ?


In this program -- they are importing static System.out and using only out.println..
Also, they are importing static Integer.* and using MAX_VALUE..
However, if we import staic Integer and use Integer.MAX_VALUE..why does it not work??
Please explain.

Here is the code:

The output, I think, should be "Trying to Notify" and "Notified" with no certainity of the order in which they will appear.

However, the output is only "Trying to Notify".
Please explain why so?

Thanks Chandra..Got it..
Also, if we remove "static" from the variables..it works..
Here is the modified code:

Please explain - At what time deos the compiler know that y exists?
Also, Chandra - according to the explanation you gave (2nd code you wrote) -- this shouldn't work..??

In this code here, the output is 0. Reason being y is not known when x was initialized.
But, my question is -- I agree, y is not known at that time. But why is it not showing compiler error.. since, y is both declared and initialized after x?
Also, can somebody please explain the correct flow of the program?

Thanks All.
Got it now..
Why is a method having void return type not allowed to be used as an assert expression?


P.S.: Also, I didn't see any mention of it while reading on assertion in K&B. Am getting to know about it from mocks only. Did the authors touch on this in the book?