Rajat Asani

Greenhorn
+ Follow
since Mar 26, 2008
Merit badge: grant badges
For More
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 Rajat Asani

Yes I think you are right.
Only then the answer given makes sense.

Source--Sun microsystems learningConnection

Question---At line 12 how many objects are elegible for garbage collection.

Answer give--1

My answer----3 ie all the objects.
Since the main method ends at line 12, shouldn't all the objects be eligible for garbage collection??
Not even one. Thats why this concept of time lag in flushing was a surprise for me. So i thought i should confirm. Please don't get me wrong, am just preparing for the worse.
Got it....Thanks.

But does this mean that this can happen in execution of normal programs where no threads are involved?
If so then do we need to be on a lookout for this time lag in streams being flushed to different methods when determining the output of questions in the exam?


My questions is the how come i got this sequence as output in my program??

I am aware that the output of threads cannot be determined because of thread scheduler. Also I know that the Main and the "Rajat" thread will run independently. But in this case the execution flow in the run methods would be sequential. ie. the exception would always be thrown after the println statement printing "start". Then how come i see "start" printed after the exception.
Hi Sun,

For your first doubt

A PriorityQueue's elements are ordered either by natural ordering (in which case the elements that are sorted first will be accessed first) or according to a Comparator


Priority queue stores elements in a sorted order. This ordering could be in one of the two forms:-
1.Natural ordering
2.Using Comparator(ie Implementing the comparator interface and having our own custom sort.)

For your second doubt on how the code compiles:-
For priorityQueues we use the following three methods:-
1.offer()-To add elements to the queue
2.peek()-To get the highest priority element
3.poll()-To get the highest priority element and remove it from the queue.
A modified version of your code is given below:-


Hope this helps
Got it, compiles fine with the modification...Thanks. So i guess once we get the iterator, there is no link with the generic list, we need to use generics on the iterator.
Yes, exactly my point, why does this need a cast and the code in LINE 1 doesn't???
[ April 16, 2008: Message edited by: Rajat Asani ]


It says when using generics, implicit casting is done. However in the example above, I get a compiler error on LINE 2, saying cannot convert object to int. Is it that the iterators do not make use of generics and implicit casting as in LINE 1.
thanks Marc...would definitely keep that in mind.
Hi Dinesh,

The execution flow is quite simple here. The while condition executes till x=11.
So when x=11 it does x++<11 and exits the loop. The increment is applied immediately in the next statement.

For such questions to check the execution flow, I always use a debug mode in ECLIPSE to know which statement has what effect. Do try it out, its really useful.
I believe sridhar is correct. Guess everyone just ignored the "System.out.println" in the else part of the program.

If we replace this by simple "sc.next()"....the output would match the one given.

But in the end I think the real question was understood and explained well.
Thanks guys,

Dont know why but the point doesnt strike when required

Anyways can you please tell me, where can i find a list of exceptions(checked/unchecked) that we must know about for the exam.
SOURCE :: http://www.valoxo.ch/jr/mocks/mock01a.html
(Link from javaranch only)



Doubts:
1.Why does this give an error --- "Unreacheable catch block for IOException. This Exception is never thrown from the try statement."
2.Why does it compile if I change the IOException in catch to ArithmeticException or just plain Exception or any other exception.
3.Is there some special functionality or feature of IOException that I am not aware of.
[ April 10, 2008: Message edited by: Rajat Asani ]
Hi,
Because of the following code we come to know that lList in class B is pointing to same list object on heap:-



This returns the reference of the List on heap and assigns it to lList in class B