• Post Reply Bookmark Topic Watch Topic
  • New Topic

Queues in java  RSS feed

 
yogesh singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please, help me rectify the errors in the following program:
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yogesh. Welcome to the Ranch!

For a start, then, you're going to have to tell us what the errors are. In detail.
 
yogesh singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ExamImmutableQueueImpl.java 5 class ExamImmutableQueue is public, should be declared in a file named ExamImmutableQueue.java
Error ExamImmutableQueueImpl.java 28 incompatible types
Error ExamImmutableQueueImpl.java 35 incompatible types
Error ExamPeekableQueueImpl.java 7 class ExamPeekableQueue is public, should be declared in a file named ExamPeekableQueue.java
Error ExamPeekableQueueImpl.java 16 ExamPeekableQueueImpl is not abstract and does not override abstract method peekMinimum() in ExamPeekableQueue
Error found java.util.LinkedList
Error found java.util.LinkedList
Error required ExamImmutableQueue
Error required ExamImmutableQueue

well these are the errors on compiling the code.
 
Ankit Dan
Ranch Hand
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yogesh singh wrote:ExamImmutableQueueImpl.java 5 class ExamImmutableQueue is public, should be declared in a file named ExamImmutableQueue.java
Error ExamImmutableQueueImpl.java 28 incompatible types
Error ExamImmutableQueueImpl.java 35 incompatible types
Error ExamPeekableQueueImpl.java 7 class ExamPeekableQueue is public, should be declared in a file named ExamPeekableQueue.java
Error ExamPeekableQueueImpl.java 16 ExamPeekableQueueImpl is not abstract and does not override abstract method peekMinimum() in ExamPeekableQueue
Error found java.util.LinkedList
Error found java.util.LinkedList
Error required ExamImmutableQueue
Error required ExamImmutableQueue

well these are the errors on compiling the code.



the very first the filename and the public class should be same...in your case your filename is ExamImmutableQueueImpl.java but your interface ExamImmutableQueue is public and it is not allowed
as only one public class is allowed per source file..
hope this helps
Ankit
 
yogesh singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Dan wrote:
yogesh singh wrote:ExamImmutableQueueImpl.java 5 class ExamImmutableQueue is public, should be declared in a file named ExamImmutableQueue.java
Error ExamImmutableQueueImpl.java 28 incompatible types
Error ExamImmutableQueueImpl.java 35 incompatible types
Error ExamPeekableQueueImpl.java 7 class ExamPeekableQueue is public, should be declared in a file named ExamPeekableQueue.java
Error ExamPeekableQueueImpl.java 16 ExamPeekableQueueImpl is not abstract and does not override abstract method peekMinimum() in ExamPeekableQueue
Error found java.util.LinkedList
Error found java.util.LinkedList
Error required ExamImmutableQueue
Error required ExamImmutableQueue

well these are the errors on compiling the code.



the very first the filename and the public class should be same...in your case your filename is ExamImmutableQueueImpl.java but your interface ExamImmutableQueue is public and it is not allowed
as only one public class is allowed per source file..
hope this helps
Ankit


updated my code accordingly, still the error persists,
ExamPeekableQueueImpl.java 7 class ExamPeekableQueue is public, should be declared in a file named ExamPeekableQueue.java

where ExamPeekableQueue is not a class its the interface
 
yogesh singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please ignore the earlier message, there was some mistake in that one.
 
Ankit Dan
Ranch Hand
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where ExamPeekableQueue is not a class its the interface

but the compiler treats it as a class you can make out from the compiler error:
class ExamImmutableQueue is public, should be declared in a file named ExamImmutableQueue.java



From section 7.6 of the JLS:

When packages are stored in a file system (§7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:

>The type is referred to by code in other compilation units of the package in which the type is declared.
>The type is declared public (and therefore is potentially accessible from code in other packages).

This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.



so whether it is interface or class...only one public i hope you got this one

there are few more errors i suppose other than this one..please post them after rectifying this error..

Happy to help
Ankit
 
yogesh singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Dan wrote:
where ExamPeekableQueue is not a class its the interface

but the compiler treats it as a class you can make out from the compiler error:
class ExamImmutableQueue is public, should be declared in a file named ExamImmutableQueue.java



From section 7.6 of the JLS:

When packages are stored in a file system (§7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:

>The type is referred to by code in other compilation units of the package in which the type is declared.
>The type is declared public (and therefore is potentially accessible from code in other packages).

This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.



so whether it is interface or class...only one public i hope you got this one

there are few more errors i suppose other than this one..please post them after rectifying this error..

Happy to help
Ankit


yes, done with all the errors,
can you please help me to add elements to my queue in the program?
 
Ankit Dan
Ranch Hand
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it out and if you dont get anything .....
try again
try again
final step : help from others

Happy to help
Ankit
 
yogesh singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Dan wrote:Try it out and if you dont get anything .....
try again
try again
final step : help from others

Happy to help
Ankit

done thank you for the help guys.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!