ToString() of the Object class. Guide please

Hiya,
I need to ask a question please.
I havent understood the exact meaning of the toString() defined
in the Object class?
When and where do we need to override this?
How can I use this inherited method and see the output
How can I use this method,now overidden and see the output.
Can some please send in a small code...
Regds

"String Representation" doesn't sound like a widget to
me... I haven't tried it, though. Can you provide some
code please, showing how I could use the mechanism you
mentioned?You know.... Widgets!import java.awt.*;
import javax.swing.*;
public class Test3 extends JFrame {
  public Test3() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    MyObject[] myData = {new MyObject("Hello",1),new MyObject("Hi",27)};
    JList jl = new JList(myData);
    jl.setCellRenderer(new Widget());
    content.add(jl, BorderLayout.CENTER);
    setSize(300, 300);
    setVisible(true);
  public static void main(String[] arghs) { new Test3(); }
class Widget extends DefaultListCellRenderer {
  public Component getListCellRendererComponent(JList list, Object value,int index,
                                                boolean selected,boolean focus) {
    JLabel jl = (JLabel)super.getListCellRendererComponent(list,
        value,index,selected,focus);
    jl.setText("("+jl.getText()+")");
    return jl;
class MyObject extends Object {
  String name;
  int num;
  public MyObject(String name, int num) {
    this.name=name;
    this.num=num;
  public String toString() { return name+"-"+num; }
}

Similar Messages

  • Explicitly extending the Object class

    Hi Everyone,
    I am aware that every object that is running inside a JVM inherits from class Object implicitly. Recently I have come across some code that explicitly extends the Object class, is there any advantage in doing this, please see the code snippet below:
    public class MyClass extends Object{}Thanks heaps for your assistance.
    Regards
    Davo

    I've even seen a
    method that was declared "throws NullPointerException"shouldn't it have been "throws java.lang.NullPointerException" ...
    - I almost cried. Yes, thats truly a terrible habit :(
    a distant cousin of that habit is one I have noticed where the developer
    is totally unable to name anything appropriately..
    to print some things to the screen: "loadData"
    to print things to screen again: "getInformation" *(note: did not 'return' anything).
    ... :(

  • How to get the object class field value in CDHDR table for vendor

    hi
    how to get the object class field value in CDHDR table for vendor

    Try KRED/KRED_N as object class in CDHDR for Vendor.

  • About the Object Class

    Why Object is the Base class for the alll the classes in java ?
    Is there any specific reason , can any one explain it in detail ?

    Hi,
    Hmm try to understand OO! OO defines anything in the world to be an object. A description of similar objects is defined as class.
    So number should be an class, plane, people, computer.... When anything is an object, all the objects should have some behaviour in common (all Objects can be put to a List, all Objects can be printed to the screen using toString() and so on). So all Classes need to have a baseclass. This Class is called Object in Java (anything is an Object). Well you should know, that not anything is an Object in Java - int, boolean, char, float, double ... are primitives. So Java is not "real" OO - this is done due to performance reasons. When you want to use primitives as Objects, use a Wrapper Class (Boolean, Char...),
    Lars.

  • The Object Class

    Hi all,
    I come from a C background and am trying to learn JAVA. I was wondering if the type Object was like a void ptr in C.
    example :
    Object oref;

    My C is fairly limited, but from memory a void pointer is just a pointer that is not currently assigned to "point" to anything. This is not the same as an Object type in Java.
    Object is the root class for everything in Java. So if you write your own class, it will automatically extend Object (maybe not immediately, but somewhere in the hierachy a Class will extend from Object).
    Object provides some useful functionality that all classes therefore have, such as toString() and hashCode()
    Normally, when writing Java, you would not decalre something of type Object, as it would usually be some more specific Sub-Class

  • When do we override our own clone method not the Object class clone method

    Hi,
    I have a confusion in overriding clone method.We can create clone object by writing Object.clone() but some times I have seen writing our own clone method ,when do we write this,also clone() is defined protected and when we write our own clone it is said to write it public,why?
    Thanks
    Sumit

    protected methods can only be called in the same class and it subclass. You can make clone protected if this is all you need.
    However if you need to clone() the object from another class, it need to be public.
    This is the same for any method.
    Also as Object.clone() is protected you cannot make it private or package-local (this is true of any protected method)

  • Why is Flash CC not publishing the "object class id" and the !--[if !IE] -- code like CS6 does?

    Here is the HTML I get when I publish with CS6:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
              <head>
                        <title>tooneat_CS6</title>
                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        <style type="text/css" media="screen">
                        html, body { height:100%; background-color: #000000;}
                        body { margin:0; padding:0; overflow:hidden; }
                        #flashContent { width:100%; height:100%; }
                        </style>
              </head>
              <body>
                        <div id="flashContent">
                                  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="2560" height="1160" id="tooneat_CS6" align="middle">
                                            <param name="movie" value="tooneat_CS6.swf" />
                                            <param name="quality" value="best" />
                                            <param name="bgcolor" value="#000000" />
                                            <param name="play" value="true" />
                                            <param name="loop" value="true" />
                                            <param name="wmode" value="window" />
                                            <param name="scale" value="showall" />
                                            <param name="menu" value="false" />
                                            <param name="devicefont" value="false" />
                                            <param name="salign" value="" />
                                            <param name="allowScriptAccess" value="sameDomain" />
                                            <!--[if !IE]>-->
                                            <object type="application/x-shockwave-flash" data="tooneat_CS6.swf" width="2560" height="1160">
                                                      <param name="movie" value="tooneat_CS6.swf" />
                                                      <param name="quality" value="best" />
                                                      <param name="bgcolor" value="#000000" />
                                                      <param name="play" value="true" />
                                                      <param name="loop" value="true" />
                                                      <param name="wmode" value="window" />
                                                      <param name="scale" value="showall" />
                                                      <param name="menu" value="false" />
                                                      <param name="devicefont" value="false" />
                                                      <param name="salign" value="" />
                                                      <param name="allowScriptAccess" value="sameDomain" />
                                            <!--<![endif]-->
                                                      <a href="http://www.adobe.com/go/getflash">
                                                                <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                                                      </a>
                                            <!--[if !IE]>-->
                                            </object>
                                            <!--<![endif]-->
                                  </object>
                        </div>
              </body>
    </html>
    And here is the HTML I get when I publish with CC:
    <!DOCTYPE html>
    <html>
              <head>
                        <meta charset="UTF-8">
                        <title>tooneat</title>
                        <style type="text/css" media="screen">
                        html, body { height:100%; background-color: #000000;}
                        body { margin:0; padding:0; overflow:hidden; }
                        #flashContent { width:100%; height:100%; }
                        </style>
              </head>
              <body>
                        <div id="flashContent">
                                  <object type="application/x-shockwave-flash" data="tooneat.swf" width="2560" height="1160" id="tooneat" style="float: none; vertical-align:middle">
                                            <param name="movie" value="tooneat.swf" />
                                            <param name="quality" value="best" />
                                            <param name="bgcolor" value="#000000" />
                                            <param name="play" value="true" />
                                            <param name="loop" value="true" />
                                            <param name="wmode" value="window" />
                                            <param name="scale" value="showall" />
                                            <param name="menu" value="false" />
                                            <param name="devicefont" value="false" />
                                            <param name="salign" value="" />
                                            <param name="allowScriptAccess" value="sameDomain" />
                                            <a href="http://www.adobe.com/go/getflash">
                                                      <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                                            </a>
                                  </object>
                        </div>
              </body>
    </html>
    Also why are the DOCTYPE html and html tags different? The HTML published by CC is missing all that jazz about W3C....??

    Nested object embeds when used with IE conditionals actually have greater compatibility, but we're stretching the mark back to IE5-8:
    http://www.bobbyvandersluis.com/flashembed/testsuite/
    You can see SWFObject's example communication with callback page utilizes it (view source):
    view-source:http://www.bobbyvandersluis.com/swfobject/testsuite_2_2/test_com2.html

  • Regarding OBJECT class. A question please.

    A question regarding the Object class.
    Please correct me in case I am wrong.
    If I create a class called Foo :
    class Foo{
          Foo(){
    }The constructor of class Foo automatically invokes the constructor
    of its super class.ie it is like saying :
    class Foo{
      Foo(){
        super();
    }Am I Right?
    Even if the Foo class constructor does not include a call to 'super',
    it is implicitly invoked.
    That is the reason the Foo class can invoke/send messages toe methods defined by 'Object',
    as 'super' defined on Foo's constructor constructs/instantiates 'Object'
    Am I Right again ?
    Now,I have just noticed that the Object class does not contain any constructor
    So how can the constructor of Foo call super implicitly if the Object class
    does not contain any constructor.

    So how can the constructor of Foo call superimplicitly if the Object class
    does not contain any constructor.Even if you don't specify one, there will alwaysbe
    at least a no-args c'tor.But if you do specify a ctor with args, the
    compiler will not insert a no-arg ctor for you.That why I said there is "at least" a no-args (or more args) c'tor [in any class].

  • Where is the getString() implementation for RS and Object class question

    Dear all,
    I had these two questions ringing since a long time.
    1)ResultSet is an interface.
    In my jdbc code I have generally written rs.getString() and rs.getInt etc.. without giving a second thought as to where exactly is this getter implemented !
    I have RTF API .. without too much help.
    Could some one kindly explain Where is the implementation of the getString method ?
    2) Could you please tell why the Wait() Notify() and NotifyAll methods have been implemented in the Object class ? What was the need to define em in the Object class ?
    Thanks in advance for your time spent on this.
    Rgds

    Sarvananda wrote:
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    Rgds
    >
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    A desire to not have to couple your code to a particular database and JDBC driver. It's a classic example of the abstract factory pattern

  • Actual Mechanism of Object class as Parent Class to all the classes

    Hi All,
    We know that all the classes in the java platform are descendants of Object class. Even if we are writing a new class also, in the absence of any other explicit superclass, every class is implicitly a subclass of Object. As we are not extending the Object class directly, then how come the methods in the Object are inheriting to the Sub class what we have written? How the java maintain this heirarchy?
    Can you please explain this elaborately?
    Thanks in Advance,
    Uday

    Udaya Shankara Gandhi wrote:
    Hi All,
    We know that all the classes in the java platform are descendants of Object class. Even if we are writing a new class also, in the absence of any other explicit superclass, every class is implicitly a subclass of Object. As we are not extending the Object class directly, then how come the methods in the Object are inheriting to the Sub class what we have written? How the java maintain this heirarchy? Because the language is defined that way. Compilers implement the language according to the rules of the JLS. Exactly how they do that is undefined. It's up to each compiler. As long as it follows the rules defined in the JLS for parsing the code and generating the .class file, that's all that matters. However, somewhere in the compiler is code that does approximately this:
    if (class has an extends clause) {
      generate corresponding bytes for extends in .class file
    else {
      generate bytes for extends java.lang.Object in .class file
    }No great mystery, nor philosophical question.

  • Directory Editor adding object classes to the Extensions Tab

    I'm using Sun's Directory Editor web based product. Under the extensions tab lists the object classes you can add (obviously there are only a select few there). I would like to have shadowAccount available there. I have went through the installation and configuration guide but can't find how to do this. Just wondering if anyone knows how to add custom object classes to this tab.

    I'm using Sun's Directory Editor web based product.
    Under the extensions tab lists the object classes you
    can add (obviously there are only a select few
    there). I would like to have shadowAccount available
    there. I have went through the installation and
    configuration guide but can't find how to do this.
    Just wondering if anyone knows how to add custom
    object classes to this tab.this link has such an example:
    http://blogs.sun.com/kevlar/entry/directory_editor_tips
    Disclaimer: that's my feedback under the blog post. I'm trying to figure out how to use DE to maintain an extended schema that includes migrated NIS maps. The overall goal is to migrate from NIS to LDAP as a naming service AND create realistically easy method for day-to-day administration (constantly using the console is out of the question). I believe DE might provide a solution, if custom forms can be figured out. It's been very slow going.
    Does anyone else have examples of modifying Directory Editor forms? Any help would be appreciated.
    Thanks,
    Ron

  • How to pass the object of one class to the another class?

    Hello All,
    My problem is i am sending the object of serializable class from one class to another class but when i collection this class into another it is transfering null to that side even i filled that object into the class before transfer and the point is class is serializable
    code is below like
    one class contain the code where i collecting the object by calling this function of another class:-
    class
    lastindex and initIndex is starting and ending range
    SentenceStatusImpl tempSS[] = new SentenceStatusImpl[lastIndex-initIndex ];
    tempSS[i++] = engineLocal.CallParser(SS[initIndex],g_strUserName,g_strlanguage,g_strDomain);
    another class containg code where we transfering the object:-
    class
    public SentenceStatusImpl CallParser(SentenceStatusImpl senStatus, String strUserName, String strLanguage, String strDomain)
    *//here some code in try block*
    finally
    System.+out+.println("inside finally...........block......"+strfinaloutput.length);
    senStatus.setOutputSen(strfinaloutput);//strfinaloutput is stringbuffer array containg sentence
    fillSynonymMap(senStatus);
    senStatus.setTranslateStatus(*true*);
    return senStatus;
    Class of which object is serialized name sentenceStatusimpl class:-
    public class SentenceStatusImpl implements Serializable
    ///Added by pavan on 10/06/2008
    int strSourceSenNo;
    String strSourceSen = new String();
    String strTargetSen = new String();
    StringBuffer[] stroutputSen = null;
    HashMap senHashMap = new HashMap();
    HashMap dfaMarkedMap = new HashMap();
    boolean bTargetStatus = false;
    public SentenceStatusImpl(){
    public void setOutputSen(StringBuffer[] outputSen){
    stroutputSen = outputSen;
    public StringBuffer[] getOutputSen(){
    return stroutputSen;
    public void setTranslateStatus(*boolean* TargetStatus){
    bTargetStatus = TargetStatus;
    }//class

    ok,
    in class one
    we are calling one function (name callParser(object of sentenceStatusImpl class,.....argument.) it return object of sentenceStatusImple class containg some extra information ) and we collecting that object into same type of object.
    and that sentenceStatusImple classs implements by Serializable
    so it some cases it is returning null
    if you think it is not proper serialization is please replay me and suggest proper serialization so that my work is to be done properly (without NULL)
    hope you understand my problem

  • Oracle Access Manager Configuration : Cannot find the Person Object Class

    Hi,
    I am trying to install OAM , I am getting the following error when i am configuring the Identity server for the first time.
    1) I have installed OID. I am using one OID for both config and user data.
    2) I have installed Identity server and have modified the OID schema automically during installation.
    3) I have installed web pass.
    I have gone to the url: http://trn-ps-oid.oracle.com:7777/identity/oblix
    Here i gone to Identity System Console to configure Identity server.
    Following are the config data i have given
    Configuration DN : dc=mydomain,dc=com
    Search Base : dc=mydomain,dc=com
    Host : mypc.mydomain.com
    Port Number : 389
    Root DN : cn=orcladmin
    Root Password : *******
    Directory Server Security Mode : Open
    Is the Configuration data stored in this directory also : Yes
    Person Object Class : inetorgperson
    Auto configure objectclass : yes
    Group Object Class : groupOfUniqueNames
    Auto configure objectclass : yes
    After this I have clicked on the restart server button.
    It comes back to the page asking to enter Person Object class details.
    I Get the Error : Cannot find the Person Object Class.
    I have checked the object class in OID it is there, I have verified the connection details are also correct.
    Any Ideas what might be wrong.
    Earlier during setup i had to modify the OID schema, how do i check if this has been done.
    Any Ideas

    <?xml version="1.0" encoding="utf-8"?>
    <ValNameList
    xmlns="http://www.oblix.com"
    ListName="setup.xml">
    <NameValPair
    ParamName="mainOIS"
    Value="true"></NameValPair>
    <NameValPair
    ParamName="currentStep"
    Value="LDAP_CONFIG_CHANGES"></NameValPair>
    <NameValPair
    ParamName="status"
    Value="incomplete"></NameValPair>
    <NameValPair
    ParamName="whichDB"
    Value="OID"></NameValPair>
    <NameValPair
    ParamName="dataDirCopied"
    Value="TRUE"></NameValPair>
    <NameValPair
    ParamName="machineNo"
    Value="localhost"></NameValPair>
    <NameValPair
    ParamName="portNo"
    Value="389"></NameValPair>
    <NameValPair
    ParamName="rootDN"
    Value="cn=orcladmin,cn=Users,dc=mydomain,dc=com"></NameValPair>
    <NameValPair
    ParamName="ldapRootPasswd"
    Value="**************"></NameValPair>
    <NameValPair
    ParamName="securityMode"
    Value="Open"></NameValPair>
    <NameValPair
    ParamName="oblixUserDataSame"
    Value="Yes"></NameValPair>
    <NameValPair
    ParamName="searchBase"
    Value="dc=mydomain,dc=com"></NameValPair>
    <NameValPair
    ParamName="configDN"
    Value="dc=mydomain,dc=com"></NameValPair>
    <NameValPair
    ParamName="obClassPerson"
    Value="inetorgperson"></NameValPair>
    <NameValPair
    ParamName="defaultConfigForPersonOC"
    Value="true"></NameValPair>
    <NameValPair
    ParamName="obClassGroup"
    Value="groupOfUniqueNames"></NameValPair>
    <NameValPair
    ParamName="defaultConfigForGroupOC"
    Value="true"></NameValPair>
    <NameValPair
    ParamName="obOldClassPerson"
    Value="inetorgperson"></NameValPair>
    <NameValPair
    ParamName="obOldClassGroup"
    Value="groupOfUniqueNames"></NameValPair>
    </ValNameList>

  • How to make Object class to be serializable?

    I'm writing a session bean which contains an Object[][] as a return e.g
    public Object[][] getFoo(){
    I need the return to be of type Object since I'm constracting a 2D array of different object types e.g Integer, Double, HashMap, String etc. But EJBs require serializable objects for their public remote methods. Could you please advice me whether there is another class that I could use instead of the Object class to be serializable? I'm still using SDK1.3.1.
    Thank you

    I've already tried that before, but it doesn't work. When I try to assign different objects to my array as in the following example:
    ABC[][] abc = new ABC[4][2];
    abc[0][0] = new Integer(1);
    abc[0][1] = new String("abc");
    abc[0][2] = new HashMap();
    I'm getting compilation error since Integer, String and HashMap can not be casted into ABC. My question is whether there is such a class (part of the SDK) which implements Serializable AND these classes can be casted to, as in the above example?

  • How can i add an custom attribute and assign it to an existing custom object class in sun ds

    I need to add an attribute to sun ds schema and assign it to an existing custom object class.
    I know how to add an attribute but how can i add the attribute to an existing custom object class.
    Please help.
    Thanks

    The objectclasses attribute is multi-valued, so you can add several values to it as long as they are unique.
    For instance, I think you can add several declaration of the same objectclass as below (note the difference is the number of spaces in the value) howewer, from a schema perspective, only 1 will be taken into account:
    objectclasses: ( 2.5.6.6 NAME 'person' DESC 'Standard LDAP objectclass' SUP top MUST ( sn $ cn ) MAY ( description $ seeAlso $ telephoneNumber $ userPassword $ CustomAttr) X-ORIGIN 'RFC 2256' )
    objectclasses: ( 2.5.6.6 NAME   'person' DESC 'Standard LDAP objectclass' SUP top MUST ( sn $ cn ) MAY ( description $ seeAlso $ telephoneNumber $ userPassword $ CustomAttr) X-ORIGIN 'RFC 2256    ' )
    That's the reason why it is safe to delete previous value if you want to update an existing objectclass. No problem to add a new objectclass (new oid and new name) to the schema.
    -Sylvain

Maybe you are looking for