• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

A very basic question

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question from javaprepare.com
The question is
A java file without any class or interface declaration can be compiled.(true or false)
I think this is false.But the given answer is true.
Can anybody please explain me?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Create an empty file and name it Empty.java.
compile it.
It compiles ,right?
Jeban
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yogini,
A source file in Java is referred to as a "Compilation Unit". The JLS states in (�7.4) that "a compilation unit consists of three parts each of which is optional":
i. A package declaration.
ii. Import declarations.
iii. Top level type declarations of class and interface types.
Therefore, since all parts of a compilation unit are optional an empty source file(compilation unit) is valid.
Hope this helps,
Bob Kerfoot - SCJP
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bob could u pls. let me know wht is JLS and where is it available?
Thanx in advance.
Anukampa
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anukampa,
JLS is short for the Java Language Specification. You can download or view it directly from http://java.sun.com/docs/books/jls/index.html
Hope that helps.

------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiosity.
-- Dorothy Parker
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
U can declare some import statement and check it out.
it will compile but won't create a class file.
can any one explain me where it is used??
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic