Object Calling need to clarify

Dear Experts,I need a little help.Please read the following code to give me some answers:
<pre>
package weight;
public class Weight {
     public static final int SMALLER = -1, EQUAL = 0, LARGER = +1;
     int a;
     public Weight (int a){
          setGram(a);
     private void setGram(int a) {
          this.a = a;
     public int compareTo(Weight wgt) {          
          int status;
          double thisGram = this.getGram();
          double otherGram = wgt.getGram();     
          if (thisGram < otherGram){
               status = SMALLER;          
          }     else if (thisGram == otherGram){
               status = EQUAL;
          }     else {
               status = LARGER;
          return status;          
     private double getGram() {
          return a;
</pre>
Now I created main class:
<pre>
package weight;
public class WeightMain {
     public static void main (String args [] ){     
          Weight wgt1, wgt2;     
          wgt1 = new Weight (2);
          wgt2 = new Weight (3);     
          int result = wgt1.compareTo(wgt2);     
          if (result == Weight.SMALLER){
               System.out.println("wgt1 is smaller than wgt2");
          }     else if (result == Weight.EQUAL){
               System.out.println("wgt1 is Equal to wgt2");
          }     else {
               System.out.println("wgt1 is larger than wgt2");
</pre>
My question is how the compareTo () method is working.It is taking a object of the Weight class as it's parameter but what this.getGram() means and what wgt.getGram() means.How they are getting value.Please give me a little explanation too.
Thanks to spend you valuable time and effort.

public int compareTo(Weight wgt) {          
int status;
double thisGram = this.getGram();
double otherGram = wgt.getGram();     
if (thisGram < otherGram){
status = SMALLER;          
}else if (thisGram == otherGram){
status = EQUAL;
}else {
status = LARGER;
return status;          
private double getGram() {
return a;
}This is obviously not your code, have you taken the time to step through it and to change the arguments to the constructors to Weight in the main method?
The compareTo method takes a reference to a Weight object, it then does a simple comparison on the values returned from the getGram method and returns the appropriate "status" according to the values stored by the setGram method called in the constructor of the object.
"this" refers to the instance of an object inwhich the execution is happening and the wgt is a reference to the other object--in this case the second object that was created in the example code.
This should become clear if you learn how to use your debugger--set a breakpoint, and trace the code execution. Take the time: learn how to use the debugger and play with the code until you understand what is happening.

Similar Messages

  • Weblogic 10.3.0 issues with remote object calls.

    All:
    I was wondering if anyone has experienced any issues with Weblogic 10.3.0 dropping initial remote object calls over AMF Secure Channel. Here are the issues we are experiencing.
    1.     FLEX applications fail consistently on the first remote object call made across the AMF Secure Channel. Resulting in the request not returning from the application server; which has had varying affects on the different applications including missing data, application freeze and general degrading of the user experience.
    2.     FLEX applications require a browser/application refresh once the application has been inactive for a certain period of time. In our experiences the behavior occurs after 30 minutes of inactivity.
    I've deployed this same code to Weblogic 10.3.3 and the behaviors go away. Are there any patches to 10.3.0 that might take care of this issue that we are not aware of?
    Thanks for you help,
    Mike

    Hello,
    I found the problem. But I needed change the target of all my datasources until discover that one of my datasource didn´t answer and no errors was trigged.
    My server was waiting this datasource, and not get started.

  • With Java Persistence, are DAOs (data access objects) still needed?

    I have just looked at the Java Persistence tutorial and it says each table row of a database can be represented as a Java Persistence entity instance.
    The definition of an "entity" is very much like how you would define the class of an equivalent DAO.
    So I am wondering... should DAOs still be used ? or can persistence entities completely replace them?

    Hi,
    I am saying that if you use JPA then you will not be making a DAO class, for example if you have a Person.java object you will not need to make a PersonDAO.java object.
    For example, if using JPA you Person.java object would look like this example below...
    Of course, the classes that call person object may need to call some JPA manager APIs or some JTA transaction APIs. If you use EJB session beans to call the JP{A entity then you dont have to have any code, as ou can see here
    https://blueprints.dev.java.net/bpcatalog/ee5/persistence/ejbfacade.html
    if you do not use EJBs in a pure web app then you will likely manually write code to manage transactions and entity manager APIs such as
    https://blueprints.dev.java.net/bpcatalog/ee5/persistence/webfacade.html
    See Person.java entuty example below and see there is no DAO code.
    @Entity
    public class Person implements java.io.Serializable {
        private int personId;
        private String userName;
        private String firstName;
        private String lastName;
        private String summary;
        public Person() { }
    @Id
    public int getPersonId() {
    return personId;
    public String getUserName() {
    return userName;
    public String getFirstName() {
    return firstName;
    public String getLastName() {
    return lastName;
    public String getSummary(){
    return summary;
    public void setPersonId(int personId) {
    this.personId = personId;
    public void setUserName(String userName) {
    this.userName = userName;
    public void setFirstName(String firstName) {
    this.firstName = firstName;
    public void setLastName(String lastName) {
    this.lastName = lastName;
    public void setSummary(String summary) {
    this.summary = summary;
    }

  • Dynamic object call

    hi i have following code:
         switch (type) {
                   default:
                   case 1:
                        objSquare sq = new objSquare(positionX, positionY, positionX1,
                                  positionY1);
                        sq.color = color;
                        sq.paint(g);
                        break;
                   case 2:
                        objArc ac = new objArc(positionX, positionY, positionX1,
                                  positionY1);
                        ac.color = color;
                        ac.paint(g);
                        break;
    }it is possible to create Java object dynamicaly? So there will be no switch, but i will load object name to call from database...for example, this "objSquare sq = new objSquare" will be called depending on object requested, so i dont need many switch cases, just one object call..
    more details:
    i have DB table with:
    id object_id object_name etc....
    and i want to load object in java that corresponds with object_name variable i will get from DB...it is possible?

    You can use reflection for this, or use a map of names to factory pattern. I'd go with a factory, as it's not as open to insecurities. So have a HashMap<String, Class> or HashMap<String, Factory> where Factory is an interface with an appropriate method to create your objects, and Class is java.lang.Class and you create your objects using the newInstance method.

  • EventListeners for multiple remote object calls

    Hi all,
    I have a Flex component that is displaying content from multiple (specifically two) remote object calls. I can call both remote methods, get the results back, pass them off to their respective ItemRenderers, etc. with no trouble. What I need, though, is a way to determine if I get no results back from either function call, to dispatch an event to trigger the next view state, and I don't know how to do that. Something like:
    protected function ticketConfigurationStateChangeHandler(event:Event):void
                   if(getPackagePromptsResult.lastResult.length == 0 && getTicketPromptsResult.lastResult.length == 0)
                         this.dispatchEvent(new Event("ticketConfigurationStateChange"));
                protected function ticketPrompts_creationCompleteHandler(event:FlexEvent):void
                    getTicketPromptsResult.token = registrationAPI.getTicketPrompts();
                    getTicketPromptsResult.addEventListener(ResultEvent.RESULT, showTicketConfiguration);
                protected function packagePrompts_creationCompleteHandler(event:FlexEvent):void
                    getPackagePromptsResult.token = registrationAPI.getPackageCPrompts();
                    getPackagePromptsResult.addEventListener(ResultEvent.RESULT, showPackageConfiguration);
    Any suggestions would be greatly appreciated...I know I need the event listeners to be able to get lastResult.length (and have it not be null) but I don't know how to set them up so I can automatically pass the user through the component and onto the next one if there are no results returned without having the user click a button or something similar on an otherwise blank component.
    Thanks in advance!
    ~ Amanda

    Hi all,
    I have a Flex component that is displaying content from multiple (specifically two) remote object calls. I can call both remote methods, get the results back, pass them off to their respective ItemRenderers, etc. with no trouble. What I need, though, is a way to determine if I get no results back from either function call, to dispatch an event to trigger the next view state, and I don't know how to do that. Something like:
    protected function ticketConfigurationStateChangeHandler(event:Event):void
                   if(getPackagePromptsResult.lastResult.length == 0 && getTicketPromptsResult.lastResult.length == 0)
                         this.dispatchEvent(new Event("ticketConfigurationStateChange"));
                protected function ticketPrompts_creationCompleteHandler(event:FlexEvent):void
                    getTicketPromptsResult.token = registrationAPI.getTicketPrompts();
                    getTicketPromptsResult.addEventListener(ResultEvent.RESULT, showTicketConfiguration);
                protected function packagePrompts_creationCompleteHandler(event:FlexEvent):void
                    getPackagePromptsResult.token = registrationAPI.getPackageCPrompts();
                    getPackagePromptsResult.addEventListener(ResultEvent.RESULT, showPackageConfiguration);
    Any suggestions would be greatly appreciated...I know I need the event listeners to be able to get lastResult.length (and have it not be null) but I don't know how to set them up so I can automatically pass the user through the component and onto the next one if there are no results returned without having the user click a button or something similar on an otherwise blank component.
    Thanks in advance!
    ~ Amanda

  • Two remote objects calls on the same php class

    Hi to all,
           I've encountered a strange issue while developing with remote objects.
    I've a mxml component with an init() method inside which is called by a menu.
    When the init() method is called it makes 7 remote object calls which are bound to some components' dataprovider.
    Among this calls I've got 2 remote object which refer to the same remote class. This because I have to call the class twice and the bind the result to two different combobox. Below you find the code:
    <mx:RemoteObject id="myFile" source="myRemoteClass" destination="amfphp"  showBusyCursor="true" makeObjectsBindable="true" fault="traceFault(event)"/>
    <mx:RemoteObject id="myXls"  source="myRemoteClass" destination="amfphp"  showBusyCursor="true" makeObjectsBindable="true" fault="traceFault(event)"/>
    in the init function I make this calls:
    myFile.listDir("dir_1")
    myXls.listDir("dir_2")
    then in the mxml code I bound the result of myFile to combobox1 and the result of myXls on combobox2.
    The problem arise when I call the myXls' listDir method. When I call it I receive the following error:
    code:
    Client.Error.DeliveryInDoubt
    Message:
    Channel disconnected
    Detail:
    Channel disconnected before an acknowledgement was received
    The strange thing is that not only the myXls object returns this error, but also all the other 6 remote object return the same error above.
    I'm not sure, but I guess that the error could be caused by the two remote object which call the same php remote class. If I comment one of the two calls everything works fine.
    Do you have any suggestion about?
    Thanks!!
    Bye
    Luke

    Hi Jan.
    1) We have the 2 VO, each with 3 rows to fill in data. What I mean is that when i just fill in all the fields for the first row of the first VO, and the value of one of these fields is bigger than 50, then after the exception is thrown and the message is displayed, the fields for the first VO are duplicated and shown in the second VO as if the user had inserted them.
    2) We tried yesterday the validateEntity and a Method and Atributte Validator approaches after reading that white paper with the same results.
    The validation is correctly done using any of the those methods.
    I will try to reproduce this issue with the HR schema.
    Thanks in advance once again.

  • I need to clarify how I can use adobe as a host for my site for free. I see where business catalyst is supposed to be temporary as well as it is recommended to use as the better alternative to launch my muse site. But then I have to use the long

    I need to clarify how I can use adobe as a host for my site for free. I see where business catalyst is supposed to be temporary as well as it is recommended to use as the better alternative to launch my muse site. But then I have to use the long extension of "businesscatalyst" in addition to the domain name I'd prefer. How exactly can I take it live? do I have to use a third party hosting?

    Hi,
    Once you are done with your sitet, Click on Publish in Muse, select New Site from the drop down, It will ask you a name for your site, which will be used for  site url, you will get a url like mysite.businesscatalyst.com, then go to the browser and login to the admin panel, mysite.businesscatalyst.com/admin and on Dashboard, click Launch site. This will push your site live, and you can then add your custom domain.
    Also make sure that you have completed all these actions mentioned here
    User manual
    Do let me know if you have any question.

  • When  submit remote object call getting error Client.Error.DeliveryInDoubt

    Hello,
    We are having very weird error DeliveryInDoubt from blazeds.
    [ERROR] failed to call the remote service !!![FaultEvent fault=[RPC Fault faultString="Channel disconnected" faultCode="Client.Error.DeliveryInDoubt" faultDetail="Channel disconnected before an acknowledgement was received"] messageId="98F7B030-0FE0-0B88-300C-EC422D055E21" type="fault" bubbles=false cancelable=true eventPhase=2
    Error does not happen every time, but rather from time to time but happens on all client machines.
    Environment:
    blazeds v3.
    Flex application with Remote Object.
    Browser IE7.
    Object that passed to blazeds is complex and might have 100 items.But number of items does not seem affect error occurences.
    Short description for the object passed to blazeds remote object call for processing:
    Remote Object call takes an argument ArrayCollection of SyncRequest objects (_requestSyncList)
                    var syncRequest:SyncRequest = new SyncRequest();
                    var syncObject:Object = new Object();
                    syncObject[requestBuilder.direction] = requestBuilder.jobMap;
                    syncRequest.syncJobs = syncObject;
                    _requestSyncList.addItem(syncRequest);          
    requestBuilder.jobMap is an object that have different artifacts.
    jobMap[obj.artifact] = myColl;
    myColl is ArrayCollection of artifact of SyncJob
    Here is the definition of SyncJob
       public class SyncJob
            public var jobName:String;
            [ArrayElementType("com.farmers.docprocessing.remotesync.vo.JobParameter")]
            public var jobParams:ArrayCollection;
    Not sure what causing that issue and how to debug it. 
    Please advice.
    Thank you

    Not without you psoting some code.
    Possible problem: Difference between object type being returned, vs the type of the reference (i.e., the method that returns an object should have a return type of the interface name).

  • Mock objects calling parent constructor

    I'm trying to create some tests in which I'm providing a mock object to the constructor of my test objects and testing that appropriate methods are called in the mock. The objects I'm mocking only have a few public methods so I created an inner class that extends the object I'm trying to mock and just records which method was called. However, when I run the test it fails because the mock object calls the default constructor of the object of it's parent; causing the entire application to run. I'm trying to figure out a way around this.
    Now I already know a solution that would work, creating a second constructor in the object I'm mocking which does nothing, then call the fake constructor from my mock object instead of the default constructor. The solution dosn't feel very elegent though, I'm wondering if I'm missing a simpler solution?

    dsollen wrote:
    I'm testing JMS communication between two applications. Each topic Listener has a reference to the main class of the respective applications to communicate with them.I still don't see why a call to the constructor should start the program. Change the design so that doesn't happen. You should instead provide a start method.
    Kaj

  • Simultaneous remote object calls in one http request?

    I am noticing when I have two remote object calls happen at the same time they are being bundled into one http request.  This is causing problems in my application becuase the result is not coming back until both have finished.
    So basically I have to calls that happen at the sametime.  One does not take anytime and the other is a long running task.  I will not get the result for the first until the long running task completes.
    Has anyone else seen this?
    Any help would be appreciated.

    "suspend the main thread, pending a remote call.." No. Can't
    be done.
    ..."pass arguments into the resultHandler..." Yes, this is
    done using the AsyncToken. (ACT pattern)
    The send() methods returns an AsyncToken object. You can use
    this dynamic object to add almost anything you want to the token,
    including strings, and functions (google the term "closure").
    As I am still not comfortable with anonymous functions, I
    like to pass strings. I pass an identifier, which I can use in a
    switch statement to determine the next step. Sometimes I pass a
    "nextStep" string to define finer grain conditionality.
    I use a single dataService object and result handler function
    for all calls.
    Tracy

  • Object call itself

    This is an example from "Thinking in Java" page 234,
    //: c04:ArrayInit.java
    // Array initialization.
    public class ArrayInit {
    public static void main (String[] args) {
    Integer[] a = {
    new Integer(1),
    new Integer(2),
    new Integer(3),
    Integer[] b = new Integer[] {
    new Integer(1),
    new Integer(2),
    new Integer(3),
    I've been following in "Thinking" pretty well so far, but I'm confused about what's going on here. First it creates an array called "a" that's populated by "Integers" (not int). Then it initializes the array with each cell having another "Integer". But are they automatically initialized with more objects like themselves? Why not. Wouldn't that make an infinite loop? Is this Object calling itself before its even done initializing? I guess the Integer object isn't really described here, the "a" object is. Is "Integer" a predefined class?
    Are the flaws in my thinking obvious to anyone?
    Thanks

    didn't quite understand uyour question.
    when u say Integer a[] = new Integer[3], you are creating a three element array and initializing it with the default values.
    And the default values of an object array is null;
    so now the array contains null value only.
    if it was a primitive array , they will be intialized with the corresponding default value.
    for example, if it was an array holding primitive int, the default value is 0.
    I think the book itself explains in detail about this.
    hope you are clear abou this.
    Thanks,
    Sumesh

  • Need FM which tells whether request received(object call) from R3 OR Portal

    Hi All,
    I need to differentiate some logic in a method based on whether it is called from R/3 OR Portal.  I think there is a function module which tells whether the request is from Portal or not.
    Thanks in advance
    Regards,
    Sudhakar.

    Hi Sudhakar,
    Not aware of any such FM. But this is what you can do.
    Any action form portal usually will call an RFC. In that RFC you can use SET parameter (SAP memory). And in your method you can check for that parameter to determine if it was called from portal.
    Regards
    Krishna Kishor Kammaje

  • ABAP Objects: Calling private Methods

    Hi,
    i would choose an private Method of an global class (for example class: CL_GUI_ALV_GRID private Method: SEARCH_START) in a local class.
    class lcl_test definition for testing.
      private section.
        methods test for testing.
      data ref_alv type ref to cl_gui_alv_grid.
    endclass.
    class lcl_test implementation.
      method for test.
        create object ref_alv ...
    * How to call a private Method?
    call method ref_alv->search_start( ). "not possible!   
      endmethod.
    endclass.
    Is this possible?
    Regards,
    Damir

    Damir, of course you can call a private method of a class, if this class has made you a friend with the syntax element FRIENDS (available since Release 6.10). Here is a syntactically correct example, when my_method is a private class method:
    REPORT test.
    CLASS mytest DEFINITION FOR TESTING.
      PRIVATE SECTION.
        METHODS test FOR TESTING.
    ENDCLASS.
    CLASS myclass DEFINITION FRIENDS mytest.
      PUBLIC SECTION.
        CLASS-METHODS my_method.
    ENDCLASS.
    CLASS myclass IMPLEMENTATION.
      METHOD my_method.
      ENDMETHOD.
    ENDCLASS.
    CLASS mytest IMPLEMENTATION.
      METHOD test.  
        CALL METHOD myclass=>my_method.
      ENDMETHOD.
    ENDCLASS.
    If my_method is not a class method, then you need to create an object of the class first, whose methods you want to test.
    Kind regards,
    Michael Kraemer

  • Middleware and Adapter Object help needed

    Hi all,
    We are trying to replicate business agreements from CRM to contract accounts in our R/3 IS-U system. We've followed the various cookbooks and guidelines but have so far been unsuccessful. For object BUAG_MAIN, is an adapter object needed? If so, we are unable to find one in R3AC1.
    If we check the BDoc message, we are getting two Technical errors after creating the business agreement:
    1. "Outbound call for BDoc type BUAG_MAIN to adapter module CRM_UPLOAD_TO_OLTP failed."
    2. "Service that caused the error: SMW3_OUTBOUNDADP_CALLADAPTERS"
    Any ideas? Points will be awarded for helpful responses. Thanks in advance.
    Message was edited by:
            John S

    So in R3AC1 there is a button to show inactive adapter objects. Hitting this showed BUAG_MAIN. After that, we opened BUAG_MAIN and activated the object. This resulted in a couple of changes that we clicked through. We then were able to do an initial load of the business agreements and replications of newly created ones happened thereafter.

  • URL object calling stored procedure

    I want to call a dynamic web page (stored procedure) as a portlet. Is the best way to do this to create a URL object (in Applications) that points to the stored procedure? I have been trying this, but Portal can't find the page. The URL is valid (probably has to do with PL/SQL Gateway). What is the process for calling a stored procedure as a portlet? I don't want a Portal form created for this. I don't want any user interface template or other overhead in this portlet. The stored procedure needs full control of the content.
    null

    Hi James,
    You can try creating a dynamic page (in Applications). In your dynamic page, you can take out all the HTML codes and simply put the package/prodecure name in there. Then you can publish that Dynamic Page as a portlet and include that in your Portal page.
    Hope this helps.
    Regards,
    Jatinder

Maybe you are looking for