Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java Newsletters Archive: 166

JavaFAQ Home » Java Newsletters Go to all tips in Java Newsletters

Bookmark and Share

=== [ The Java FAQ Daily Tips, weekly publication ] ===

Issue No: 166 3 June 2003
13103 subscribers

Foreword: Excuse me for possible mistakes. English is not native language for me.

In this issue:
  • 1. When do I to choose an abstract class over an interface?
  • 2. What is difference between Hashmap and Hashtable?
  • 3. My colleague, he is testing my code, got "Headless Exception".
  • 4. Latest posts on our message board
  • 5. Link to Java FAQ

  • Hello dear friends!

    Tip 1

    Question: When do I to choose an abstract class over an interface?

    Answer: Choosing interfaces and abstract classes is not an either/or proposition...

    "Often in a design, you want the base class to present only an interface for its derived classes. That is, you don't want anyone to actually create an object of the base class, only to upcast to it so that its interface can be used. This is accomplished by making that class abstract using the abstract keyword. If anyone tries to make an object of an abstract class, the compiler prevents them. This is a tool to enforce a particular design.

    You can also use the abstract keyword to describe a method that hasn't been implemented yet-as a stub indicating "here is an interface function for all types inherited from this class, but at this point I don't have any implementation for it." An abstract method may be created only inside an abstract class. When the class is inherited, that method must be implemented, or the inheriting class becomes abstract as well. Creating an abstract method allows you to put a method in an interface without being forced to provide a possibly meaningless body of code for that method.

    The interface keyword takes the concept of an abstract class one step further by preventing any function definitions at all. The interface is a very handy and commonly used tool, as it provides the perfect separation of interface and implementation. In addition, you can combine many interfaces together, if you wish, whereas inheriting from multiple regular classes or abstract classes is not possible."

    from "Thinking in Java", http://javafaq.nu/java/book/Chapter01.shtml#Heading29


    Java wimps please close your ears ... For the Java programmer who
    thought he knew everything there was to know about Java, have a
    look at the most advanced Java newsletter archived on the website
    http://www.smotricz.com/kabutz Guess what, it won't even cost you
    anything! Subscribe today - you won't be disappointed.

    Tip 2

    Question: What is difference between Hashmap and Hashtable?

    Answer: there is almost no difference, since "hashmap is Hash table based implementation of the Map interface" (citation from API). The difference is that Hashtable is synchronized.


    Tip 3

    Question: My colleague, he is testing my code, got "Headless Exception". He jokes that is thrown by code which is written by headless people Smile He has shown me log file even. Is he joking with me?

    Answer: Probably not Smile I mean that you are Ok although this exception exists in reality.

    It is thrown when code that is dependent on hardware like keyboard, display, or mouse is called in an environment that does not support a keyboard, display, or mouse. For example, all modern servers have no display, keyboard and mouse.


    Latest posts on our message board


    I have developed this little program that illustrates the problem that is similar to a different one I am making. I wonder how you make the first method run through completely then go onto paint(g) which runs through the second. As of now, all three: down,first, and second appear simultaneously.

    // The "Threads" class.
    import java.applet.*;
    import java.awt.*;

    public class Threads extends Applet
    continues here

    Class question

    My question is simple:

    I have a Frame (Frame1) with a textfield component on it and a jbutton and
    another Frame (Frame2). When i push a jbutton on Frame1, Frame2 appears. All
    well so long. The problem is here: I have another textfield (editable) on
    Frame2 and a jbutton. I want to get the text of textfield on Frame2 when i
    push the button and have the text BACK ON FRAME 1.

    I have a .java file for each Frame: Frame1.java and Frame2.java. I 'm
    creating an object like this on Frame2.java:
    Frame1 obj=new Frame1();
    and i get Frame1's methods with obj.
    All seem good, i'm getting no error message, but it doesn't work.

    As you may have understood i'm a little bit rookie so any help would be appreciatable. I' m working on Borland JBuilder 8

    Thanks in advance.
    continues here

    GUI - refresh ..it will not end

    Hi there

    Since a very long time I'm stuck in the same problem again & again...

    I'm using swings JFrame where I add an instance of a Class that extends JLabel. I've overridden the paintComponent(Graphics g)-method where I do the whole draw-stuff and finally call super.paintComponent(g).

    Problem: The content of the frame does not refresh, until the window is resized etc.


    private JFrame myFrame = new JFrame();
    continues here

    MS-Java emulation on Java 2?


    There is an old avatar chat applet (example: http://eagles.chatserve.com/ip.html) called InstantPalace. The applet works great, but it's pretty old, and only runs on the MS-Java and older "Java 1" JREs. So users who have upgraded to Java 2 JREs can't use it. The Applet was created by a company that is no longer in business, so chances of it ever being updated for Java 2 compatibility are, unfortunately, not very good.

    I was wondering if there was a way to emulate MS-Java inside of a Java 2 applet, so older Java2-incompatible applets such as this one could be used on systems with Java 2.
    continues here

    centering applet on screen

    I have an applet that I want to position in the top center of my screen,
    When I run the applet in the applet viewer it shows up in the top left corner of my screen, Dose anyone have any ideas on how I can fix this, this is the html code I am using. I also tried using a center method in this code, but then my applet didn`t appear on the screen. Any help wopuld be greatly appreciated.

     Printer Friendly Page  Printer Friendly Page
     Send to a Friend  Send to a Friend

    .. Bookmark and Share

    Search here again if you need more info!
    Custom Search

    Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

    RSS feed Java FAQ RSS feed Java FAQ News     

        RSS feed Java Forums RSS feed Java Forums

    All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

    Interactive software released under GNU GPL, Code Credits, Privacy Policy