• 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

Delimiters ";;;;" next to package statement or import statement is leading to compilation error.

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone please explain why multiple delimiters causing compilation error here.


compilation error:
c:\SCJPDemo>javac ATest.java
ATest.java:3: 'class' or 'interface' expected
import java.io.*;;;;
^

---------------------------------------------------------


compiles without any error:
--------------------------------



compiles without any error:
--------------------------------


compilation error:
c:\SCJPDemo>javac ATest.java
ATest.java:4: 'class' or 'interface' expected
import java.util.*;;;;
^

I understand the below scenarios:
1) If there are multiple delimiters next to package statement and also any import statement exists -> compilation error
2) If there are multiple delimiters next to package statement and there is NO import statement -> NO compilation error
3) If there are multiple delimiters next to import statements and there exists another import statement next to it -> compilation error
4) If there are multiple delimiters next to import statements and there is NO import statement next to it -> NO compilation error

Any inputs??

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

Sridhar Gudipalli wrote:I understand the below scenarios:
1) If there are multiple delimiters next to package statement and also any import statement exists -> compilation error
2) If there are multiple delimiters next to package statement and there is NO import statement -> NO compilation error
3) If there are multiple delimiters next to import statements and there exists another import statement next to it -> compilation error
4) If there are multiple delimiters next to import statements and there is NO import statement next to it -> NO compilation error


yup thata true.
 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any Logical way to remember this ?
 
Ranch Hand
Posts: 78
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really think that on the exam won't be such a question but maybe i'm wrong
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The specification allows ; to appear at same place as top-level class or interface. But not between import and package statements.

So the extra semicolons are allowed only after the last import or package statement (if there is at least one such statement in the file).

A file named Empty.java with the following contents

compiles without errors. (And without creating any class files.)
 
Sridhar Gudipalli
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Vlado for clarification.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic