aspose file tools*
The moose likes Beginning Java and the fly likes Question re: Eclipses class wizard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question re: Eclipses class wizard" Watch "Question re: Eclipses class wizard" New topic
Author

Question re: Eclipses class wizard

Mark Toddd
Greenhorn

Joined: Jan 05, 2010
Posts: 11
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


"What you talkin' bout Willis?"
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 05, 2010
Posts: 11
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 13, 2005
Posts: 39885
    
  28
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question re: Eclipses class wizard