Why some instance variables are passed to current contructor ..

I wonder why some instance attributes are passed to contructor like
publi class A{
private int numberone;
public FileReader fr;
public BufferedReader br;
public A(FileReader fr,BufferedReader br){
this.fr = fr;
this.br=br;
You see int numberone is not passed but we can still use. why we can not do same with the FileReader and Buffer object? please explane
Thank very much
Jorg3

Deos anyone have a clue why this hapens?
Thanks a lot
Jorg3
Error: C:\LookupServer.java(30): Incompatible type for =. Can't convert int to java.lang.String.
while((line=br.read())!=null)save.addElement(line);
fr = new FileReader(file_name);
br = new BufferedReader(fr);
String line =" ";
while((line=br.read())!=null)save.addElement(line);
for(int i = 0; i<save.size();i++)
String k = (String)save.elementAt(i);
System.out.println(k);
}catch(Exception e){
System.out.println(e.toString());

Similar Messages

  • Some Out-Variables are not filled when one is missing (Oracle-Client 10)

    Hello everybody,
    we have a problem in our applications, written in C++ using OCI.
    All works fine with Oracle Client 8 and 9, the problem occurs when using Client 10.
    A simple example:
    select 1, 2, 3, 4, 5 from dual;
    I have 4 out-variables, the 3rd one is missing:
    OCIDefineByPos(..., 1, &out1, ...);
    OCIDefineByPos(..., 2, &out2, ...);
    OCIDefineByPos(..., 4, &out4, ...);
    OCIDefineByPos(..., 5, &out5, ...);
    When executing with Oracle Client 8 and 9, the result is:
    out1 = 1
    out2 = 2
    out4 = 4
    out5 = 5
    Executing the same with Oracle Client 10, the result is:
    out1 = 1
    out2 = 2
    out4 = 0
    out5 = 0
    When there is a selected column without a variable for it, all following out-variables are not filled. Can someone repeat and / or explain this? I read the Oracle Docs for the OCI 10, but nowhere is a hint about differences or changes in this behaviour. I know that when selecting a column I should spend an out-variable for it, but nobody is perfect.
    Here are some details:
    Oracle Client 10.2.0.1.0
    Client OS Windows XP SP1
    Oracle Database 10g Release 10.2.0.1.0
    Application developed with Visual Studio C++ 7.1
    Thanks for any help.
    Torsten
    Here's the code, I changed the simple OCI-example from the Oracle homepage:
    void ocitest()
    static text username = (text ) "xxx";
    static text password = (text ) "yyy";
    static OCIEnv *envhp;
    static OCIError *errhp;
    static sword status;
    sword out1, out2, out3, out4, out5;
    sb2 ind1, ind2, ind3, ind4, ind5; /* indicator */
    static text maxemp = (text ) "SELECT 1, 2, 3, 4, 5 FROM dual ";
    OCISession authp = (OCISession ) 0;
    OCIServer *srvhp;
    OCISvcCtx *svchp;
    OCIStmt stmthp, stmthp1;
    OCIDefine defnp1 = (OCIDefine ) 0;
    OCIDefine defnp2 = (OCIDefine ) 0;
    OCIDefine defnp3 = (OCIDefine ) 0;
    OCIDefine defnp4 = (OCIDefine ) 0;
    OCIDefine defnp5 = (OCIDefine ) 0;
    (void) OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0,
    (dvoid * (*)(dvoid *, size_t)) 0,
    (dvoid * (*)(dvoid *, dvoid *, size_t))0,
    (void (*)(dvoid *, dvoid *)) 0 );
    (void) OCIEnvInit( (OCIEnv **) &envhp, OCI_DEFAULT, (size_t) 0,
    (dvoid **) 0 );
    (void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &errhp, OCI_HTYPE_ERROR,
    (size_t) 0, (dvoid **) 0);
    /* server contexts */
    (void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &srvhp, OCI_HTYPE_SERVER,
    (size_t) 0, (dvoid **) 0);
    (void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &svchp, OCI_HTYPE_SVCCTX,
    (size_t) 0, (dvoid **) 0);
    (void) OCIServerAttach( srvhp, errhp, (text *)"", strlen(""), 0);
    /* set attribute server context in the service context */
    (void) OCIAttrSet( (dvoid *) svchp, OCI_HTYPE_SVCCTX, (dvoid *)srvhp,
    (ub4) 0, OCI_ATTR_SERVER, (OCIError *) errhp);
    (void) OCIHandleAlloc((dvoid *) envhp, (dvoid **)&authp,
    (ub4) OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0);
    (void) OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,
    (dvoid *) username, (ub4) strlen((char *)username),
    (ub4) OCI_ATTR_USERNAME, errhp);
    (void) OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,
    (dvoid *) password, (ub4) strlen((char *)password),
    (ub4) OCI_ATTR_PASSWORD, errhp);
    checkerr(errhp, OCISessionBegin ( svchp, errhp, authp, OCI_CRED_RDBMS,
    (ub4) OCI_DEFAULT));
    (void) OCIAttrSet((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX,
    (dvoid *) authp, (ub4) 0,
    (ub4) OCI_ATTR_SESSION, errhp);
    checkerr(errhp, OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &stmthp,
    OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));
    checkerr(errhp, OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &stmthp1,
    OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));
    checkerr(errhp, OCIStmtPrepare(stmthp, errhp, maxemp,
    (ub4) strlen((char *) maxemp),
    (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));
    checkerr(errhp, OCIDefineByPos(stmthp, &defnp1, errhp, 1, (dvoid *) &out1,
    (sword) sizeof(sword), SQLT_INT, (dvoid *) &ind1, (ub2 *)0,
    (ub2 *)0, OCI_DEFAULT));
    checkerr(errhp, OCIDefineByPos(stmthp, &defnp2, errhp, 2, (dvoid *) &out2,
    (sword) sizeof(sword), SQLT_INT, (dvoid *) &ind2, (ub2 *)0,
    (ub2 *)0, OCI_DEFAULT));
    /* checkerr(errhp, OCIDefineByPos(stmthp, &defnp3, errhp, 3, (dvoid *) &out3,
    (sword) sizeof(sword), SQLT_INT, (dvoid *) &ind3, (ub2 *)0,
    (ub2 *)0, OCI_DEFAULT));*/
    checkerr(errhp, OCIDefineByPos(stmthp, &defnp4, errhp, 4, (dvoid *) &out4,
    (sword) sizeof(sword), SQLT_INT, (dvoid *) &ind4, (ub2 *)0,
    (ub2 *)0, OCI_DEFAULT));
    checkerr(errhp, OCIDefineByPos(stmthp, &defnp5, errhp, 5, (dvoid *) &out5,
    (sword) sizeof(sword), SQLT_INT, (dvoid *) &ind5, (ub2 *)0,
    (ub2 *)0, OCI_DEFAULT));
    /* execute and fetch */
    if (status = OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0,
    (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT))
    if (status == OCI_NO_DATA)
    else
    checkerr(errhp, status);
    void checkerr(OCIError *errhp, sword status)
    text errbuf[512];
    sb4 errcode = 0;
    switch (status)
    case OCI_SUCCESS:
    break;
    case OCI_SUCCESS_WITH_INFO:
    (void) printf("Error - OCI_SUCCESS_WITH_INFO\n");
    break;
    case OCI_NEED_DATA:
    (void) printf("Error - OCI_NEED_DATA\n");
    break;
    case OCI_NO_DATA:
    (void) printf("Error - OCI_NODATA\n");
    break;
    case OCI_ERROR:
    (void) OCIErrorGet((dvoid *)errhp, (ub4) 1, (text *) NULL, &errcode,
    errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
    (void) printf("Error - %.*s\n", 512, errbuf);
    break;
    case OCI_INVALID_HANDLE:
    (void) printf("Error - OCI_INVALID_HANDLE\n");
    break;
    case OCI_STILL_EXECUTING:
    (void) printf("Error - OCI_STILL_EXECUTE\n");
    break;
    case OCI_CONTINUE:
    (void) printf("Error - OCI_CONTINUE\n");
    break;
    default:
    break;
    }

    Use int/long instead sword .

  • Why customer exit variable to grab the current month value doesn't work?

    In CMOD, input the following code to grab the current month value from the system date:
    Grab the month value with System Date
    WHEN 'CURMONTH'.
        CLEAR l_s_range.
        l_s_range-low = SY-DATUM+4(2).
        l_s_range-sign = 'I'.
        l_s_range-opt = 'EQ'.
        APPEND l_s_range TO e_t_range.
    In Query Designer, create a formula variable CURMONTH processed by customer exit and the dimension under the Currency/Unit tab is "Number".  Put the formular variable in the column as a KF.  When running the query, the column with the formular variable shows values of "2,0000000" other than just "2" I want for the current month.  If  the dimension under the Currency/Unit tab is "date", the column with the formular variable shows values of "00/00/0000".  Any idea?  How to grab the correct current month value which is 2 from the system date.
    Thanks!

    Oh ok , try the below options, As such I dont see any errors in our code .
    Not sure if you have ABAPER's in your team, just check with them once on the FM we are trying to see .
    Next , do you hvae 0CALDAY available in your report ? If so try to restrict that field with variable "0DAT" and write the same code you have written for your formula variable , but instead change the variable name to "0DAT" and try if this gets the month . let me know if I'm not clear .

  • Why some jar applet are cached and other don't?

    Hi all,
    i've an application with some signed applets.
    In some applets every update is immediately visible in Java console, in other applets i need to clear jar file stored in jvm cache to see my updates.
    Anybody knows how?
    Thanx a lot in advance
    Andrea

    Hi,
    tnx for you response. You are right, jars aren't downloaded until they ary modified.
    the problem is that in jvm cache these jar result expired (expire date is set to "yesterday") and i don't know why..
    if u pleas can help me...
    many thanx
    Bye
    Andrea

  • Why some file info are missing in Bridge?

    Hi,
    I'm trying to use CQ as a repository for a material database for 3D rendering.
    The Jpeg files are "scaled" in Photoshop to have some prcise dimension in cm independantly of their resolution...
    When the file is saved on the desktop Bridge can show you the real dimension in cmof the sample, but when handled by CQ, bridge don't show this information...
    Is it possible to prevent CQ filtering this ?

    Thanks for the help!  That method works fine.  However I've always been in the habit of right-clicking and using the mouse to cut, copy, and paste and CS4 no longer allows that method to work.

  • Why some PDF files are not imported into my iPod?

    Hi, Yesterday, I added a new book to iTune and syn my iPod.  After the syn, I found that only about 50% of the books on iTune showed up on the iPod.  Can anyone tell me what is wrong and how to fix this problem so that all books can be imported?

    Waht was the source of the books that did not sync?
    Are they really pdfs w/o DRM?

  • LDB: Why some personnel numbers are filetered out in the pnppernr?

    Hi guys,
    I am testing my  LDB program. I have entered the personnel numbers in the selection screen. before going into GET PERAS. I have 5 personnel nos to be processed. But it seems that only selected pernrs allows in the GET PERAS. Please tell me what happened. Is it the auth issue? It can't be because I was able to process the other personnel numbers. I tried to isolate the personnel that were flagged out. and in the system debug mode. Before get peras, it was some like CE functional that triggers to terminate a certain personnel to go in the process of GET PERAS.
    Need your professional adive.
    Thank you in advance

    You could call macro PNP_GET_AUTH_SKIPPED_PERNRS at END-OF-SLECTION to make sure it is not an auth issue.
    And check the P - CP relation in HRP1001. If it is not correct PNPCE will not select the personnel number.

  • In javascript, objects used to be passed by reference, now for some reasong they are passed by value. Is this a bug on my end or is it because of changes in the JS engine. Any advice on how this can be fixed on my end?

    ''Duplicate post, continue here - [/questions/777098]''
    Using: FF beta 9
    Back-Compatibility problem. (Javascript)

    A good place to discuss issues with Namoroka 3.6 and Minefield 4 nightly builds and Firefox 4.0 beta builds at the mozillaZine Firefox Builds forum.<br />
    You need to register on the mozillaZine forum site in order to post at that forum.
    See http://forums.mozillazine.org/viewforum.php?f=23

  • Instance variables again

    why some private variables are placed at the bottom of the code? is that correct? some place the variables on top. why is that? which is the correct

    I agree that it's a matter of personal preference, but also of following a common code style (which is pretty important, especially if others need to read your code). And in my experience the overwhelming majority puts member variables at the top.

  • Scope of instance variables in servlets..

    Hi all,
              Sorry for asking a dumb question..
              What is the scope of instance variables in a servlet? Is the scope is
              limited to thread?
              In other words, in the following example, i am setting "testStr", in one
              request and when i tried to access the same instance variable from another
              request, i am getting it as null. Does it mean instance variable is limited
              to that particular thread/request?
              thanks in advance..
              -ramu
              

    Oops ... I had misunderstood and had the problem backwards ;-)
              > Is it known behavior? With registered servlet its working fine (a
              > instance variable is shared by all requests)
              I believe so; I typically deploy in a WAR so have not seen the problem that
              you describe. Servlets can be reloaded, so what you saw could have been
              caused bye a date/time mismatch between the .class file and the server's
              current time. On the other hand, that could be how WebLogic works.
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              http://www.tangosol.com
              +1.617.623.5782
              WebLogic Consulting Available
              "Ramu" <[email protected]> wrote in message
              news:[email protected]...
              > Hi Purdy,
              >
              > I got it. I am testing the servlet as a unregistered servlet, which is
              > creating instance for every new request!!!, which created this whole
              > confusion. Is it known behavior? With registered servlet its working fine
              (a
              > instance variable is shared by all requests)
              >
              > > What theory? ;-) Instance variables are on the object, and the object
              can
              > > be used by multiple threads, thus allowing multiple threads to access
              the
              > > same instance variables.
              > what i mean by theory here is, all instance variables in servlet should
              be
              > shared by all requests. Now i got it sir.
              >
              > Thank you..
              > -ramu
              >
              >
              > >
              > > Peace,
              > >
              > > --
              > > Cameron Purdy
              > > Tangosol, Inc.
              > > http://www.tangosol.com
              > > +1.617.623.5782
              > > WebLogic Consulting Available
              > >
              > >
              > > "Ramu" <[email protected]> wrote in message
              > > news:[email protected]...
              > > > Hi,
              > > >
              > > > > No, an instance variable in a servlet class is not limited to a
              > thread.
              > > > There
              > > > > is exactly one copy of the servlet created in memory and all
              requests
              > > pass
              > > > > through the same instance, thus sharing any instance variables. A
              > > couple
              > > > of
              > > > > things to remember:
              > > > I totally agree with you, But i am wondering why my sample servlet(i
              am
              > > > attaching the file) is not sharing the instance variables across
              > > > threads/reqs. (in 1st request set some string to "testStr" instance
              > > > variable, in next request if you read the same instance variable, you
              > will
              > > > get null!!)
              > > > Our current code is having instance variables. But right now we are
              not
              > > > getting any problems. But as per theory, instance variables should be
              > > shared
              > > > across threads/requests..
              > > >
              > > > Any how we are changing our code to remove all instance variables.
              > > >
              > > > thanks,
              > > > -ramu
              > > >
              > > > >
              > > > > 1.) Using instance or class variables in servlets that are not
              > read-only
              > > > is not
              > > > > a good thing to do. This makes the servlet not thread-safe. To
              > > maintain
              > > > > variables across requests, sessions, etc., use the servlet-defined
              > > objects
              > > > to
              > > > > store the state (e.g., request, session, etc.).
              > > > >
              > > > > 2.) If you modify the servlet class on disk, WebLogic will reload
              the
              > > > servlet
              > > > > class thus discarding the old instance and creating a new one (of
              > > course,
              > > > this
              > > > > depends on some configuration parameters for servlet reloading).
              > > > >
              > > > > Hope this helps,
              > > > > Robert
              > > > >
              > > > > Ramu wrote:
              > > > >
              > > > > > Hi,
              > > > > > thanks for quick reply.
              > > > > > I am not at all using SingleThreadModel. See the following code.
              > > > > > In first request i am passing "abc" value to testStr. But in
              second
              > > > request,
              > > > > > I am getting null for testStr in second request. It looks like
              (for
              > > me)
              > > > for
              > > > > > non single threaded model also, scope of instance variables is
              > > limited
              > > > to
              > > > > > Thread/Request.. But as per theory, because its not single
              threaded
              > > > model,
              > > > > > only one instance should be there AND testStr(instace variables)
              > > should
              > > > be
              > > > > > shared across the all threads. But i am not able see that
              behaviour
              > > > here.
              > > > > > But if declare instance variable as static, o am able to share
              it
              > > > across
              > > > > > all threads/requests.
              > > > > >
              > > > > > note:
              > > > > > From browser i am setting testStr to "abc" with URL like
              > > > > > "localhost/test1?testStr=abc"
              > > > > > And 2nd req from browser is like "localhost/test1" (on server
              > output
              > > i
              > > > am
              > > > > > getting null for testStr)
              > > > > >
              > > > > > Any ideas?
              > > > > >
              > > > > > thanks,
              > > > > > -ravi
              > > > > >
              > > > > > import java.io.*;
              > > > > > import javax.servlet.*;
              > > > > > import javax.servlet.http.*;
              > > > > >
              > > > > > public class test1 extends HttpServlet
              > > > > > {
              > > > > > public String testStr;
              > > > > >
              > > > > > public void doGet (HttpServletRequest req, HttpServletResponse
              res)
              > > > > > throws ServletException, IOException
              > > > > > {
              > > > > > doPost(req, res);
              > > > > > }
              > > > > >
              > > > > > public void doPost (HttpServletRequest req,
              HttpServletResponse
              > > res)
              > > > > > throws ServletException, IOException
              > > > > > {
              > > > > > try {
              > > > > > res.setContentType("text/html");
              > > > > > PrintWriter out = res.getWriter();
              > > > > > if(req.getParameter("testStr") != null)
              > > > > > {
              > > > > > testStr = req.getParameter("testStr");
              > > > > > System.out.println("set testStr = " + testStr);
              > > > > > }
              > > > > > else{
              > > > > > System.out.println("get testStr = " + testStr);
              > > > > > }
              > > > > >
              > > > > > }
              > > > > > catch(Exception e){
              > > > > > e.printStackTrace();
              > > > > > }
              > > > > >
              > > > > > }
              > > > > > }
              > > > > >
              > > > > > "Cameron Purdy" <[email protected]> wrote in message
              > > > > > news:[email protected]...
              > > > > > > Yes or no, depending on if your servlet implements
              > > SingleThreadModel.
              > > > > > >
              > > > > > > See the servlet 2.2 spec for documentation on how many instances
              > of
              > > a
              > > > > > > servlet will be created. See the doc for the SingleThreadModel
              > > > interface.
              > > > > > >
              > > > > > > Peace,
              > > > > > >
              > > > > > > --
              > > > > > > Cameron Purdy
              > > > > > > Tangosol, Inc.
              > > > > > > http://www.tangosol.com
              > > > > > > +1.617.623.5782
              > > > > > > WebLogic Consulting Available
              > > > > > >
              > > > > > >
              > > > > > > "Ramu" <[email protected]> wrote in message
              > > > > > > news:[email protected]...
              > > > > > > > Hi all,
              > > > > > > >
              > > > > > > > Sorry for asking a dumb question..
              > > > > > > >
              > > > > > > > What is the scope of instance variables in a servlet? Is the
              > scope
              > > > is
              > > > > > > > limited to thread?
              > > > > > > >
              > > > > > > > In other words, in the following example, i am setting
              > "testStr",
              > > in
              > > > one
              > > > > > > > request and when i tried to access the same instance variable
              > from
              > > > > > another
              > > > > > > > request, i am getting it as null. Does it mean instance
              variable
              > > is
              > > > > > > limited
              > > > > > > > to that particular thread/request?
              > > > > > > >
              > > > > > > > thanks in advance..
              > > > > > > >
              > > > > > > > -ramu
              > > > > > > >
              > > > > > > >
              > > > > > > >
              > > > > > >
              > > > > > >
              > > > >
              > > >
              > > >
              > > >
              > >
              > >
              >
              >
              

  • Stateful session bean destroying instance variables?

    I'm trying to use a stateful session bean as some kind of login controller and to maintain the login id and access level across JSPs and HTMLs so that once logged in, all the JSPs can obtain the login name of the current user (String) and his access level (int).
    I use the login.jsp to login and it successfully reports logging in with the correct access level retrieved from database. However, if I go to another JSP (testlogin.jsp), these 2 EJB instance variables are always destroyed and set to null and 0 when I access them again.
    What am I missing that my stateful session bean is not saving these instance variables? Do I need to put them in some serializable value objects (create a help VO class?)
    I suspected that on different JSP, I call the MemberControllerHome.create() method, it creates a new instance or something but if I don't use the create method how do I get a handle to MemberController at all?
    MemberControllerBean.java
    public class MemberControllerBean implements SessionBean {
         //initialize in ejbCreate.
         private MemberHome memberHome;
         SessionContext context;
         //Member currentLogin;
         //Current Login
         private String loginID;
         private int accessLevel;
         // Constructor
         public MemberControllerBean() {}
    ...some code in between...
    public void login(String id, String password){
              try{
                   Member member = null;
                   member = memberHome.findByPrimaryKey(id);
                   if(member.getMPassword().equals(password)){
                        this.loginID = member.getMID();
                        this.accessLevel = member.getMAccessLevel();
                   else{
                        throw new EJBException("Login failed. Invalid member ID and/or password.");
              } catch (FinderException ex) {
                   throw new EJBException("Login failed. Invalid member ID and/or password.");
         public void logout(){
              this.loginID = null;
              this.accessLevel = 4;
         public String getLoginID(){
              return this.loginID;
         public int getLoginAccessLevel(){
              return this.accessLevel;
    login.jsp
    String mID = request.getParameter("mID");
    String mPassword = request.getParameter("mPassword");
    out.println("20:" + mID + ":" + mPassword);
    if(mID != null && mPassword != null){
         out.println("22:" + mID + ":" + mPassword);
         try{
              InitialContext ic = new InitialContext();
              MemberControllerHome home = (MemberControllerHome) ic.lookup("java:comp/env/ejb/MemberController");
              MemberController mc = home.create();
              out.println("26:Logging in as " + mID + " with " + mPassword);
              mc.login(mID, mPassword);
              out.println("28:" + mc.getLoginID() + "logged in successfully at level " +
                   mc.getLoginAccessLevel() + ".");
         } catch (NamingException ex) {
              out.println("java:comp/env/ejb/MemberController not found.");
         } catch (EJBException ex) {
              out.println(ex.getMessage());
         } catch (Exception ex) {
              out.println(ex.getMessage());
    testlogin.jsp
    <%
    try{
         InitialContext ic = new InitialContext();
         MemberControllerHome home = (MemberControllerHome) ic.lookup("java:comp/env/ejb/MemberController");
         MemberController mc = home.create();
         out.println("You are logged in as <b>" + mc.getLoginID() +
              "</b> at level <b>" + mc.getLoginAccessLevel() + "</b>.");
    } catch (NamingException ex) {
         out.println("java:comp/env/ejb/MemberController not found.");
    } catch (EJBException ex) {
         out.println(ex.getMessage());
    } catch (Exception ex) {
         out.println(ex.getMessage());
    %>

    The key to the problem is that in testlogin.jsp a new stateful session bean is created. The new bean instance of course doesn't know the log-in information you stored in the old session bean. That is why the method returns null and 0 when called.
    There are couple of ways to solve the issue. The easiest solution is to store the bean instance created in Login.jsp in the jsp's implicit HttpSession object. Because login.jsp and testlogin.jsp share the same session, the bean instance can be easily stored and retrieved.
    Here is the code you need to have:
    1. in login.jsp
    session.setAttribute("MemberControllerBeanInstance", mc);
    2. in testlogin.jsp
    MemberController mc =
    (MemberController) session.getAttribute("MemberControllerBeanInstance");
    Hope it helps.

  • What's the difference between global variables and instance variables?

    hi im just a biginner,
    but what is the difference between these two?
    both i declare them above the constructor right.
    and both can access by any method in the class but my teacher said
    global variables are not permitted in java....
    but i don't know what that means....and i got started to confuse these two types,,
    im confusing.......
    and why my teacher said declaring global variables is not permitted,,,,,,
    why.....

    instance variables are kindof like Global variables. I'm not surprised you are confused.
    The difference is not in how they are declared, but rather in how they are used.
    There are two different "styles" of programming
    - procedural programming.
    - object oriented programming.
    Global variables are a term from Procedural programming.
    In this style of programming, you have only one class, and one "main" procedure. You only create one instance of the class, and then "run" it.
    There is one thread of control, which goes through various methods/procedures to accomplish your task.
    In this style of programming instance variables ARE "global" variables. They are accessible to all methods. There is only one instance of the class, and thus only one instance of the variables.
    Global variables are "bad" BECAUSE you can change them in any method you like. Even from places that shouldn't have to. Also if you use the same name as a global variable and a local variable, you can cause great trouble. This can lead to very subtle bugs, as the procedures interact in ways you don't expect.
    The preferred method in procedural programming is to pass the values as parameters to the methods, and only refer to the parameters, and local variables. This means that you can track exactly what your method is doing, and what it affects. It makes it simpler to understand. If you use global variables in your methods, it becomes harder to understand.
    So when are instance variables not global variables?
    When you are actually using the class as an Object, rather than just a program to run. If you are creating multiple instances of an object, all with different values for their instance variables, then they are not global variables. For instance you declare a Person object with an attribute "firstname". Your "main" program then creates many instances of the Person object, each with their own "firstname"
    I guess at the end of all this, it comes down to definitions.
    Certainly you can write procedural code in java. You can treat your instance variables, for all intents and purposes like global variables.
    I can only think to show a sort of example
    public class Test1
       User[] users;
       public void printUsers(){
         // loop through and print all the users
         // uses a global variable
          for(int i=0; i<users.length; i++){
            users.printUser();
    public void printUsers(User[] users){
    // preferred method - pass it the info it needs to do the job
    for(int i=0; i<users.length; i++){
    users[i].printUser();
    public Test1(){
    User u1 = new User("Tom", 20);
    User u2 = new User("Dick", 42);
    User u3 = new User("Harry", 69);
    users = new User[3];
    users[0] = u1;
    users[1] = u2;
    users[2] = u3;
    printUsers();
    printUsers(users);
    public static void main(String[] args)
    new Test1();
    class User{
    String firstName;
    int age;
    public User(String name, int age){
    this.firstName = name;
    this.age = age;
    public void printUser(){
    // here they are used as instance variables and not global variables
    System.out.println(firstName + " Age: " + age);
    Shit thats a lot of typing, and I'm not even sure I've explained it any good.
    Hope you can make some sense out of this drivel.
    Cheers,
    evnafets

  • Inheritance - instance variable initialization

    Hi all.
    I have a question regarding inherited instance variables.
    class Animal {
       int weight;
       int age = 10;
    class Dog extends Animal {
       String name;
    class Test {
       public static void main(String[] args) {
          new Dog();
    }This is just an arbitrary code example.
    When new Dog() is invoked, I understand that it's instance variable "name" is give the default
    type value of null before Dog's default constructor's call to super() is invoked.But Im a little perplexed about
    Animals instance variables. I assume that like Dog, Animals instance variables are given their default type values
    of 0 & 0 respectively, before Animals invocation of super(); What im unclear about is that at the point that weight and age are given their default type values, are Dog's inherited weight and age variables set to 0 aswell at that exact moment? Or are Dog's inherited weight and age variables only assigned their values after Animals constructor fully completes because initialization values are only assigned to a classes instance variables after it's call to super().
    Many thanks & best regards.

    Boeing-737 wrote:
    calvino_ind wrote:
    Boeing-737 wrote:
    newark wrote:
    why not throw in some print statements and find out?Super() or this() have to be the very first statement in a constructor..
    Also you cannot access any instance variables until after super or this.
    :-S
    Kind regardsbut if you add the "print" statement in animal constructor, you can easily see what happened to the attributes of Dog ; that s the trick to print "before" super()You can never add a print before super(). It's a rule of thumb, super() and this() must always be the first statements
    in a constructor, whether added implicitly by the compiler or not. In this case there are 2 default constructors (inserted by the compiler), each with a super() invocation. Even if i added them myself and tried to print before super(), the compiler would complain.
    Thanks for the help & regards.you didn't understand what i meant ; take a look at that:
    class Animal {
       int weight;
       int age = 10;
       public Animal() {
           Dog thisAsADog = (Dog) this;
          System.out.println(thisAsADog.name);
          System.out.println(thisAsADog.x);
    class Dog extends Animal {
       String name;
       int x = 10;
    public class Test {
       public static void main(String[] args) {
          new Dog();
    }this way you will know what really does happen

  • Problem in recognising instance variables declared in the class

    Hi all,
    I am trying to deploy an Servlet desiged in WebObjects5.1 application server on application on Iplanet Application server 6.5
    Back ground: All of you might be aware that WebObjects5.1 is an J2ee compliant application server. When an application is designed in WebObjects, it creates a WAR file which can be deployed on any J2ee complaint application server.
    I tried to create such application in WebObjects and tried to deploy on IplanetApplication server6.5(running on Windows using IIS web server).
    I am able to successfully deploy the application. But inorder to do this i had to manually add ias-Web.xml file to the war file generated( gave some arbitrary global id). The aplication just consists some string displaying hello world.
    Now when i try to deploy an application which has some instance variables, the instance variables are not getting recognised. This application works fine on WebObjects5.1. But variables are not getting recognised when deployed iplanet application server
    Has any one faced such kind of problem earlier? If yes please help me out
    Thanks
    Venkatesh

    Hi,
    Please send me your servlet code and war file.
    Thanks

  • Need a little help with instance variables

    I'm still pretty new to this, but what I have here is some instance
    variables that I need to constuct a record from. This keeps track of a
    sorting process. In the public Sortable getRecord() method is where
    I need to construct that record, which is where I'm lost.
    I look at the tutorials on this site but still can't seem to find what I'm looking for.
    What's giving me so much trouble is that I have variables of different types
    and I can't out how to group them togther without getting some wierd error.
    public class SortableSpy implements Sortable {
        public Sortable a; // Sortable is an interface that this class inplements
        public int swaps;
        public int compares;
        public SortEvent events [];
        public int nevents;
        public SortableSpy(Sortable arr) {
                a = arr;              // These are
                swaps = 0;
                compares = 0;  // the variables I need
                nevents = 0;
                events = new SortEvent[1000];  // to use
        public Sortable getRecord() {
             // and this is where I need the record to be constructed
           // then another class will call this record which will keep track
          // of compares and swaps
              return ;
         Thanks for any help anybody can give me

    Why do you have a field that's the same type
    (implements the same interface) as the class itself?
    This is possible, of course, but what are you hoping
    to achieve by doing so?The interface was pre set-up by my professer. Here is the interface
    public interface Sortable  extends Stringable {
        public int size(); // Number of objects to sort
        public boolean inOrder(int i, int j); // are objs i and j in order?
        public void swap(int i, int j); // Swap objects at i and j
        public Stringable getS(int i);  // For debugging - make an
                                      // object being sorted stringable
    }>
    Your code would be easier to read, both for the
    person grading your homework and for anyone who wants
    to help you here, if you chose variable names that
    have meaning. "a" doesn't qualify.What "a" is suppose to be is an object that is sortable. So when I use a sorting
    algorithim it will sort "a". This part was also setup by my proffeser.
    >
    Where do you expect to get all the data that will go
    into those fields?I should've put the entire class here before, instead of just the constuctor
    here it is:
    public class SortableSpy implements Sortable {
        public int t;
        public Sortable a;
        public int swaps;
        public int compares;
        public SortEvent events [];
        public int nevents;
        public SortableSpy(Sortable arr) {
                a = arr;
                swaps = 0;
                compares = 0;
                nevents = 0;
                events = new SortEvent[1000];
        public Sortable getRecord() {
              return a;
         // ** construct a SortRecord from the instance variables
        public String brief() { // or here
                return "Number Of Events" + this.hashCode() + " (" + nevents + ")";
        public String verbose( ) {
              return "Number Of Compares" + this.hashCode() + " (" + compares + ")" +
              "Number Of swaps" + " (" + swaps + ")";
        public boolean inOrder(int i, int j) {
            compares++;
            SortEvent ev = new SortEvent();
            ev.i = i;
            ev.j = j;
            ev.e = EventType.Compare;
            events[nevents] = ev;
            nevents++;
         return a.inOrder(i,j);
        public void swap(int i, int j) {
                int temp = i;
                i = j;
                j = temp;
        public int size() { return nevents;};
        public enum EventType {compare, swap;
         public static Event Compare;}
        private class si implements Stringable {
                private int i;
                public si (int j) { i = j; };
                public String brief() { return " " + i;}
                public String verbose() { return this.brief();}
        public Stringable getS(int i) {
                return  a;
    }>
    getRecord may be better named "createRecord", if I
    understand what you're trying to do (I may not). But
    it sounds like this name may have been specified by
    your professor.
    Yeah get record is supose to return the number of times an
    algorithm swaps and compares objects during the sorting process
    sort of like spying in, as he described
    I get the impression that you've misunderstood a
    homework assignment.Unfortunaty I'm starting to think so myself, but thanks to both of you guys
    for the help you've giving me so far.

Maybe you are looking for

  • Dock disappears when downloading

    Whenever I upload or download a file, my dock disappears until I'm finished. For example, if I go to upload a picture to facebook, finder pops up and asks me to select the file, right? Well as long as that finder window is open, my dock completely di

  • My new tabs setting has chnanged to msn when I downloaded msn games, how can I reset new tabs to open my firefox home page please?

    Hi since I downloaded msn games my new tab window defaults to msn but I want it ot be Firefox. I can't seem to find how to reset it, can you advise please. Thanks

  • Get in a LV tree ctrl a sequence structure

    Hi, I am doing an editor for customizing some sequence parameters (for example "run mode). I'd like to import into a LV tree control all the test sequence maintaining the same structure of the original one. I mean, each step is an item of the tree (T

  • Jsp:useBean scope!!!!

    If you declare <jsp:useBean id="test" scope="session" class="test" /> how can you release the session when you finish using the class??? or what is the ideal scope to used in send and response??? for example... page A: input form page B: process form

  • Return For Correction-EIT

    Hello All, We have registered an Extra Information Type and enabled security for Employee self service responsibility.Every thing is working fine except return for correction feature. Approver is able to return the notification for correction but whe