• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PriorityQueue Question

 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I have two question.
(A) Why this program gives comilation warning?
(B) Output
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does the warning message mean to you? Why not tell us the warning message you are getting?

To get the output you can run the program. Please show some effort to find the solution.
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While compilation
without -Xlint:unchecked option to javac
Note: C:\nbworkspace\SCJPKSBB\src\PriorityTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

with -Xlint:unchecked option to javac
C:\nbworkspace\SCJPKSBB\src\PriorityTest.java:21: warning: [unchecked] unchecked call to offer(E) as a member of the raw type java.util.Queue
q.offer(">Java<");
C:\nbworkspace\SCJPKSBB\src\PriorityTest.java:22: warning: [unchecked] unchecked call to offer(E) as a member of the raw type java.util.Queue
q.offer(">java<");
C:\nbworkspace\SCJPKSBB\src\PriorityTest.java:23: warning: [unchecked] unchecked call to offer(E) as a member of the raw type java.util.Queue
q.offer("> Java<");
C:\nbworkspace\SCJPKSBB\src\PriorityTest.java:24: warning: [unchecked] unchecked call to offer(E) as a member of the raw type java.util.Queue
q.offer("> java<");
C:\nbworkspace\SCJPKSBB\src\PriorityTest.java:25: warning: [unchecked] unchecked call to offer(E) as a member of the raw type java.util.Queue
q.offer(">$<");
5 warnings


I got these warnings.

Barry,I know the output but want the Ranchers to have a look and solve.
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't quite understand, did you ask the question because you wanted to know the answer?
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I didn't mean that. I have got the answer for ( B ) but ( A ) is still unanswered.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sanjeev Kumar Singh:
No I didn't mean that. I have got the answer for ( B ) but ( A ) is still unanswered.



Sanjeev,

You have to keep in mind that this site is also for learning. You have to show some effort that you are working towards the solution -- asking what is the output gives the impression that you never ran it yourself.


Anyway, the warning errors are caused by your use of generics. They are only warning errors and you may ignore them if you like... but to learn more, you may try the Sun tutorial on Generics.

Henry
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apart from Sun's tutorial there is also an entry in Angelika Langer's Generic FAQ
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry and Barry,
Thanks for the help.I will try to be more specific towards questioning next time.
[ November 23, 2006: Message edited by: Sanjeev Kumar Singh ]
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a doubt.i coplied the program i got the ouput as

(space)Java
(space)java
$
usually queue will sort it,so i am getting the above 3 output.but
i want to know what happenened to the other two entries
(without space)java and (without space)Java.
please let me know.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by B pandoo:
i have a doubt.i coplied the program i got the ouput as

(space)Java
(space)java
$
usually queue will sort it,so i am getting the above 3 output.but
i want to know what happenened to the other two entries
(without space)java and (without space)Java.
please let me know.



Yes, it's a tricky one - not fair really.

q.poll() removes the element from the queue. So think about the value of q.size() as you execute the loop. How many times does the loop execute if the size is changing.

When you have that sorted out, fix the program so that you get all five elements.
 
Marcus Green
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sanjeev, knowing how to ask a question well is an art in itself. We dont mean to "wag our fingers" at you when we comment on the style of your asking. Don't be put off by our comments, keep posting and asking (and even answering) questions.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

To Sanjeev:
this warning occurs, when you use a generic class without parameterizing it.

To B pandoo:
perhaps try
System.out.println("index i:"+i + " size:"+q.size());
after the line with the poll, and have a look at the output.


Yours,
Bu.
 
B pandoo
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks group.now i am clear
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic