Easy to Learn Java: Programming Articles, Examples and Tips

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

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
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"!.

Easy Learn Java: Programming Articles, Examples and Tips - Page 157


Previous 1060 Stories (530 Pages, 2 Per Page) Next

Java Newsletters: Java Newsletters Archive: 166

Go to all tips in Java Newsletters

=== [ 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

    --
    John

    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.

    --
    John


    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.

    --
    John


    Latest posts on our message board

    Threads

    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

    Hi,
    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...

    Situation:
    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.

    Code:

    private JFrame myFrame = new JFrame();
    continues here


    MS-Java emulation on Java 2?

    Hi,

    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

    Hi,
    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.



    comments? | Printer Friendly Page  Send to a Friend | Java Newsletters | Score: 0
    Posted by jalex on Monday, February 02, 2004 (15:56:19) (2802 reads)

    Java Newsletters: Java Newsletters Archive: 165

    Go to all tips in Java Newsletters

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

    Issue No: 165 20 May 2003
    12893 subscribers

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

    In this issue:
  • 1. The beta release of J2SE 1.5 is scheduled for late 2003. I have heard that there will be some changes in a code writing process that will make our life easier...
  • 2. I would like to create a class that can execute jscripts. Does any one know if there is such class?
  • 3. I work with RMI now and need to implement a new feature into software that was written by another people one year ago.
  • 4. Latest posts on our message board
  • 5. Link to Java FAQ

  • Hello dear friends!

    Tip 1

    Question: The beta release of J2SE 1.5 is scheduled for late 2003. I have heard that there will be some changes in a code writing process that will make our life easier...

    Answer: Yes, indeed. The improvements to J2SE being developed in project "Tiger" are intended to make programs clearer, shorter, safer, and easier to develop, without sacrificing compatibility. Java 1.5 will shift the responsibility for writing the boilerplate code from the programmer to the compiler...
    Example:

    Instead of writing
    String title = ((String) words.get(i)).toUppercase();

    you will do like this:

    String title = words.get(i).toUppercase();
    and it will decrease the number of compile errors. Compiler will try to cast to String without saying it explicitly.

    More about all coming changes you can read in this excellent article:
    "New Language Features for Ease of Development in the Java 2 Platform, Standard Edition 1.5: A Conversation with Joshua Bloch" on:
    http://java.sun.com/features/2003/05/bloch_qa.html

    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: I would like to create a class that can execute jscripts. Does any one know if there is such class?

    Answer: Yes, it is Rhino. Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users.
    Be aware that it has some limitations, Rhino is an implementation of the core language only and doesn't contain objects or methods for manipulating HTML documents.

    More read about Rhino here:
    http://www.mozilla.org/rhino/


    Tip 3

    Question: I work with RMI now and need to implement a new feature into software that was written by another people one year ago. I need to find out: what is IP address of a client and then connect or reject the connection. I do not want to add methods to client... It must be the way how to find out it using RMI methods. Unfortunately I did not find with first attempt.

    Answer: Your RMI server extends UnicastRemoteObject that extends java.rmi.server.RemoteServer.
    That class (RemoteServer) has public static String getClientHost() method.
    When called from a thread actively handling a remote method invocation the hostname of the client is returned.

    Then use public static InetAddress getByName(String host) method of java.net.InetAddress
    Be aware that you do need to try to create an instance of InetAddress. It is static.
    Just get it!


    Latest posts on our message board

    Coming Sunday and Saturdays date

    How to get coming sundays date with respect to surrent date taking care of the month change leap year etc.

    thread is here ...


    Window resize

    Here is the scenario:

    I have a window that contains a table in a scrollpane,
    the window itself has a scroll pane, when I try to reduce the size of the window from right to left the scroll apne of the window
    will be displayed.

    What I want is the scrool pane of the table will be the one to resize no the scroll pane of the window

    Anyone can suggest how to prioritize the resizing of scroll pane?

    thread is here...


    Please help, java login script with jdbc:odbc

    Hello

    Could some one please help me,
    i need a small example of a login code. The user and password is located in a Access database and the connection is jdbc dbc

    now i have to make a simple login script that asks the username and password, the username and passwordt have to machts one of the names and passwords from the database, if this name and password are found in the database the user goes to a nother page and send a URL code with it....

    Im looking for this script on the internet but i cant find any example, pleae help
    thread is here...


    EXCEPTION_ACCESS_VIOLATION error with Tomcat server

    I have a query regarding Tomcat server. I am running Tomcat 4.0 server. I have a login html page from where I am entering the valid id and password and submitting the form. As soon as I click on submit button an error occurs saying "An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x77fcab56" and server gets closed. I am not getting how to handle this error. Please tell the solution.

    thread is here...


    GUI - Repaint() - when will it end!!!!

    Hi there, looks like every java guy has to go thru this 1 gui/repaint() issue in life. so i am a member there.

    I have a qtn - like those countless folks out there - new to java and struggling with repaint() which dont seem to work. - can someone help? (thank you in advance).

    Heres the problem

    Have this drawing application with menus and stuff. so i draw box/lines/ circle etc. and when the mouse is released, i add the positions etc to an array, in my paint program, i parse thru the array and show the stuff. Now whatever i draw, doesnt appear immediately (although i have a repaint() (also tried validate, revalidate and every command i have learnt/come across).

    funny thing is, if i press my alt key, the "file" menu option will appear to be selected, when i press escape, the drawing window gets focus and immediately all my drawings appear. So my question, how do i make it do that.

    Additionally (while i am on the roll here) in my menu option i have a File/New when this is selected, i clear the array and do a repaint(). that works beautifully and all the drawing are gone. but if i click on a icon (designated as "new") that wont do anything until i go thru that pressing alt (or switching to another application using alt+tab and then coming back to my paint program).

    Any ideas?

    hoping to hear from someone.

    thread is here


    Input & Output

    how i was wondering how do you input a string from a file line by line which is delimited by (eg one:hello:crap) and is output to GUI ??

    FileReader reader = new FileReader("test.txt");

    BufferedReader in = new BufferedReader(reader);

    String inputLine = in.readLine();
    ......
    full thread is here


    an some one help me wih java sreen tips

    hello can some one tell me how an i create a java screen tip on a hyperlink ...
    i mean when ever some one brings his mouse over a link there should open a window in which there should b the information about the link ...
    thanx

    thread is here


    fail Xrunhprof

    when i run a aplication with Xrunhprof and times option it appears a message in my console.
    "HPROF ERROR: stack underflow in method exit"
    "HPROF ERROR: thread local table NULL in method exit 006A629C"
    Does Somebody know whatґs up?
    thanks

    thread is here...


    Embedding Fonts in Java

    Is there a way to embed fonts in to a java applet??
    If you can answer it would be greatly appreciated
    thread is here ...


    Performance

    Hi,
    I have a problem regarding SunOne Application

    server7.0 installed on solaris5.8.
    I am getting 11000 records in the cached row set. But

    while populating the cached row set

    (crs.populate(resultset)) with the result set the

    server is real slow taking as long as half an hour for

    processing.
    The same thing when run on weblogic6.1 on windows
    ......

    full thread is here ...


    How to disable a JApplet

    Hi guys,In my project,I need to disable my Japplet when browser start it,then after getting some information,I will enable it later;I try to use setEnable(false),but it doesn't work,the components inside my Japplet are still active,How can I do this by one method call or just no way to do it?Thanks

    thread is here ...

    need help

    I simply cannot set my OS to open JAR files with doubleclick. How can I set it to open with java.exe -jar.
    I am using WinXP

    thread is here ...

    Please ask your questions and help each other at our Java Forum:
    http://javafaq.nu/forum/


    The Java FAQ Daily Tips is a newsletter that is only sent to those who have specifically subscribed to it (double opt-in).

    To subscribe/unsubscribe to "The Java FAQ Daily Tips" weekly edition newsletter visit our page here:
    http://www.javafaq.nu/plm2html/my_subscription.shtml

    If you have troubles please contact us: subscription@javafaq.nu


    Link to Java FAQ

    If you have added a link to http://javafaq.nu on your WEB-site, please let us know and you will get listed on our
    "pages linking to us" pages! If your page is a programming is programming relates you will of course get listed in the WEB-directory as well. Also, if you link to us, you have a chance to be listed in this newsletter as well.

    More information and graphics artworks can be found here
    http://javafaq.nu/other/linktous.shtml


    Advertising

    For information on advertising on the Java FAQ's Daily Tips Newsletter, send an email to: adv@javafaq.nu
    You will get the answer immediately from auto responder!


    Send your comments, questions, praise and complaints to us: comments@javafaq.nu

    Copyright (c) 2000 - 2003 John Andersson, All rights reserved.



    1 comment | Printer Friendly Page  Send to a Friend | Java Newsletters | Score: 0
    Posted by jalex on Monday, February 02, 2004 (15:54:38) (4069 reads)

    Previous 1060 Stories (530 Pages, 2 Per Page) Next

    530| 529| 528| 527| 526| 525| 524| 523| 522| 521| 520| 519| 518| 517| 516| 515| 514| 513| 512| 511| 510| 509| 508| 507| 506| 505| 504| 503| 502| 501| 500| 499| 498| 497| 496| 495| 494| 493| 492| 491| 490| 489| 488| 487| 486| 485| 484| 483| 482| 481| 480| 479| 478| 477| 476| 475| 474| 473| 472| 471| 470| 469| 468| 467| 466| 465| 464| 463| 462| 461| 460| 459| 458| 457| 456| 455| 454| 453| 452| 451| 450| 449| 448| 447| 446| 445| 444| 443| 442| 441| 440| 439| 438| 437| 436| 435| 434| 433| 432| 431| 430| 429| 428| 427| 426| 425| 424| 423| 422| 421| 420| 419| 418| 417| 416| 415| 414| 413| 412| 411| 410| 409| 408| 407| 406| 405| 404| 403| 402| 401| 400| 399| 398| 397| 396| 395| 394| 393| 392| 391| 390| 389| 388| 387| 386| 385| 384| 383| 382| 381| 380| 379| 378| 377| 376| 375| 374| 373| 372| 371| 370| 369| 368| 367| 366| 365| 364| 363| 362| 361| 360| 359| 358| 357| 356| 355| 354| 353| 352| 351| 350| 349| 348| 347| 346| 345| 344| 343| 342| 341| 340| 339| 338| 337| 336| 335| 334| 333| 332| 331| 330| 329| 328| 327| 326| 325| 324| 323| 322| 321| 320| 319| 318| 317| 316| 315| 314| 313| 312| 311| 310| 309| 308| 307| 306| 305| 304| 303| 302| 301| 300| 299| 298| 297| 296| 295| 294| 293| 292| 291| 290| 289| 288| 287| 286| 285| 284| 283| 282| 281| 280| 279| 278| 277| 276| 275| 274| 273| 272| 271| 270| 269| 268| 267| 266| 265| 264| 263| 262| 261| 260| 259| 258| 257| 256| 255| 254| 253| 252| 251| 250| 249| 248| 247| 246| 245| 244| 243| 242| 241| 240| 239| 238| 237| 236| 235| 234| 233| 232| 231| 230| 229| 228| 227| 226| 225| 224| 223| 222| 221| 220| 219| 218| 217| 216| 215| 214| 213| 212| 211| 210| 209| 208| 207| 206| 205| 204| 203| 202| 201| 200| 199| 198| 197| 196| 195| 194| 193| 192| 191| 190| 189| 188| 187| 186| 185| 184| 183| 182| 181| 180| 179| 178| 177| 176| 175| 174| 173| 172| 171| 170| 169| 168| 167| 166| 165| 164| 163| 162| 161| 160| 159| 158|
    157
    | 156| 155| 154| 153| 152| 151| 150| 149| 148| 147| 146| 145| 144| 143| 142| 141| 140| 139| 138| 137| 136| 135| 134| 133| 132| 131| 130| 129| 128| 127| 126| 125| 124| 123| 122| 121| 120| 119| 118| 117| 116| 115| 114| 113| 112| 111| 110| 109| 108| 107| 106| 105| 104| 103| 102| 101| 100| 99| 98| 97| 96| 95| 94| 93| 92| 91| 90| 89| 88| 87| 86| 85| 84| 83| 82| 81| 80| 79| 78| 77| 76| 75| 74| 73| 72| 71| 70| 69| 68| 67| 66| 65| 64| 63| 62| 61| 60| 59| 58| 57| 56| 55| 54| 53| 52| 51| 50| 49| 48| 47| 46| 45| 44| 43| 42| 41| 40| 39| 38| 37| 36| 35| 34| 33| 32| 31| 30| 29| 28| 27| 26| 25| 24| 23| 22| 21| 20| 19| 18| 17| 16| 15| 14| 13| 12| 11| 10| 9| 8| 7| 6| 5| 4| 3| 2| 1|


    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