How many classes should a .java file contain?

Are there any general guidelines on how many Java classes should be contained in a single .java file? I've been creating a new .java file for each class I write but see examples in Sun's Java tutorial where there are at least two classes in a single .java file. One such case is the TableDemo example at
http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/TableDemo.java
Thanks.

The example you point to isn't really more the one class in one java file. It makes use of an inner class. An inner class is something different! As far as I understand it, it is mainly used to implement some behaviour (in this case AbstractTableModel behaviour). If the MyTableModel was in a separate class file, it couldn't access the variable of the main TableDemo class. So they use an inner class.
So unless you need inner classes, this example is no reason to put more than one class in a .java file. In general, just put one class in a .java file. It's easier for everybody.

Similar Messages

  • If you have two public class in a java file what will be the error ?

    Q:If you have two public class in a java file what will be the error and how will you remove that.?

    Kannan_S wrote:
    I dont want you to be on that list . Here goes my explanation..
    A class is well defined with members and functions
    An abstract class is not defined well as compared to a full fledged class (talking more generically)
    An interface is more abstract.
    I was asking the author who has posted this question to be like a class(very clear)
    and not either as an abstract class or an interface
    Hope i have made it clear..Not in the slightest. This has absolutely no bearing whatsoever on the question asked. Not to mention that classes are classes, and all equal in the eyes of the compiler, be they abstract, concrete or interfaces. It's difficult to see what your point is, to be honest, but I suspect it wouldn't be worth seeing anyway

  • I have been requested the certificate for iOS development since 4 days ago, but the result is still pending approval. So how many days should i wait?

    i have been requested the certificate for IOS Development since 4 days ago, but the result is still pending approval. So how many days should i wait?

    1. You did not get an error message telling you that your iPhoto library was getting full. You got a message telling you that your HD was getting full, right?
    OS X needs about 10 gigs of hard drive space for normal OS operations - things like virtual memory, temporary files and so on.
    Without this space your Mac will slow down as the OS hunts for space on the disk, files will be fragmented, also slowing things down, apps will crash and the risk of data corruption - that is damage to your files, photos, music - increases exponentially.
    Your first priority is to make more space on that HD. Nothing else can be done until you do.
    Purchase an external HD and move your Photos and Music to it. Both iPhoto and iTunes can run perfectly well with the Library on an external disk.
    Your Library has been damaged from being run on an overfull disk.
    How much free space on it now?

  • How many song should i get on the 2gb ipod shguffle 4th generation

    How many songs should I get on the 2gb I Pod Shuffle 4th generation

    Hello Maureen,
    The number of songs will vary based on the length of each song and how large the file is, but on average 2 GB will hold approximately 500 songs. 
    I found this information in the following link (the title of this article says 2nd generation iPod shuffle, but the number of songs in 2 GB is the same for the 4th generation as well):
    iPod shuffle (2nd generation) - Technical Specifications
    http://support.apple.com/kb/sp27
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • How do you run another Java file from a master Java file?

    We're making a game in Java at school, and we need to know how we can run a Java file from another one - like inside the master Java file, we need to have a command to run game.java (something like that). Thanks!

    We're making a game in Java at school, and we need to know how we can run a Java file from another one - like inside the master Java file, we need to have a command to run game.java (something like that). Thanks!One doesn't "run a Java file", and there's no conventional definition of "master Java file". If you want to call the main() method of another class, just make sure the class is in your classpath and call the method. If you want to start up a separate JVM with that class as a process, use Runtime.exec() or similar method.
    ~

  • How many times should I run the APPLE TEST HARDRIVE/DRIVE on my macbook?

    how many times should I run the APPLE TEST HARDRIVE/DRIVE on my macbook?

    Do you mean your hardware tester or Disk Utility?
    -Bmer
    Mac Owners Support Group - Join us @ MacOSG.com
      Mac611 Mobile Mac Support - about.Mac611.com
       iTunes:MacOSG Podcast | YouTube.MacOSG.com
                       An Apple User Group 
    Have an iPhone or iPod touch? Enter Mac611.com in Safari on it for 'mobile Mac support.'

  • How to test the simple .java file in cactus

    dear friends,
    i have use the junit first time .And i am working in weblogic8.1 so i have use cactus .But i face the problem to use it.
    1. how to test the simple .java file in cactus.
    2.how to run the cactus in weblogic 8.1.

    Hi,
    It is because the converter works on byte code and it only supports a subset of the Java language (see the JC specifications). It is kind of like compiling you code on Java 6 and trying to run it on Java 5. The JCDK outlines the required compiler version.
    Cheers,
    Shane

  • How to compile and run java files on a mac using command line?

    can someone tell me or link me to some article on how to compile and run java files from command line on a mac? I have mac OS X leopard

    What do you mean by "where to put them" ? What do you want to put anywhere ?
    Have you read Peter's comment in brackets ? Perhaps you have a classpath problem ?
    Edited by: Michael_Knight on Aug 31, 2008 4:23 AM

  • How many monte should  a new iPod 5g keeps the charge

    How many minutes should a new
    iPod touch fifth generation should keep the charts

    What is you question? In one place you ay "How many monte should a new iPod 5g kepps it charge" and in another "How many minutes should a new
    iPod touch fifth generation should keep the charts"
    What is the iPod doing during the time period?
    Apple say:
    Music playback time: Up to 40 hours when fully charged
    Video playback time: Up to 8 hours when fully charged
    However, uses report less time.

  • How many frameworks available in Java?

    How many frameworks available in Java? Which are most commonly used?
    Edited by: Passion on Jun 16, 2008 2:50 AM

    the number of available frameworks is a function of time, climbing asymptotically to a number n where n is larger than 0 and probably smaller than infinity.
    The value of n is an unknown, and possibly cannot be known at any time Java is in active use.

  • How many records does SAP object BAPIE1VARKEY contain

    Hi Folks,
    I have just started learning ABAP.
    And i have following queries in mind.
    how many records does SAP object BAPIE1VARKEY contain?
    regards,
    Nithin

    Going on an interview? Going to try to fool a savvy tech manager?  I hope not...  How about you tell me why the answer is not two?

  • How many frames should I cut out each second to get a old film look?

    Hi,
    What is the general rule of thumb (if their is one) of how many frames should be cut every second to achieve a choppy old film look? Or maybe it's not every second? What do you guys do?

    you will get a more realistic look if you chop out frames manually
    dump the playhead arbitrarily on the time line insert a cut nudge the playhead either i or 2 frames on and cut again discard the frames and either leave the black or butt the clips up for a "skip".
    this really doesn't take long to do and is better than a predetermined sequence of chops made by a filter.
    CGM do a free filter for aged film to add the hairs, navel lint, boogers etc . .

  • I have a MacBook Pro 15" mid 2010.  My battery has 326 cycles.  It is not lasting more than 1 hr and a few minutes before needing a charge.  How many cycles should it have?

    I have a MacBook Pro 15" mid 2010 that was purchased in summer of 2010.  My battery has used 326 cyles.  Is this normal for these batteries after two years?  How many cycles should I expect to get out of it before getting a new one?  Also, it only last about 1 hour plus about 30 minutes before needing to be charged again.

    The battery is considered a 'consumable' item by Apple - I know that newer models (not sure about 2010's) are supposed to 'last' to about 1,000 cycle counts. But it all depends on how you've used (or abused) your battery as to how long it's going to last. I've 182 cycles on my 8 month old MBP and my battery 'health' is at 98%: I can still get a good 6 1/2 hours out of it...
    ...if you want more battery time, you're just going to have to buy a new battery or, if you purchased AppleCare, see if Apple will replace it gratis. I doubt that they will, though...
    Clinton

  • How many ghz should I get if I plan on using my IPAD2 for internet access, email, facebook and games for my children?

    How many ghz should I get if I plan on using my IPad2 for internet access, email, facebook and games for my daughters children?

    Ghz is the CPU speed and that is fixed for each iPad model.
    The GB is the number of Gigabytes of storage.
    I had a 32G iPad1 and filled it up with 5000 songs, 20,000 photos and about 50 apps.  It doesn't sound like you will need anything larger than that.  If you are just talking about a few dozen apps and email, the 16G version should be adequate.

  • How many songs should I expect my IPod 1G to hold?

    How many songs should I be able to load to my IPod shuffle 1G?

    iPod tuchsdoare not formated for a a Mac or PC. 
    You do not have the right/lience to give away music you purchased.
    An iPod can only sync with ene computer. To change syncing computer you have to erase the iPod and then sync to the new computer.

Maybe you are looking for