Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compile empty file 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 "Compile empty file" Watch "Compile empty file" New topic

Compile empty file

Gaurav Pavan Kumar Jain
Ranch Hand

Joined: Mar 19, 2007
Posts: 168
Hi all

I created a blank file and save it as When I compile it it compile successfully no error occur. I write nothing In that fie.

Please let me know how compiler treat such files.
sadasiva kumar
Ranch Hand

Joined: Oct 30, 2003
Posts: 91 compiles without any errors.But when we run application ,it ll not execute.You ll get Runtime error.
Exception in thread "main" java.lang.NoClassDefFoundError:First


A bend in the road is not the end of the road ... unless you fail to make the turn.
JB Ramesh

Joined: Jan 09, 2007
Posts: 20
I also want to know why empty file is allowed by compiler. Anyway while runnning it will give runtime error.

And that file can not be referred as an object also. Then why java creaters allow the empty file ? The compiler can ignore it right ?

Is there any technical funda behind this ??
[ March 20, 2007: Message edited by: JB Ramesh ]
Andy Morris
Ranch Hand

Joined: May 30, 2004
Posts: 78
So when you say it compiles successfully you're saying it produces a .class file?

I'd be very suprised if it did. The runtime exception you're getting isn't because it's running an 'empty' class file, it's because the class file doesn't exist.

I doubt anyone here can tell you why the designers of Java decided not to warn you (or abort compilation) if it finds an empty .java file. My only thoughts are that an empty java file has no negative impact, so why bother failing compilation over it? I'd have thought a compiler warning would be useful though.
I agree. Here's the link:
subject: Compile empty file
It's not a secret anymore!