wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes First valid statement in a java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "First valid statement in a java class" Watch "First valid statement in a java class" New topic
Author

First valid statement in a java class

Kareem Qureshi
Ranch Hand

Joined: Mar 14, 2002
Posts: 102
Hi,
I went through a test by Jaworski,
It says that
If a package statement is included in a source file then it must appear as first non blank line.
I think this is not correct
Please advice
Thanks in advance
Kareem
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
There is no such requirements stated in the JLS.
The only requirement is that the package statement (0 or 1 per compilation unit) must precede all import statements (zero or more) which in turn must precede the following class and/or interface declarations (zero or more).
It is perfectly allowed to have blank lines and/or comments before the package statement. There are numerous examples out there proving this point (just start with Sun's classes).
One more point, an empty file will compile and is a valid Java source file.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Kareem Qureshi
Ranch Hand

Joined: Mar 14, 2002
Posts: 102
Thanks i was sure of the answer but you know i am scheduled to take the exam two weeks from now and presently taking all the tests available on net. So that is why i am posting mistakes or things which i think are mistakes. so that i will not make that mistake ever again.
Kindly bear with me because my aim is to get 100%(pretty ambitious but achievable with your help)
of course the last exam i would take before the final exam is Valentin's mock test.
Thanks
Kareem
Radha Krishna
Greenhorn

Joined: Mar 18, 2002
Posts: 3
Hi Kareem
You can write package statement in the class after spaces or comments, but import statements and class declaration after package statement only
wish you all the best
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: First valid statement in a java class