Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, my name is srinath.please let me know that while writing
java programm what is the neccassary to give class name as
file name.
 
Trailboss
Posts: 23459
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this to the forum "Java in General (beginner)"
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So that you'll be able to compile and execute your program. You can have several classes in a source file. Only one top-level class in a source file can be declared public. This class must have the same name as the source file. That's just the way Jave expects it to be.

Bosun
 
Sheriff
Posts: 6959
2
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or to be more precise, that's the way Sun's reference command-line compiler expects it to be. There's nothing in the Java language which ties one public class to one file, that's just a requirement of the compiler. Some systems (IBM Visual Age for example) represent the source code in some sort of internal repository and not in individual files at all.
The main reason for theoriginal command-line compiler requiring one public class per file is to make import and dependency checking acceptably efficient. If every import statement required all possible java source and/or class files to be checked, compilation would be ridiculously slow.
 
reply
    Bookmark Topic Watch Topic
  • New Topic