Can a method return a class ?

hi,
i have a simple question.
can a method return class value ?
in the below script i did'nt understand the commented line.
package com.google.gwt.sample.stockwatcher.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("login")
public interface LoginService extends RemoteService {
  public LoginInfo login(String requestUri);  //What is this ? is this a sample of what i asked ?
}

The answer to your question is yes.
The idea is that an object calls a function of another object (passing in objects to the function as arguments) in which that object returns an object (note the arguments or returned value of the function may alternately be primitive types). Each object typically encapsulates data and provides a rich set of functions to the calling object so that calling object doesn't have to deal with the raw data directly. Therefore, not only does the calling object get the data it wants, but also a rich set of functions that can manipulate that data.
Example:
Book book = new Book();
int characterCount = book.getChapter(3).getParagraph(4).getSentence(12).getWord(8).getCharacterCount();
In the above, each object (Book, Chapter,Paragraph,Sentence,Word) has a rich set of functions it provides to its caller.
Example: the Sentence Object has a collection of word objects (raw data). Functions it provides to Paragraph object are:
Word getWord(int index), Words getWords(), int getWordCount().
If you haven't already done so, I suggest reading a book on Java from cover to cover to pick up such Object Oriented concepts.

Similar Messages

  • Can a method return multiple items

    Can a method return more than one thing?
    I want to have a method return a boolean and a String. My method is saying if something is right or wrong, then its saying the reason why.
    help, please.
    Thanx

    Afternoon_Delight wrote:
    My question is:
    Is there a way so that it can be more like this:
    public boolean, String checkValidity (){
    To expand on the previous posts, one way (not saying it's the best one!) is to create an object that combines the information that you want returned:
    public class MyValid
      private boolean valid;
      private String text;
      public MyValid(boolean valid, String text)
        this.valid = valid;
        this.text = text;
      public boolean isValid()
        return valid;
      public String getText()
        return text;
    class DoFoo
      public MyValid checkValidity()
        return new MyValid(false, "Because I said so!");
    }

  • Can "main" method return values

    Hi,
    I have a requirement of returning values to the
    command prompt from the main method. Is this possible
    to do in the first place. Is it valid.
    i.e. Can you do the following in Java,
    =======================================
    import java.io.*;
    import java.lang.Object;
    import java.util.*;
    public class P
         public static String main(String args[])
         String bye = "BYE";
         return(bye);
    =========================================
    Can "main" method in Java return values at command
    prompt.
    Can you have something like,
    public static String main(String args[])
    instead of
    public static void main(String args[])
    Help urgently needed as I need to pipe data from a
    Java program to a C++ program. One method is to
    writing to a flat file but this would cause overheads
    reading and writing to a file, hence this way.
    Any help would be greatly appreciated.
    Thanks in advance.
    Thank,s

    Hi jchak,
    Yes I am trying to pass a Java String to a C++
    application. Any insights, any help.
    OK the whole thing goes as follows,
    =========================================
    Theres a C++ application which first starts up.
    This app is then supposed to invoke a Java class file
    which does some processing. Finally the value of one
    variable in Java (actually a huge String) is to be made
    available back to C++. This could be done thru flat file
    wherein the Java outputs the string to the flat file
    and on return the C++ program can be made to read the
    same flat file to retrieve that string but this would
    surely cause some overheads (time factor) reading and
    writing files. So I wish to devise some way by means
    of which I can return the string value back to the C++
    program. Piping of data from one app to another is what I
    want to do.
    Is there some way by means of which Java can return
    back or communicate or pipe back the string back to
    C++. How can it be done without using external flat files
    or databases.
    Thansk,
    JAtin

  • Abstract class method returning unknown class

    Hi
    I have created an abstract class having one of the method returning an object of a class which is not present at the compiletime. surprisingly the compiler didn't check the availability of the returning class at compilation time. it gave exception of classnotfound when I tried to rum it.
    is there any explanation of it??

    Thanks for the replay. I got the reason.
    actually evenif I did not compile to class file, but I have kept my java file in the same directory. while compiling the abstract class the compiler automatically compiled the reffered class and generated the required class file.
    I got the error when I moved the java file to another dir
    the code is like
    <code>
    abstract class AbstractTest{
         CompleteClass method1(){
              System.out.println("inside method1 of abstract class");
              return new CompleteClass();
         ExtraClass method2(){
                   System.out.println("inside method2 of abstract class");
                   return new ExtraClass(); // this class was not compiled before
         } // only java file is there in the dir
         abstract void demoMethod();
    </code>

  • Can a method return more than one value?

    I was studying for my biology exam and I got bored and I started thinking and then I wandered if a method can return more than one value...?
    For example, if I want a method to return a row a column, I make a method that returns an int. But what if I want to return two ints? Or what If I want to return an integer and a string? Is it possible or do I have make two methods, each returning one thing?
    What I always did until now is is I want for example to return a few integers, I would store them in a String and then when I return the string, I parse the numbers out using stringtokenizer... but it doesn't look like the best way... and it's pretty annoying...

    I'm weak on terminology, hence I don't even know what
    AFAIK means...As Far As I Know
    This doesn't really make sense for me. It's more
    efficient to make a whole class just for two
    integers, than having two methods? Efficiency is not the point. The flow is.
    If you have two methods, the caller must be aware of both of them. The other way it's up to the callee.
    Just because the
    two integers are related to each other? Doesn't
    making a class require more memory usage than just
    making two one-line methods?The memory usage is not wholly irrelevant, but there are ways to handle that (caching, inlining, etc.).
    It's a bit hard to counter your point for me, but if you had done a lot of GUI painting stuff, you'd see all those Points, Dimensions, Rectangles, you name it, are quite invaluable.

  • Can EJB method return another EJB?

    Hello,
    I am new to EJB technology. I am working with Sun Application Server bundled in Netbeans 4.1
    Is it po[b]ssible a method of a session bean to return another EJB which is instantiated with arguments depended on the method?
    If no, is there an alternative way?
    thank you in advance, Kostas

    Is it possible within the SessionBean method to
    call another Session Bean, create it using the
    local interface, pass some parameters using setter
    methods, then cast it from local interface to
    remote and send it to the user?I think it's not possible casing Local Interface into Remote Intrface, because they inherit from different classes.
    Remote interface extends EJBObject and Local interface extends EJBLocalObject
    Fil

  • Can java method return  multiple values

    hey , I need big favor can i return two arrays in a single function

    Not directly no.
    But there are ways around it.
    You can create a "result object" which has attributes being the two arrays, and return that object (ie wrap the arrays in another object)
    You could put the arrays into a collection (eg ArrayList/Vector) and then return that object. You can then retrieve the two arrays as the first two items in that list.
    Either of those should work, even if they are hacks ;-)
    Cheers,
    evnafets

  • The class of the deferred-methods return type "{0}" can not be found.

    I am developing a multilingual portal application.
    I have the method that changes the locale based on user's choice in the bean and the method is being referred to as below.
    <af:selectOneChoice label="Select Language" autoSubmit="true"
    value="#{localeBean.locale}"
    valueChangeListener="localeBean.changeLocale">
    <af:selectItem label="English" value="en" id="si1"/>
    <af:selectItem label="French" value="fr" id="si2"/>
    <af:selectItem label="Dutch" value="nl" id="si3"/>
    </af:selectOneChoice>
    when i try to run the application, i am getting compile time errors as below,
    The class of the deferred-methods return type "{0}" can not be found.
    No property editor found for the bean "javax.el.MethodExpression".
    After going through the discussion forums i learned that the compilation errors can be resolved by setting the <jsp:directive.page deferredSyntaxAllowedAsLiteral="false> at the starting of the page.
    Even after that i am getting the compilation error.
    Any solutions, suggestions or possible approaches would be helpful as i am new to Webcenter Portal development.
    Thanks,

    The error you get points to a problem on the page (somewhere). Switch to source mode and check the right margin if you see orange or red marks. These are pointing to problems (not all are show stoppers, but they give you hints that something is not according to the standard for jsf, jsff, jsp or jspx pages.
    Have you checked that the bean is correctly defined and that it's reachable?
    Start a fresh page and isolate the problem, e.g. build a selectOneChoiuce on the new page (don't copy it as you might copy the error too) and make it work on the new page. Once you have it running you can compare the solution to your not running page.
    Timo

  • Returning a HashMap K, M from a method of a class typed M

    So, this is what I have. I have a class parameterized for a bean type of a collection it receives, and in a method of the class, I need (would like) to return a HashMap typed as <K, M> as in:
    public class MyClass<M> {
       private Collection<M> beanList;
       public HashMap<K, M> getMap(  /* what do I do here */ );
    }I tried to cheat from looking at the Collections.sort method, knowing it uses the List type in its return type as in:
    public static <T extends Comparable<? super T>> void sort(List<T> list)So, I am trying:
    public HashMap<K, M> getMap(Class<K> keyType)But, it is telling me I need to create class K.
    So... how does the Collections.sort method get away with it and I can't????
    I suppose I could write the method as:
    public HashMap<Object, M> getMap()but became somewhat challenged by my first guess.
    Any ideas... or just go with the HashMap with the untyped key?

    ejp wrote:
    provided K is inferable from the arguments.Or from the assignment context:
    Set<String> empty = Collections.emptySet();
    Otherwise you have to parameterise the class on <K, M>.You may also specifically provide K when you use the method if the context doesn't give the compiler enough information or if you want to override it.
    Example:
    Set<Object> singleton1 = Collections.singleton("Hello"); //error
    Set<Object> singleton2 = Collections.<Object>singleton("Hello"); //fineEdited by: endasil on 14-May-2010 4:13 PM

  • Changing an object by calling a method in another class that returns nothin

    How can a method like for example Arrays.sort(Object[] a) work? The method has a return statement void, so how come the array passed into the method "magically" end up as being sorted when we look at it in another class after having called this method?

    jverd wrote:
    sunfun99 wrote:
    Since references really are more like addresses, jverd's adress-on-pieces-of-paper analogy is the best, but certainly not because the addresses on the pieces of paper are copies of the address (they aren't). We may just be splitting ever finer semantic hairs here, but how is it not a copy of the address?It is a finely split hair - and ultimately just a difference of language use, I think.
    We scribble on pieces of paper and thereby have at least two things to deal with: the scribble, and the location. It is unfortunate, but in English both things are referred to as "the address". The scribble has qualities like "red", "legible" etc, the location has qualities like "distant", "next door to the president": so they do seem to be different things.
    We use "address" for both: "I can't read this address" vs "Go to this address". Children make jokes based on the ambiguity: "How do you spell it."
    But then there's a third thing: the denotation of the location by the scribble. (denotation here == reference/pointing-at/leash/stick etc). It really does seem to be a third thing. (With apologies to Jean Buridan) consider a person who has lat/long coordinates explained to them for the first time and is handed a piece of paper with coordinates on it. They are asked "Do you know who lives here?" and they answer "Yes, I know the person at this address!". Most would say the statement is false - even if it turns out they were handed their own address. Their assertion of knowledge is an assertion about the denotation of the location by the coordinates, not about the location itself.
    So what is copied by a scribe or a photocopy machine when it copies an address? Clearly it's the scribble, not the location. The scribble is duplicated, the location is not. But what about the denotation of the location by the scribble? Not withstanding the above example (and especially in contexts where knowledge and similar concepts are not involved), you could say that the denotation of the location by the scribble is a value. In other words you could hold that two denotations of some location are not just equal but identical iff they denote the same location. (You could, but you needn't.) It is in this sense that the pieces of paper bear, not copies of the address, but the same address.
    (Exactly the same applies to "pointers" ie signposts. If you have two "north pole" signs (1) The are different signs (2) They point to the same place (3) They are two signs bearing one and the same reference.)
    Edited by: pbrockway2 on Mar 15, 2009 12:49 PM

  • WSIF - Can we return java class back to bpel (PLEASE HELP)

    Scenario : We have old project and migrating to Oracle BPEL.
    In this project we have Java Files and inside that java files we have many functions which return java object. Is it possible to return java value object to bpel process.
    Steps which i have followed:
    1. Created a WSDL file using the control file given below.
    2. Changed the name spaces and types generated to XFMFRq and TXNLog as i/p and o/p.
    3. Imported same file into oracle bpel.
    4. Called the function : logbegin.
    EXCEPTION : The types are not compactable is the exception we are getting but we are able to call the function and execute first line but not able to return TXNLOG class as an xml element to bpel.
    For Example :
    1. Java Method and this method returns Java Value Object
    Java Control which has TXNLOG as the value object which will return the value.
    CONTROL FILE
    public TxnLog logBegin(com.hp.rtfs.xfmf.doc.XFMFRqDocument requestXML)throws Exception
    //LogUtil.logDebug(LogConstants.MODULE_BPM,BPM_CONTROL_NAME,"Enter Method logBegin ");
    txnLog=new TxnLog();
    try
    System.out.println("AMMA1121212");
    LogUtil.logDebug(LogConstants.MODULE_BPM,BPM_CONTROL_NAME,"Entering Top user id update in LogBegin");
    txnLog.setTlogChannelLoginId("AMMA1");
    txnLog.setTlogChannelUserId("AMMA2");
    System.out.println("AMMA2");
    txnLog.setTlogChinChannelId("ATM");
    txnLog.setTlogChannelSessionId("SESSION-1111");
    System.out.println("AMMA3");
    txnLog.setTlogCustCifKey((new Long("121212")));
    txnLog.setTlogEmtnTxnCd("TXN-001");
    System.out.println("AMMA4");
    txnLog.setTlogSendIpAddr("10.1.1.1");
    txnLog.setTlogChannelTxnSeqId(new Integer("1212"));
    System.out.println("AMMA5");
    TxnLogPK txnLogPk=new TxnLogPK(new Integer("121212"),
    DateUtil.getDate(requestXML.getXFMFRq().getMsgRqHdr().getUID().getRTFSTransSeqUIDDt()),"1212");
    txnLog.setTxnLogPK(txnLogPk);
    System.out.println("AMMA6");
    catch(Exception e)
    //LogUtil.logError(LogConstants.MODULE_BPM,BPM_CONTROL_NAME,"Exception "+e.getMessage());
    e.printStackTrace();
    return txnLog;
    TXN LOG value object is :
    // Oracle JDeveloper Stub Generated Source
    package com.hp.rtfs.ods.infra.trx;
    public class TxnLog
         implements java.io.Serializable
         // Constructors
         public TxnLog(com.hp.rtfs.ods.infra.trx.TxnLogPK p1, java.lang.Long p2, java.lang.String p3, java.util.Calendar p4, java.lang.String p5, java.lang.String p6, java.lang.String p7, java.lang.String p8, java.lang.String p9, java.lang.Integer p10, java.util.Calendar p11, java.lang.String p12, com.hp.rtfs.ods.infra.channel.ChannelInfo p13, java.util.Set p14) { }
         public TxnLog() { }
         public TxnLog(com.hp.rtfs.ods.infra.trx.TxnLogPK p1, java.util.Set p2) { }
         // Fields
         private com.hp.rtfs.ods.infra.trx.TxnLogPK TxnLogPK;
         private java.lang.Long tlogCustCifKey;
         private java.lang.String tlogEmtnTxnCd;
         private java.util.Calendar tlogStartDt;
         private java.lang.String tlogStat;
         private java.lang.String tlogSendIpAddr;
         private java.lang.String tlogChannelUserId;
         private java.lang.String tlogChannelLoginId;
         private java.lang.String tlogChannelSessionId;
         private java.lang.Integer tlogChannelTxnSeqId;
         private java.util.Calendar tlogEndDt;
         private java.lang.String tlogChinChannelId;
         private com.hp.rtfs.ods.infra.channel.ChannelInfo channelInfo;
         private java.util.Set txnLogDatas;
         // Methods
         public com.hp.rtfs.ods.infra.trx.TxnLogPK getTxnLogPK() { }
         public void setTxnLogPK(com.hp.rtfs.ods.infra.trx.TxnLogPK p1) { }
         public java.lang.Long getTlogCustCifKey() { }
         public void setTlogCustCifKey(java.lang.Long p1) { }
         public java.lang.String getTlogEmtnTxnCd() { }
         public void setTlogEmtnTxnCd(java.lang.String p1) { }
         public java.util.Calendar getTlogStartDt() { }
         public void setTlogStartDt(java.util.Calendar p1) { }
         public java.lang.String getTlogStat() { }
         public void setTlogStat(java.lang.String p1) { }
         public java.lang.String getTlogSendIpAddr() { }
         public void setTlogSendIpAddr(java.lang.String p1) { }
         public java.lang.String getTlogChannelUserId() { }
         public void setTlogChannelUserId(java.lang.String p1) { }
         public java.lang.String getTlogChannelLoginId() { }
         public void setTlogChannelLoginId(java.lang.String p1) { }
         public java.lang.String getTlogChannelSessionId() { }
         public void setTlogChannelSessionId(java.lang.String p1) { }
         public java.lang.Integer getTlogChannelTxnSeqId() { }
         public void setTlogChannelTxnSeqId(java.lang.Integer p1) { }
         public java.util.Calendar getTlogEndDt() { }
         public void setTlogEndDt(java.util.Calendar p1) { }
         public java.lang.String getTlogChinChannelId() { }
         public void setTlogChinChannelId(java.lang.String p1) { }
         public com.hp.rtfs.ods.infra.channel.ChannelInfo getChannelInfo() { }
         public void setChannelInfo(com.hp.rtfs.ods.infra.channel.ChannelInfo p1) { }
         public java.util.Set getTxnLogDatas() { }
         public void setTxnLogDatas(java.util.Set p1) { }
         public java.lang.String toString() { }
         public boolean equals(java.lang.Object p1) { }
         public int hashCode() { }
    ---------------------------------------------------------------------------

    I have been bragging to my clients the benefits of
    Java Applications, but one thing I couldn't convince
    them is the use of a JVM. They dislike the idea of
    downloading the JRE, and the slowness of programs
    running in an interpreter. I am stumped for not being
    able to satisfy their need for a .EXE program on their
    Win32 systems. And, it would be ridiculous to go back
    again to C++, after learning Java. I'm not going to address the JRE distribution as it's already been mentioned and there are several ways of approaching that problem that you can find easily in the forum so I won't waste space for it here.
    What you need to address more than anything is the supposed slowness of java programs. The question at hand is slow as compared to what? In what context? A benchmark can be twisted to show whatever the author of the report wants it to show. Thus I tend to distrust such statistics in general due to the economical influence of the author or comissioner of the report being in the business of trying to sell something. Exactly what are they calling slow and what causes this perception on their part? I wouldn't sidestep the issue, or try to B.S. about it, but I'd be willing to bet that their fears are unfounded and based on superstition and hearsay.
    >
    Is their a tool or a way to convert .CLASS files into
    .EXE(Win32) files, to make it execute faster and
    independent? I know it would sacrifice portability,
    but I have to give in to demands. As they say it,
    "The customers are always right." Please, anybody out
    there, shed some light for me on this one. Thanx in
    advance.
    BlueKnyght.ph

  • Creating  a static method returning Logger Object inside class

    Hello,
    Instead of creating Logger Instance in every class , can i do like this way by creating a static method in some class returning a Logger object , and using that method for getting instance of Logger in another class through that method
    Regards
    Mayur Mitkari

    On a related note, if you want to make it simpler, never do this:
    if (a == true)Instead, just do if (a)It's pointless and cluttersome to use == or != with true or false.
    // wrong
    if (a == true)
    if (a != false)
    // right
    if (a)
    // wrong
    if (a == false)
    if (a != true)
    // right
    if (!a)Also, note that
    if (x) {
      return true;
    else {
      return false;
    }can be simplified to return x;If you do that and change your variable to something a bit more meaningful, like trueCount or numTrue or something, your code would be
    int trueCount = 0;
    if (a) trueCount++;
    if (b) trueCount++;
    if (c) trueCount++;
    return trueCount >= 2;which is about as simple and clear as it can get, IMHO. Using less code doesn't necessarily make the code simpler or clearer. The idea is that someone reading the code can easily understand what it does.
    And note that the above can be easily generalized to "Are there at least M true values in this array/list of N booleans?" and still be concise and clear.

  • Why method local inner class can use final variable rather than....

    Hi all
    Just a quick question.
    Why method-local inner class can access final variable defined in method only?
    I know the reason why it can not access instance variable in method.
    Just can not figure out why??
    any reply would be appreciated.
    Steven

    Local classes can most definitely reference instance variables. The reason they cannot reference non final local variables is because the local class instance can remain in memory after the method returns. When the method returns the local variables go out of scope, so a copy of them is needed. If the variables weren't final then the copy of the variable in the method could change, while the copy in the local class didn't, so they'd be out of synch.

  • Can't add list element when calling a method from another class

    I am trying to call a method in another class, which contains code listmodel.addElement("text"); to add an element into a list component made in that class.
    I've put in System.out.println("passed"); in the method just to make sure if the method was being called properly and it displays normally.
    I can change variables in the other class by calling the method with no problem. The only thing I can't do is get listmodel.addElement("text"); to add a new element in the list component by doing it this way.
    I've called that method within it's class and it added the element with no problem. Does Java have limitations about what kind of code it can run from other classes? And if that's the case I'd really like to know just why.

    There were no errors, just the element doesnt get added to the list by doing it this way
    class showpanel extends JPanel implements ActionListener, MouseMotionListener {
           framepanel fp = new framepanel();
           --omitted--
         public void actionPerformed(ActionEvent e){
                  if(e.getSource() == button1){
                       fp.addLayer();
    /*is in a different class file*/
    class framepanel extends JPanel implements ActionListener{
            --omitted--
         public void addLayer(){
              listmodel.addElement("Layer"+numLayer);
              numLayer++;
    }

  • Can we use SAMT to syntax check methods in global classes ?

    Transaction SAMT can be used to perform syntax checks on programs but I can't see how to use it to check methods in global  classes. Can anyone tell me how to do this ?
    thanks,
    Malcolm.

    I've figured out a way to do this.
    You need to put the class name followed by '=====CP' into the program name......with enough ='s to make the name up to 32 characters. Bit fiddly but it can be done.

Maybe you are looking for

  • Stock Avaliability Before Billing

    I want the system to automatically check stock quantity when Billing so that i won't over bill the customer or sell what i dont have. eg i have 20 cartons of vimto (Finished Product) in stock and unknowing to me i have raised sales order for 21 carto

  • Tracking and managing PDF reviews

    This question was posted in response to the following article: http://help.adobe.com/en_US/acrobat/using/WS98D212C7-4991-427e-B0F9-F459485AEAC5.w.html

  • Whats the purpose of reason codes?

    Hi Experts, In many scenarios we add reason codes e.g. all the actions like terminations, new hire, rehire, change in position etc. Now our organization is adding a new reason code for termination action with reason code "termination due to LOA".  An

  • How to make a total restore of my Mac Mini?

    I need to start over and I want to reinstall Mac OS, but  I don't have Mac OS on CD/DVD. Need help!

  • Installing SAP ERP6 EHp4on Solaris 10 ,oracle 10g

    Hello gurus i am planning to install SAP ERP6 EHP4on SOLARIS 10 Sparc,Oracle 10g So i have 3 questions that i need a bit clarified although i went thro the inst guide 1.Will the install  or sapinst ask me to create the oracle directories and  sapdata