Use of constructor

hi could u explain the use of constructors....
in one class i have 2 constructors ..one is no argument constructor and second one is with arguments...... what these two constructors will do??....

The constructor that matches the method's invocation (no arg or arg) will be executed. See this tutorial for more explanation:
http://java.sun.com/docs/books/tutorial/java/data/objectcreation.html

Similar Messages

  • How can I use multiple constructor

    Hi,
    I have some problem to using multiple constructor in java. It shows some error while compiling the following program. can any one give better solution for me.......
    public class Test6{
       public Test6(){
    this(4);    /*
    C:\Test6.java:5: cannot find symbol
    symbol  : constructor Test6(int)
    location: class Test6
    this(4);
      Test6(byte var){
    System.out.println(var);
    public static void main(String[] args){
    Test6 t6 = new Test6();
    }

    A number like 4 is an integer literal. So, you are passing an int to a function that is defined to accept a byte, hence you have a type mismatch. You need to cast the integer literal to a byte before passing it to the function:
    this( (byte) 4);

  • Create Requester ABCS without Reference using Service Constructor

    Hello,
    we using Service Constructor to create Requester ABCS. We disable the checkbox for CAVS and References, but the WSDL of EBS is as reference in Project and binding didn't bind to oramds. Another point is, that we disable ErrorHandling, but in composite and bpel is an external reference to AIAAsyncErrorHandling.
    Here are some screenshots:
    [Default Target Service Options|http://dl.dropbox.com/u/4274798/AIA-EAP/ServiceConstructor/SC_TargetServiceOptions-Enable.png]
    [Disable Checkboxes|http://dl.dropbox.com/u/4274798/AIA-EAP/ServiceConstructor/SC_TargetServiceOptions-Disable.png]
    [Reopen after editing|http://dl.dropbox.com/u/4274798/AIA-EAP/ServiceConstructor/SC_TargetServiceOptions-AfterConfirm.png]
    [Disable Error Handling|http://dl.dropbox.com/u/4274798/AIA-EAP/ServiceConstructor/SC_AddErrorHandling.png]
    Is it a bug in service constructor or did we misunderstanding the checkboxes?
    Marcel

    Bug 9431667 is logged for issue where error handling was unchecked, but it is still being defined.

  • What is the use of constructors

    what is the use of constructors in abstract class when we cannot instantiate the class

    Double posted and answered.
    http://forum.java.sun.com/thread.jspa?threadID=740376

  • Unable to Create Requestor ABCS using AIA Constructor in Jdev 11.1.1.2

    Hi Gurus,
    I'm currently trying to create ABCS Requester with J developer 11.1.1.2 using the AIA Service Constructor.
    The Composite Application shows the BPEL Component and the target services under the Composite screen.When we click on the BPEL Component we dont the process flow.
    Steps Followed
    1. Create project in Project Lifecycle Workbench
    2.Using the AIA Service Constructor connect to the AIA_LIFECYCLE Workbench.
    3.Select the RequestorABCS Service
    4.Filled out all the ApplicationName,ShortName,Service Version etc on Step 3 of 8
    5. Selected the Service Operation as Query.
    6.Under ABM import the Custom XSD structure and provided the Input and output message
    7.Select the message pattern as request/response
    8.Target Service Step selected the Query Service (this would query the required Customer Content which needs to be mapped).
    9.The the AIA Service Constructor creates BPEL Composite Component.
    When we double and open the BPEL Component we just see the error handling and partner link information.
    We are unable see any assign,scope invoke component on the swim lanes..
    Has anyone experienced this issue while creating ABCS Requester.
    Regards
    Sabir

    Hi Everyone,
    I was able to create Requestor ABCS in Jdev 11.1.1.2 by selecting EBS,wsdl as target. This is workaround you need to follow to create requestor ABCS where you have V2 wsdl available.
    Looks like there is bug#9541128 assigned for this issue. And looks like it would be fixed in 11.1.1.4 version of Jdev as per Oracle Support.
    Regards
    Sabir

  • Use of constructor in abs class?

    What is the use of writing constructors in abstract class?

    You would use an abstract class's constructor to initialize the state of an object of that class, just the same as any other class.

  • Using different constructors

    Hello all,
    I have a class that can be instantiated with 2 different constructors, like this :
    public class LProject {
    private List projects;
    public LProject(String path, String name) {
    super(path, name);
    projects = new ArrayList();
    public LProject(String path, String name, String description) {
    super(path, name, description);
    }My question concerns the initialization of the ArrayList, if i first create an object with LProject(path, name) the ArrayList will be initialize, and the then if i create a second object with LProject(path, name, description), the ArrayList would still be usable or it would be null?
    Do i have to initialize the ArrayList in both constructor? In this case it would give me two differents ArrayList so if i add the LProject object created before it will be in two different ArrayList?
    It is not clear for me can somebody help me clear that out.
    thanks a lot

    I don't think that is thread safe.
    If I was you I would do
    private static List projects = new LinkedList();
    Actually, that is not thread safe. But your example is not thread safe, either.
    @OP: if you want to use this static list, do this:
    private static List projects = Collections.synchronizedList(new ArrayList());But synchronization is not really necessary, if you keep this field as private and if you will not provide any kind of getter method that can return this list field (you can't guarantee what the other programmers will do with your list). If you decide to not use synchronization, you must guarantee that the manipulation of this list will only occur inside this class, where you can yourself control the access of this list. And you can achieve this control only by making this list totally unavailable to the others.
    If you are expert in synchronization, then you can use a unsynchronized list, doing the control of the manipulation of this list by your own code inside your class. Otherwise, if you don't know very much about synchronization, although the cost of performance when synchronization is being used (not so much, but there is a cost), it is always safer using a synchronized list.

  • Size Property of OracleParameter is not set when used in constructor

    Hi
    I have an issue in using OracleParameter in my .net windows app(vb.net) . If I create a OracleParameter like this, ths size property is not set
    Dim opParam As New OracleParameter("v_Test", OracleDbType.Char, 120, ParameterDirection.Output)
    'Here 120 is the size I have set, but it is not getting assigned to the Size property
    MsgBox(opParam.Size) 'This will return 0
    'I have to assign like this explicitly to have the size property set.
    opParam .Size=120
    Is it a problem in ODP.Net or I am doing something stupid ?.
    Any answers would be greatly appreciated
    Cheers
    John

    Hi John,
    In looking at the constructor call you have this "format":
    string, OracleDbType, int, ParameterDirection
    This does not match to a constructor that does what you want. What it matches to is:
    string, OracleDbType, object, ParameterDirection (i.e. the value (object) is being set where it looks like you want to set the size).
    The closest matching constructor for what you want would be:
    string, OracleDbType, int, object, ParameterDirection
    i.e.
    Dim opParam As New OracleParameter("v_Test", OracleDbType.Char, 120, null, ParameterDirection.Output)Hope that helps a bit (assuming I have not misread, etc...)
    - Mark

  • Singleton Class using a constructor not a getInstance method

    Hi,
    I have a class with a couple of contructors, the class is instantiated many times in the application.
    Is there any way by which I can return a single instance of the class when the contructor is called ?.
    I dont want to declare a get instance method to return a single instance is it somehow possible to do this in the contructor itself.
    This is done so I dont have to refactor the whole application and change all the places where this class is instantiated.
    Example
    XXXClass xxx = new XXXClass();
    every time new XXXClass() is called the single instance of the class must be returned.
    I dont want to implement
    XXXClass xxx = XXXClass.getInstance();
    Thanks in advance
    Rgds
    Pradeep Thomas

    The short answer to your question is No. If your class has accessible constructors and your code calls "new" then there will be multiple instances of the corresponding objects.
    Possible ways round your problem are to use static variables in place of instance variables or to use your existing class as a wrapper for another class that is instantiated only once. This second class should include all the variables and methods and the wrapper class would delegate all calls to it. This is not quite a singleton because there would still be multiple instances of the wrapper, but each instance would share the same variables and methods. You could also add a getInstance() method to the wrapper class so that new code could start to use it as a singleton.
    Other than that, it's time to refactor! Good Luck.

  • Singleton Class using a constructor not a get Instance method ?

    Hi,
    I have a class with a couple of contructors, the class is instantiated many times in the application.
    Is there any way by which I can return a single instance of the class when the contructor is called ?.
    I dont want to declare a get instance method to return a single instance is it somehow possible to do this in the contructor itself.
    This is done so I dont have to refactor the whole application and change all the places where this class is instantiated.
    Example
    XXXClass xxx = new XXXClass();
    every time new XXXClass() is called the single instance of the class must be returned.
    I dont want to implement
    XXXClass xxx = XXXClass.getInstance();
    Thanks in advance
    Rgds
    Pradeep Thomas

    Pradeep ,
    You see a constructor does not return anything
    when you tell java
    String str = new String();
    It is into the reference str that a Object of the type String is assigned and used ..
    If you want a single instance to exist in your application ..the best way is to use the singelton approach.
    Alternatively you could create one static instance of the object in a parent class and all the classes that inherit from it will then share access .

  • Converting a String to a Double, may I use Double constructor?

    Hello,
    I need to convert A String to a Double in my application.
    Usually I use the Double.parseDouble(String) method that works fine.
    But I have found one line in the code that use the Double class constructor: new Double(String). It has been observed that that constructor sometimes throws NullPointerException.
    My question is, are theses two methods both good practices to do the convertion? Could threre be a multi-threading problem with the Double construtor?
    I'm using JDK 1.3.1.
    Here is a sample of stack trace:
    bvsmgr: java.lang.NullPointerException
         at java.lang.FloatingDecimal.readJavaFormatString(Unknown Source)
         at java.lang.Double.valueOf(Unknown Source)
         at java.lang.Double.<init>(Unknown Source)
    Thank you for all answers,
    Florent.

    But I have found one line in the code that use the
    Double class constructor: new Double(String).
    It has been observed that that constructor sometimes
    throws NullPointerException.
    My question is, are theses two methods both good
    practices to do the convertion? Could threre be a
    multi-threading problem with the Double construtor?Both methods are the same (they both use valueOf()), and if the c'tor throws an NPE, then only because you feed it null. parseDouble would do that, too.

  • ABCS using Service Constructor

    How important it is to following the general AIA custom extension standards to extend a custom developed ABCS process using the service constructor?
    My understanding is Oracle follows the AIA custom extension standards to keep the out of the box PIP code upgrade/patch free.. When we are developing our own ABCS processes using the service constructor, there is an option to add the extensions to the custom ABCS processes, does this add any value?, my personal feeling is that this is going to increase the complexity of the custom code..
    Please share your experiences...
    Thanks,
    Sid

    Hi,
    We have come to the same conclusion. We will not need to add extension points to ABCS as we would simply redevelop and deploy a new version.
    I also don’t think extension points are required for long running EBF’s as we can deploy multiple versions. The only problem that could occur is if we wanted already running processes to change their behaviour, but as we do not have any long running process as yet we haven’t considered this.
    Not implementing extension points effects how we use the PIPAuditor. All our ABCS’s fail the extension point tests. I think I will need to look into removing these tests from out PIPAuditor.
    Robert

  • Inserting Records in an Array and using a constructor with it

    I badly need help on this! Please please please! I have been studying java for a short time only.
    Anyway, here goes: My project requires the following:
    Employee inputs the no. of video in the shelf. They have four classifications: Drama, Comedy, Action, and Thriller. Each video classification has different rates. The employee creates a video record containing the following information: 1. video ID number, 2. video classification, and 3. Price.
    The employee should display the classifications of videos available and the price. Only the available video tapes would be displayed according to the customer's chosen classification. When the customer chooses the video he wants to rent, the program will register and attach the name of the customer to the video number.
    I only need to use arrays, and NOT database to record the information.

    is it ok i i declare the drama_rate outside the video class?
    i have a list of variables on my videoupdate classYes. It's probably best to declare it static & then you can access it directly:
    public static float drama_rate = 100.0;
    rate = <the class name>.drama_rate;
    so, i should also include a customer no. both in the video and customer class.I would. You may want to list a bunch of videos and who currently has them. This way you don't have to search the customers AND the videos to do this.
    thanks =) i don't know either why we had to validate/invalidate,\
    but our applet doesnt refresh when >it is supposed to, so
    we just used this method. It wouldnt slow down the application, would it?Could you just revalidate()?
    the use of arrays. i havent finished with the program yet.
    i have the design already, i just couldnt put it in code.
    im not familiar with the use of multidimensional arrays-
    can i use this for the video and customer records i will need to store?Not sure what you're using arrays for, but here's an example of something I might do. Maybe it will be useful to you.
    Have you looked at HashMaps? You could use "Customer" as the key and then use an ArrayList of checked out Videos as the value:
    HashMap customers = new HashMap();
    ArrayList videos = new ArrayList();
    //Add the checked out videos to the list
    videos.add(video);
    <etc>
    // Add this customer and the list of videos he has checked out.
    customers.put(customer,videos);
    [\code]

  • Which the cost of using a constructor in big model class ?

    Hello for all
    I am having to do a find and I have an entity(model) with 20 parameters.
    The question is:
    It is better to ask (by if's) if the parameters are null, if they go I pass null for the object, or to carry that object with the parameters, to use empty strings when it has not data for example, and to send it like this.
    Which the cost of the operations in terms of expenses with processor in the first option and memory on secondy? Which the most advantageous?
    I thank the collaboration
    Thanks

    I think the best way to use null. So we can first check whether it is null or not. If it is not null we can proceed further.
    Looking performance i think this is better option.

  • Does serialization uses the constructor?

    actually, the question is about de-serialization.
    It seems some calls in my no-arg constructor are never made.

    actually, the question is about de-serialization.
    It seems some calls in my no-arg constructor are
    never made.http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/input.html#2971
    "For serializable objects, the no-arg constructor for the first non-serializable supertype is run [...] Then the fields of each class are restored by calling class-specific readObject methods" (emphasis added)
    In other words, the serialization mechanism assumes that the serialized object is in a correct state, and that it merely needs to update field contents. This is very reasonable -- consider what would happen if your object's constructor set an ID field on the object.
    However, a particular JVM may maintain object state that's not visible to the application, and is set by the construction process (in particular, by the constructor for Object, which is often the first non-serializable supertype of a serializable class).
    If you really want to update your object during deserialization, override the readObject() method.

Maybe you are looking for

  • Can't find files after restoring them from Time Machine

    Hi! Yesterday I formated my macbook pro and re-install Mountain Lion. Before that I made a backup using Time Machine. When I wanted to create full system restore I couldn't do that. Neither using migration assistant neither with Mountain Lion startup

  • HP Multicenter Printer HP LaserJet Pro MFP M127fn

    I cannot get my printer to connect to my computer wirelessly and printer did not come with a USB cable.  I am on Windows 7 64 bit.

  • Music Wont Add To iTunes

    When i try to add a .MP3 File to iTunes Library It Just Doesn't Come Up. So I Tried Windows Media Player. That Said I Need A Codec Or Something :S Why Wont It Add? Thanks Kaos. A Good One   Windows XP  

  • Accessing components vars.

    Hi, How do I access a var in a differint component? I have two custom components in the same application and need to get the variable (arrayCollection) from one to populate a chart in the other.

  • Drop Down in webDynpro.

    Hi experts , I wana get help on drop down. I have got an internal table which has all the company code related to the user who has loged in UI. I want to display that internal table as drop down. Please provide me a solution .