Where do I declare my objects?

I've never understood where to instantiate/construct/declare? my objects. For example when making a JFrame I could put
JFrame frame;
at the top of the program and the in the main class put
frame = new Frame();
or I could just put
JFrame frame = new JFrame();
Which one do I use and in what situation?

You could theoratically do both. Because it really depends on the scope of how you want to use your object.
For example, for the following code... You can subsequently use the xxx Object in xxxMethod2()....
public class NewClass {
     private Object xxx;
     public void xxxMethod() {
          xxx = new Object();
     public void xxxMethod2() {
}But for the following code... you can't use xxx in xxxMethod2()... since the scope of the object already ends in xxxMethod().
public class NewClass {
     public void xxxMethod() {
          Object xxx = new Object();
     public void xxxMethod2() {
}I hope i've made it simple enough for you to understand.

Similar Messages

  • How to set Where clause in the View Object of the MessageChoice ?

    Hi,
    How to set Where clause in the View Object of the
    MessageChoice ?
    Example:
    <bc4j:rootAppModuleDef name="EdEscolaCampusView1AppModule"
    definition="ed00050.Ed00050Module"
    releaseMode="stateful" >
    <bc4j:viewObjectDef name="EdEscolaCampusView1" >
    <bc4j:rowDef name="CreateEdEscolaCampusView1" autoCreate="true" >
    <bc4j:propertyKey name="key" />
    </bc4j:rowDef>
    </bc4j:viewObjectDef>
    <bc4j:viewObjectDef name="ListaTipLocalView1"
    rangeSize="9999">
    </bc4j:viewObjectDef>
    </bc4j:rootAppModuleDef>
    </bc4j:registryDef>
    messageChoice declaration:
    <bc4j:messageChoice name="SeqTipoLocalCampus"
    attrName="SeqTipoLocalCampus"
    prompt="Local do Campus">
    <contents>
    <bc4j:optionList attrName="SeqTipoBasico"
    textAttrName="NomTipoBasico"
    voName="ListaTipLocalView1"/>
    </contents>
    </bc4j:messageChoice>
    I would like set where clause of ViewObject, with dinamic parameters (using attribute1 = :1), before populate messageChoice.
    thanks...
    Danilo

    Hi Andy,
    I try set a where clause using the message:
    Set where Clause parameter using UIX , but my UIX Page have 2 messageChoice's of different ViewObject's, then I need implement this Java Class:
    //Nome da Package da Tela Detail
    package br.com.siadem.siaed.ed00050;
    // Importa as Bibliotecas necessárias
    import oracle.jbo.ViewObject;
    import oracle.jbo.ApplicationModule;
    import oracle.jbo.client.Configuration;
    import oracle.cabo.servlet.BajaContext;
    import oracle.cabo.servlet.Page;
    import oracle.cabo.servlet.event.PageEvent;
    import oracle.cabo.servlet.event.EventResult;
    import oracle.cabo.data.jbo.servlet.bind.*;
    import oracle.cabo.ui.data.BoundValue;
    import oracle.cabo.ui.data.DataBoundValue;
    import javax.servlet.http.HttpServletRequest;
    import br.com.siadem.siaed.util.*;
    import javax.servlet.http.Cookie;
    import oracle.cabo.data.jbo.def.NestedAppModuleDef;
    import oracle.cabo.data.jbo.def.ViewObjectDef;
    import oracle.cabo.data.jbo.def.AppModuleDef;
    // Classe que configura os parametros para a execução da Query,
    // utilizando variáveis de Sessao
    public class FunPreQueryLista
    public static EventResult FunConfiguraQuery(BajaContext context, Page page, PageEvent event) throws Throwable
    // TrataDadosSessao - Classe utilizada para retornar os valores das variáveis de sessão genéricas
    // Ex: CodCliente, CodMunicipio etc...
    TrataDadosSessao varDadosSessao = new TrataDadosSessao();
    // 1o. Parametro Configurado - Através da classe TrataDadosSessao, utilizando um método Get
    // <alterar>
    String valor1 = varDadosSessao.getCodCliente();
    String valor2 = varDadosSessao.getCodMunicipio();
    //Cria o objeto que retorna o ApplicationModule
    ApplicationModule am = ServletBindingUtils.getApplicationModule(context);
    // Início das Configurações da Query da Lista
    //Cria o objeto que retorna o view object da lista desejada
    //alterar
    ViewObject TipoLocal = am.findViewObject("ListaTipoLocalView1");
    //Configuração dos parametros definidos na query do view Object
    //alterar
    TipoLocal.setWhereClauseParam(0,valor1);
    TipoLocal.setWhereClauseParam(1,valor2);
    // Executa a Query
    TipoLocal.executeQuery();
    // Fim das Configurações da Query da Lista
    // Início das Configurações da Query da Lista
    //Cria o objeto que retorna o view object da lista desejada
    //alterar
    ViewObject TipoDestLixo = am.findViewObject("ListaDestinoLixoView1");
    //Configuração dos parametros definidos na query do view Object
    //alterar
    TipoDestLixo.setWhereClauseParam(0,valor1);
    TipoDestLixo.setWhereClauseParam(1,valor2);
    // Executa a Query
    TipoDestLixo.executeQuery();
    // Fim das Configurações da Query da Lista
    // Retorna o Resultado para a Página
    return new EventResult(page);
    The code works very well...
    And, I'm sorry for my two repost's in UIX Forum about this in a few time.
    Thank very much...
    Danilo

  • JSP, Data Web Bean, BC4J: Setting the where clause of a View Object at run time

    Hi,
    I am trying to develop a data web bean in which the where clause of a View Object will be set at run time and the results of the query then displayed.
    My BC4J components are located in one project while the coding for the data web bean is in another project. I used the following code bu t it does not work. Could you please let me know what I am doing wrong?
    public void populateOSTable(int P_EmpId)
    String m_whereString = "EmpView.EMP_ID = " + P_EmpId;
    String m_OrderBy = "EmpView.EMP_NAME";
    oracle.jbo.ApplicationModule appModule = null;
    ViewObject vo = appModule.findApplicationModule("EMPBC.EMPAppModule").findViewObject("EMPBC.EMPView");
    vo.setWhereClause(m_whereString);
    vo.setOrderByClause(m_OrderBy);
    vo.executeQuery();
    vo.next();
    String empName numAttrs = vo.getAttribute(EmpName);
    System.out.println(empName);
    Thanks.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by JDev Team (Laura):
    Here is how I have usually done mine:
    1. In the JSP, use a RowsetNavigator bean to set the where clause and execute the query.
    2. Use a custom web bean to process the results of the query (print to HTML).
    for example:
    <jsp:useBean class="oracle.jbo.html.databeans.RowsetNavigator" id="rsn" scope="request" >
    <%
    // get the parameter from the find form
    String p = request.getParameter("p");
    String s = request.getParameter("s");
    // store the information for reference later
    session.putValue("p", p);
    session.putValue("s", s);
    // initialize the app module and view object
    rsn.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
    // set the where clause string
    String theclause = "presname = '" + p + "' AND slideno=" + s;
    // set the where clause for the VO
    rsn.getRowSet().getViewObject().setWhereClause(theclause);
    rsn.getRowSet().getViewObject().executeQuery();
    rsn.getRowSet().first();
    %>
    </jsp:useBean>
    <jsp:useBean class="wt_bc.walkthruBean" id="wtb" scope="request" >
    <%
    // initialize the app module and VO
    wtb.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
    wtb.render();
    %>
    In this case, the render method of my custom web bean mostly gets some session variables, and prints various content depending on the session variable values.
    Hope this helps.
    </jsp:useBean><HR></BLOCKQUOTE>
    Laura can you give the code of your walkthru bean? i wna't to initialize a viewobject, set the where clause and give that viewobject back to initialize my navigatorbar.
    Nathalie
    null

  • So how do you declare an object?

    Okay I have a program I'm trying to build that lets me navigate between menus...
    Main Menu starts up:
    (Unimportant)
    Then it takes me to another Menu.
    When this is over I want to go back:
       System.out.println("Select: ");
            System.out.println("1: to Return to the main menu");
            System.out.println("or");
            System.out.println("0 to Exit");
         if(input.nextInt()==1){
             main(); // <-- error here
         else if(input.nextInt()==0){
             System.exit(0);
            }   It doesnt find the main method because I didn't declare it as an object at the top...
    How do I do that?
    Edited by: tark_theshark on Mar 30, 2008 5:24 AM

    Nah, this has nothing to do with declaring an object, and you really don't want to do this. What you really want to do is to have a loop of some kind, say a while loop and have the loop repeat until the user presses "0". Something like so:
        public static void main(String[] args)
            boolean done = false;
            while (!done)
                if(input.nextInt() == 0)
                    done = true;
        }Edited by: Encephalopathic on Mar 30, 2008 6:27 AM

  • Where is ldap_parse_result declared

    In Identity Management Application Developer's guide, ldap_parse_result is a clearly documented API. However, I could not find the function prototype defined anywhere. It is not in ldap.h. Where is it declared?

    I don't see anything obviously wrong in your code. Try adding
    session.setDebug(true);
    You can use the same Session for sending and for reading.
    A Session just encapsulates your configuration parameters,
    so as long as they're the same for both usages, one Session
    is fine.

  • Can anyone tell me where to download the Business Objects LiveOffice Plugin

    Can anyone tell me where to download the Business Objects LiveOffice Plugin
    Thanks
    Jeff

    Hi Jeff,
    If you have installed Business Objects Enterprise XI R2 on your machine from CD, follow the steps to install the Live Office,
    1. Navigate to the Add-Ons\Live Office folder on the BusinessObjects Enterprise collaterals CD or locate the Live Office setup.exe file on your network.
    2. Double-click setup.exe to launch the Live Office Installation Wizard.
    3. Follow the on-screen instructions in the Live Office Installation Wizard to complete the installation procedure.
    You can also download the collaterals for Business Objects Enterprise XI R2 by logging in the service.sap.com and following the following steps,
    1. Click on the SAP Support Portal link, and then go to Downloads Tab and click on the 'SAP Software Distribution Center'.
    2. In the middle of the page you will get the 'Search for Software' link, click on that link.
    3. In the Search type 'Collaterals' and click search.
    4. You will get the Collaterals for BOBJ Enterprise XI R2 SP2 and SP4 for Windows.
    Hope this resolves your issue.
    Regards,
    Abhijeet T.

  • Puzzle about declare List object

    Why we declare a object using "List list=new ArrayList();" other than "ArrayList list=new ArrayList();"?I have seen in Java API that:"Source source=new StreamSource();" other than "StreamSource souce=new StreamSource();".Is there any advantages to do this?

    just gives you more flexibility when you may possibly change the instance of the object being created.... more like the Factory patteren....
    hmmm.... i dont think im making much sence here.... :O)) let me explain with an example....
    the return type of Calendar.getInstance() is Calendar while internally it actually returns an instance of GregorianCalendar which is a sub-class of the Calendar class... the reason to that all the methods that you want are available in the Calendar class, & if a couple of version down the road if the API changes to return an instance of some other sub-class of Calendar, anyone using it would not be effected....
    BUT if in your case you are using specific methods that are only available in the ArrayList and not in the List class.... then you would be better off using ArrayList list=new ArrayList()....
    hope this explains to some extent
    regards
    omer

  • Where is it declared the return variable?

    Hi everyone,
    please which system privileges must you have to recompile a stored procedure owned by another application developer?
    and where is it declared the return variable?
    thank you

    In short you will need ALTER ANY PROCEDURE privilidge for that.
    Lets do a test for this:
    From User A:
    SQL> create table test as select * from user_objects where rownum<10;
    SQL> create procedure test_proc as
    2 begin
    3 delete test;
    4 commit;
    5 end;
    6 /
    Procedure created.
    Now from User Scott:
    alter procedure cr.test_proc compile
    ERROR at line 1:
    ORA-01031: insufficient privileges
    Now connect to user A and do the following:
    1* grant alter any procedure to scott
    SQL> /
    Grant succeeded.
    Now from Scott user:
    alter procedure cr.test_proc compile;
    Procedure altered.
    SQL> show errors
    No errors.
    Thats what you wanted.
    Riaz

  • Declaring an object

    I have a class (lets say it innerClass) which is nested inside the main. I have a method which has been used defined another class. Now, i want to create an object of the class which contains the method definition and use it in the innerClass which is inside main. How can i do it?
    Heres a sample code:
    Class A
    method m()
    some code;
    public static void main(String [] args)
    display.asyncExec(new Runnable() ) //Innerclass
    want to use the method here;
    Now where do i create and with what do i initialize it?
    Edited by: iconabhi on Nov 30, 2007 8:51 PM

    If it's not evident to you where and how your object should be constructed, you probably don't need an instance of that object. You should make the method static and call it statically, with A.m().
    Now, if what you have is multiple classes (say A, B, C, D) implementing the same interface I, and m() is declared in I, then that's a different story. That's closer to the Strategy pattern that petes mentioned. However even with the strategy pattern, the whole point is that you would just have some object of type I supplied to you from the outside caller or a factory method. So it seems more likely that you just need a static method.

  • Declarative java object cache in non oc4j container

    hello,
    i'm trying to use the cache.jar from 10g in a standalone application.
    i've followed the j2ee services guide and use cache.open(path_to_javacache.xml). javacache.xml has preload-file defined, in which i've declared my userdefined classloader and userdefined cached object. the implementations of both implement declarable. however,when i use cacheaccess.getaccess(region_name) i get regionnotfoundexception.
    i've also tried to use the configurator alternative, where i specify the declarative cache xml file. but this gives me a classcastexception.
    any suggestions. better yet is there a sample program that
    shows the use of a decl cache in a non oc4j container.
    thanks

    Hi,
    I ran into the same problem while evaluating OC4J V9 Java Cache standalone.
    Cache.open() silently ignores errors:
    * Cache.open(path_to_javacache.xml) seems to silently swallow alle error messages (in your case the ClassCastException) and the ignore the configuration file
    * so to get meaningful error messages, first attempt to open the file with new Configurator(path_to_javacache.xml)
    * once there are no more errors, you can open it with Cache.open(path_to_javacache.xml)
    Now, to get around the ClassCastException:
    * you need to add xmlparserv2.jar from your oc4j distribution
    * this must be the first xml-parser in your classpath (when e.g. xerces.jar comes first, you will get a ClassCastException)
    A relative javacache.xml is relative to your working directory.
    The preload-file - Path seems to be relative to the javacache.xml path, if it is not absolute. I keep javacache.xml and preload-file together which worked for me.
    Hope this help,
    Andreas

  • Where used list for business objects in TM

    Hi,
    There is a where used list framework in TM7 for
    Transportation Zone, Lane etc.  Is it possible to include the same for TCM business objects like
    FA, Tariff, TCCS, Rate Table, Scale etc.  Is it possible to do the customization?
    Thanks and regards,
    Suresh.

    Hi
    The following may of useful to you.
    https://wiki.sdn.sap.com/wiki/display/ESpackages/IntegrationofTransportationManagementSystemBusinessObjects
    Regards
    Shan

  • How to get the "where used" of a portal object.

    Hi folks!
    I'm coding a program to get the list of the portal objects where a specific portal object (an iView  for example) is used. I found the method getWhereUsedList from IPcdContext but I'm getting some errors.
    Is this the best/correct way to get a "where used list"?
    Does anyone have an example of how to use this method correctly?
    Thanks in advance.
    Geraldo.

    Hi Tanja, thank you very much for your attention.
    Following your tips I figured out that the error was occurring during the casting and not during the getWhereUsedList method call. Now, I'm casting to Object. I'd like to cast to a more proper class. During my tests I got an error that showed me that the cast should be to a PcdGlSearchResult class. I couldn't find any javadoc for this class and when I changed the cast to this class I started to get a execution class load  error. Please let me know if you have any advice regarding the casting.
    private void getWhereUsed1(IPortalComponentRequest request, String id, StringBuffer sb) {
    InitialContext iCtx = null;
    Object objectId = null;
    String tString = null;
    Hashtable env = null;
    IPcdContext result = null;
                         env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
    env.put(Context.SECURITY_PRINCIPAL, request.getUser());
    env.put(Constants.REQUESTED_ASPECT, IPcdAttribute.PERSISTENCY_ASPECT);
    try {
    iCtx = new InitialContext(env);
    result = (IPcdContext) iCtx.lookup(id);
    for (NamingEnumeration ne = result.getWhereUsedList(""); ne.hasMoreElements();) {
    objectId = (Object) ne.nextElement();
    tString = objectId.toString();
    sb.append(tString + CR);
    } catch (Exception e) {
    StackTraceElement[] elements = e.getStackTrace();
    for (int i = 0; i < elements.length; i++)
    sb.append(elements<i> + CR);

  • Where to find IDs for Object-Tag?

    Hello!
    I wrote an application that should use every java-plugin starting with version 1.2.x (preferable 1.2.0) and up in IE, but I don't know where I could find the IDs I have to place in the Object-Tag.
    Does anybody where to get information where to find this?
    Thanks in advance, lg Clemens

    http://www.google.nl/search?hl=nl&q=site%3Asun.com+%22object+tag%22&btnG=Google+zoeken&lr=
    Allthogh there is an explenation about static and dynamic versioning on the first and
    second hit , a list of classid for each version (dynamic versioning) is missing on all
    hits.

  • Where is the instane of object stored in memory

    hello all,
    this is the question asked me in an interview.
    when we create an instance of an object or a variable.
    where is that instance is stored in memory?
    where are the static, final, instance variables are stored in memory?
    thanks in advance
    raghu mohan

    Yes, its handled by JVM. there is heap memory n stack memory something is available.
    where is it actually stored?
    where will the JVM resides in memory?
    thanks in advance
    raghu

  • Urgent: Where to write HFM API objects coding in consolidation?

    Hi,
    I want to write a code on HsvProcessFlow library object to make some customized changes. But wondering where should i write this code. Is rules editor is the place where i should write the code. Please help me on this.
    Regards,
    Arvind

    Hi,
    I want to write a code on HsvProcessFlow library object to make some customized changes. But wondering where should i write this code. Is rules editor is the place where i should write the code. Please help me on this.
    Regards,
    Arvind

Maybe you are looking for