Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A very basic question

 
Yogini Soundalgekar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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?
 
Jonathan Jeban, Martin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Create an empty file and name it Empty.java.
compile it.
It compiles ,right?
Jeban
 
Bob Kerfoot
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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
 
Anu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob could u pls. let me know wht is JLS and where is it available?
Thanx in advance.
Anukampa
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • 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
 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • 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??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic