Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile empty file

 
Gaurav Pavan Kumar Jain
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I created a blank file and save it as First.java 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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First.java compiles without any errors.But when we run First.java application ,it ll not execute.You ll get Runtime error.
Exception in thread "main" java.lang.NoClassDefFoundError:First



regards
SADASIVAKUMAR UTTI
SCJP1.4
 
JB Ramesh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic