This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question re: Eclipses class wizard" Watch "Question re: Eclipses class wizard" New topic

Question re: Eclipses class wizard

Mark Toddd

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 '' in Eclipses main window and then use the class wizard to generate a new class for my '' 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.


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

Joined: Jul 08, 2003
Posts: 24183

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

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

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

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

Joined: Oct 13, 2005
Posts: 37923
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.
I agree. Here's the link:
subject: Question re: Eclipses class wizard
Similar Threads
How to use JUnit with Eclipse ?
eclipse plugin development
How do i compile and run a java program in JBuilder
compile error using ant in eclipse
name of java file