File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question re: Eclipses class wizard

 
Mark Toddd
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I'v noticed that Eclipse creates a new tab when you use its class wizard. Which in turn saves the class code in its own .java file.

My question is:

If I'm writing a program called 'hithere.java' in Eclipses main window and then use the class wizard to generate a new class for my 'hithere.java' program Eclipse will open a new tab into which I can put all my classes and methods. Eclipse will also save this new file as a new'.java' file.

Is this standard practice to have a separate file containing classes as well as the main program file?

Or, is it better to write my classes and methods in my main program file?
Or, perhaps Eclipse has a function to combine the two files together (just guessing).

Any help would be much appreciate.

cheers

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, each class should be in its own *.java file. That's not strictly required (not in all cases, anyway), and there are exceptions, but for the most part, what the class wizard is doing for you is the right way to do things.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Public classes belong in new files.

Besides, there wouldn't be much point in a new class wizard if all it did was type "class ${className} {}" in the current window.
 
Mark Toddd
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies

So in general then, I should expect the majority of java applications to have more than one .java file?

And, If so, as long as all the files are located within the same directory unless otherwise directed the program should run right?

Thanks again.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any non-trivial Java application will have multiple Java source files. Some have hundreds, even thousands.

It would be unusual, and confusing, to have "many" files in the same directory--in general (again, for non-trivial applications) the classes are arranged in packages, the layout of which depends on functionality, personal preference, any of many general coding practices, and so on.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will find more about packages here and here in the Java™ Tutorials, and you should have a look at the naming conventions about names and using capital and small letters.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic