Results 1 to 6 of 6

Thread: Adding an object in java

  1. #1
    Join Date
    Dec 2009
    Posts
    296

    Adding an object in java

    Hello,
    I am trying something different here. I have an object o1 of class O1:
    Code:
    Public Class O1{
      Public int var1 = 6;
      Public int var2 = 64;
      Public int var6 = 645;
    }
    And I will course through reflection. What I want is to create a new object containing some fields O1. In fact, my question is: If I have a Field f, is that I can add to an object ? I know this is something different from others but I need to know the answer to it.

  2. #2
    Join Date
    Nov 2009
    Posts
    359

    Re: Adding an object in java

    Hello,
    The answer is no, when you create the new object, you are obliged to specify a type. If the type of object O1 is created, then it will have all the attributes of the class M1. I think you are not aimed to your program very well, what exactly you want to do in your code, that is what is the expected result of your code. I think you need to read some more documentation on the basics of java that is the core java.

  3. #3
    Join Date
    Apr 2008
    Posts
    240

    Re: Adding an object in java

    Hello,
    Here is my code, even I was trying to so something similar to this. If check my code and if you find that it is wrong somewhere then please guide me with the correct.
    Code:
    Public class dbconf {
     
        Public dbconf() {
        }
    
        @ Description(description ="Address of database server")
        Public String sernm = "localhost";
        
        @ Description(description ="Database name")
        Public String dbnm = "TestDatabase";
        
        @ Description(description ="Password to access database")
        Public String dbps = "pass @ database";
    }

  4. #4
    Join Date
    Dec 2009
    Posts
    296

    Re: Adding an object in java

    Hello,
    Here is my XML configuration, please check it this is correct.
    Code:
    xml version ="1.0" encoding ="UTF-8"?>
    <databasecn xmlns: xsd ="url here" id ="i0" xmlns: = xsi"url here" xsi: noNamespaceSchemaLocation ="Database configuration.xsd">
        <serverName>192.168.1.118</ serverName>
    </ databasecn>
    Thanks in advance.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Adding an object in java

    Hello,
    When you do extend to a Serializable object, you can make your own "serialization", there is no requirement to use standard mode ... Simply define the following methods
    Code:
    private void writeObject (java.io.ObjectOutputStream out)
    throws IOException
    private void readObject (java.io.ObjectInputStream in)
    throws IOException, ClassNotFoundException;
    Just use them in your code and see how the program works, if you get an error then post back the error you get.

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Adding an object in java

    Hello,
    Java provides a serialization in XML API standard that meets your needs XMLEncoder/XMLDecoder. Indeed, the attributes with default values are not serialized. A disadvantage, however, classes must serialize to respect the Convention JavaBeans (a default constructor and accessors / modifiers for attributes to serialize). It is possible to overcome this disadvantage, however, it appears rather laborious.

Similar Threads

  1. get classes and object in java
    By preeti makkar in forum Software Development
    Replies: 1
    Last Post: 07-05-2012, 11:08 AM
  2. conversion of Object into integer in JAVA
    By Jaisudha in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 12:45 PM
  3. How big is an Object in Java? Why Java neglects sizeof?
    By KALINDA in forum Software Development
    Replies: 4
    Last Post: 10-11-2009, 03:19 AM
  4. How to create object in JAVA
    By HP_Crook in forum Software Development
    Replies: 3
    Last Post: 09-10-2009, 11:52 PM
  5. Object test = new Object() <-- Java, best way in C++
    By ADISH in forum Software Development
    Replies: 3
    Last Post: 25-10-2008, 02:32 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,566,423.50632 seconds with 17 queries