• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compile empty file

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic