Regarding static

Hi,
may i know how it works if v use static accoring memory and while linking the class file. i know according to memory, i need to know while linking, is it same for c and c++, how it differs?.
plz send me
siva

If we declare a variable 'static' , it is available for all instances of the class .

Similar Messages

  • Need some explanations regarding static Method

    Hello,
    I have a code where a class has a static method access by other classes. This not working as I thought and I would like to understand why.
    Here below is the code.
    Here is a class having the static method "test"
    package test;
    public class StaticTest {
        public StaticTest() {
        public static void test (int i){
        while (i < 1000){
            System.out.println("i = " + i );
            i++;
    }Here is the code of another class (Thread) using this static method. This Thread can be initialized with an integrer value that will be passed to the static Method.
    package test;
    public class ThreadTester extends Thread {
        int x;
        public ThreadTester(int i) {
            x=i;
        public void run(){
            StaticTest.test(x);
    }Here is the code starting 2 Thread running in parallel and both are then calling the static method.
    //start 2 thread accessing the static method.
          ThreadTester test1 = new ThreadTester(0);
          ThreadTester test2 = new ThreadTester(200);
          test1.start();
          test2.start();
    ...As the second thread is started with a bigger value I thought that we would only have seen few printouts from the first thread starting by 0 and then printouts starting by 200.
    Here is what I thought regarding the result:
    i = 0
    i = 1
    i = 2
    i = 3
    i = 200 --> startup of the second thread, x in static method is overriden (at least this is what I thought!)
    i = 201
    i = 202
    i = 203
    i = 204
    i = 205
    i = 206
    i = 207
    i = 208
    i = 209
    But the real result is:
    i = 0
    i = 1
    i = 2
    i = 3
    i = 4
    i = 5
    i = 200
    i = 6
    i = 201
    i = 202
    i = 203
    i = 204
    i = 205
    i = 206
    i = 7
    i = 207
    i = 208
    i = 209
    i = 8
    It seems that there is 2 instances running in parallel. I thought that it would'nt be the case with the word "Static".
    Also I don't understand the result because if I use JBuilder in Optimizer mode I can see that there is only one instance of StaticTest object.
    Can anyone here explain me how is that possible?
    Thanks in advance for your help.
    Regards,
    Alain.

    >
    thread test1 creates its own stack and starts incrementing �i� starting at values 0. However, in the middle of incrementing, it gets kicked out by the OS (or JVM) into a �blocked� state to allow other threads to run. BUT before leaving the running state, test1 saves the stack state including the value of �i�.
    >
    Ok, now I understand, but then I have another question.
    What is the difference between the code shown in my first post and the following where we create 2 instances of StaticTest class (which is not static in this case for sure).
    How to decide (while coding) if it is better to use difference instances of class or not?
    package test;
    public class StaticTest {
        public StaticTest() {
        public void test (int i){ //Not static anymore
        while (i < 1000){
            System.out.println("i = " + i );
            i++;
    }We create new instance in the Thread.
    package test;
    public class ThreadTester extends Thread {
        int x;
        public ThreadTester(int i) {
            x=i;
        public void run(){
    StaticTest newInstance = new StaticTest(); //Create a new instance
            newInstance .test(x);
    }Alain

  • Regarding static control

    Hi Experts,
                       i have knowledge on flow_conrol,but in which case i will go for static_control, please guide me
    Regards
    ksbabu

    Hi,
    You can use it in two different places :
    In the Model : for instance double-click your datastore and click "Datastore Static Control". It will perform a check on the data using all the constraints (keys, references and conditions) defined and load all the erroneous rows in an error table.
    In an Interface : If you set static control, it will perform the same operation AFTER the loadind of the target table. So all rows will be loaded into the target and then the static control will copy the erroneous rows in the error table.
    Hope it helps.
    Regards,
    JeromeFr
    ps: you should mark your discussions as questions when you create them

  • Regarding Static Price Allocation

    Hi All
    Thanks in Advance
    Can any one please tell me what in " Static Price Allocation " & how it is executed in R/3?
    Its Very Urgent
    Thanks & Regards
    Natash Singh

    Heard of Dynamic Price Changes, but not Static Price Allocation...
    Can you provide the context please?
    Cheers.

  • Regarding static or instance

    Hi all,
               I am in confusion that which is called first static (method / attribute ) or Instance (method/attribute).
    Becoz what i know is whenever an object is created, first static is called then instance.
    please correct me if i am wrong.
    regards,
    satish

    Hi Sathis,
    Instance & Static Method :
    if u declare one method as a static then we can call that method using class name, that method is independent of that object.You declare them using the CLASS-DATA statement.
    if u declare one method as a instance then we can call that method using object name, that method is dependent of that object.You declare them using the DATA statement.
    Instance & Static Attribute :
    if u declare one attribute as a static then we can use that attribute through class name, that attribute is independent of that object.You declare static methods using the CLASS-METHODS statement.
    if u declare one attribute as a instance then we can use that attribute through object name, that attribute is dependent of that object.You declare instance methods using the METHODS statement.
    if u have any doubt ask me,
    Regards,
    Vijay
    Edited by: Vijay.V on Dec 26, 2007 3:33 PM
    Edited by: Vijay.V on Dec 26, 2007 3:36 PM

  • Regarding static methos and attributes...

    Hi..
    What do u mena by static methids and atributes?
    Why v'll use these?
    Whats the purpose?
    Regards
    sandeep.

    Hi,
    Static Attributes
    The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement. They are accessible for the entire runtime of the class.
    All of the objects in a class can access its static attributes. If you change a static attribute in an object, the change is visible in all other objects in the class.
    The technical properties of instance attributes belong to the static properties of a class. It is therefore possible to refer in a LIKE addition to the visible attributes of a class – through the class component selector or through reference variables, without prior creation of an object.
    Methods
    Methods are internal procedures in a class that define the behavior of an object. They can access all of the attributes of a class. This allows them to change the data content of an object. They also have a parameter interface, with which users can supply them with values when calling them, and receive values back from them The private attributes of a class can only be changed by methods in the same class.
    The definition and parameter interface of a method is similar to that of function modules. You define a method meth in the definition part of a class and implement it in the implementation part using the following processing block:
    Static Methods
    You declare static methods using the CLASS-METHODSstatement. They can only access static attributes and trigger static events.
                Reward If Helpfull.
    Regards Madhu.

  • Sunstudio in Ubuntu 7.10 (Some trouble regarding static libary)

    Dear freinds,
    I install sunstudio 12 from "SunStudio12ml-linux-x86-200709-ii[1].tar.bz2" in my Ubuntu 7.10 operating system.
    My Directory of installation is /opt/sun
    I install "jdk-6u5-nb-6_0_1-linux-ml.sh" in /usr/java
    The configuration of PC:
    =================
    Linux dell-desktop 2.6.22-22-14-generic #1 SMP Tue Feb 12 07:42:25 UTC 2008 i686 GNU/Linux
    Operating system:
    =============
    Ubuntu
    Release 7.10 (gusty)
    kernel Linux 2.6.22-14 generic
    GNOME 2.20.1
    Processor type:
    ================
    Intel(R) Core(TM)2 Duo CPU T7500 @2.20 GHz
    ERROR:
    ======
    I am getting the following error while compilling f95 file--------------------------
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /opt/sun/sunstudio12/prod/lib/libfsu.a(__f90_init.o): In function `__f90_init_f77compat':
    __f90_init.c:(.text+0x96): undefined reference to `atexit'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(initio.o): In function `__f90_initio_a':
    initio.c:(.text+0x106): undefined reference to `fstat64'
    initio.c:(.text+0x176): undefined reference to `fstat64'
    initio.c:(.text+0x1af): undefined reference to `fstat64'
    initio.c:(.text+0x317): undefined reference to `fstat64'
    initio.c:(.text+0x37e): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(initio.o):initio.c:(.text+0x3b7): more undefined references to `fstat64' follow
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o): In function `open_old_a':
    open.c:(.text+0x3c9): undefined reference to `lstat64'
    open.c:(.text+0x460): undefined reference to `lstat64'
    open.c:(.text+0x4c6): undefined reference to `lstat64'
    open.c:(.text+0x560): undefined reference to `lstat64'
    open.c:(.text+0x870): undefined reference to `lstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o):open.c:(.text+0xb82): more undefined references to `lstat64' follow
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o): In function `open_old_a':
    open.c:(.text+0xe46): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o): In function `open_new_a':
    open.c:(.text+0x1649): undefined reference to `lstat64'
    open.c:(.text+0x16e9): undefined reference to `lstat64'
    open.c:(.text+0x18e7): undefined reference to `lstat64'
    open.c:(.text+0x1a0e): undefined reference to `lstat64'
    open.c:(.text+0x1b35): undefined reference to `lstat64'
    open.c:(.text+0x1c18): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o): In function `open_scratch_a':
    open.c:(.text+0x2241): undefined reference to `fstat64'
    open.c:(.text+0x235a): undefined reference to `stat64'
    open.c:(.text+0x23a3): undefined reference to `stat64'
    open.c:(.text+0x23e9): undefined reference to `stat64'
    open.c:(.text+0x2429): undefined reference to `stat64'
    open.c:(.text+0x27a8): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o): In function `open_a':
    open.c:(.text+0x3354): undefined reference to `lstat64'
    open.c:(.text+0x338b): undefined reference to `fstat64'
    open.c:(.text+0x3af5): undefined reference to `fstat64'
    open.c:(.text+0x3dd4): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o): In function `open_old_r':
    open.c:(.text+0x50fd): undefined reference to `lstat64'
    open.c:(.text+0x5194): undefined reference to `lstat64'
    open.c:(.text+0x51f6): undefined reference to `lstat64'
    open.c:(.text+0x5343): undefined reference to `lstat64'
    open.c:(.text+0x547b): undefined reference to `lstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o):open.c:(.text+0x55b5): more undefined references to `lstat64' follow
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o): In function `open_old_r':
    open.c:(.text+0x5629): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o): In function `open_scratch_r':
    open.c:(.text+0x58a2): undefined reference to `fstat64'
    open.c:(.text+0x5997): undefined reference to `stat64'
    open.c:(.text+0x59f0): undefined reference to `stat64'
    open.c:(.text+0x5a3b): undefined reference to `stat64'
    open.c:(.text+0x5a7e): undefined reference to `stat64'
    open.c:(.text+0x5de9): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(open.o): In function `open_r':
    open.c:(.text+0x65e3): undefined reference to `lstat64'
    open.c:(.text+0x661a): undefined reference to `fstat64'
    open.c:(.text+0x6b5e): undefined reference to `lstat64'
    open.c:(.text+0x6c13): undefined reference to `lstat64'
    open.c:(.text+0x6d1a): undefined reference to `lstat64'
    open.c:(.text+0x6dc5): undefined reference to `lstat64'
    open.c:(.text+0x6e72): undefined reference to `lstat64'
    open.c:(.text+0x6eda): undefined reference to `fstat64'
    open.c:(.text+0x7171): undefined reference to `fstat64'
    open.c:(.text+0x74c0): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(sfw.o): In function `__f90_ssfw':
    sfw.c:(.text+0x3ce05): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(sfw.o): In function `__f90_ssfw_pos':
    sfw.c:(.text+0x3d370): undefined reference to `fstat64'
    /opt/sun/sunstudio12/prod/lib/libfsu.a(sfw.o):sfw.c:(.text+0x3d49f): more undefined references to `fstat64' follow
    make: *** [test1] Error 1
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Could anybody please give me a solution for this.
    Thank you,
    Regards,
    Panjit

    Thank you very much,
    Even though it is not a total solution.........But I can work with Dynamic libary.
    It works with dynamic option for all code...........But in future I may have to work with static libary....I dont know what to do then.
    Can you please sugesst any solution so that I can use Bstatic option.
    But I am happy because I can work for my code and your sugesssions works well for me.
    Thank you
    Kind Regards,
    Pranjit

  • Need info regarding static file cache in weblogic

    Hi,
    I want to cache the static files at weblogic side
    I am using Apache plugin provided by weblogic
    I have gone through the e-docs about FileCache ON which is needs to be set in httpd.conf
    I want to know is there any settings which is set at weblogic to cache static files
    As i am using apache plug in provided by weblogic i want to know if there is any setting at weblogic side
    Thanks in advance

    Hello,
    Normally the statis contents are served from web servers, in your case this may be from Apache. So what statis files are you referring to in weblogic, is that a part of HTML and images from WAR / EAR ?
    In general weblogic has its own cache temp location as runtime to keep the classfiles and other resources unpacked from WAR / EAR.
    -AJ

  • Clarification regarding static blocks.

    I can understand from this about the static initialization block. I just need one clarification. What is the difference between the blocks with and without the 'static' keyword? For eg., the following code prints 'Hello'
    class ClassWithStaticBlock {
              System.out.println("Hello");
    public class StaticBlockTester {
         public static void main(String[] args) {
              new ClassWithStaticBlock();
    }If I modify the class ClassWithStaticBlock like given below, I receive the same output. So, what is the difference between the two?
    class ClassWithStaticBlock {
         static {
              System.out.println("Hello");
    }Thanks.

    The static block is only run upon loading of the class. Well, during the initialization phase of loading it, but it amounts to much the same thing. Non-static initiializers are run every time the class is instantiated. Try this
    class ClassWithInitializers {
      static {
       System.err.printlln("Loading class");
        System.err.println("Initializing");
      public static void main(String[] args) {
        new ClassWithInitializers();
        new ClassWithInitializers();
        new ClassWithInitializers();
        new ClassWithInitializers();
    }See any difference?

  • Regarding static block

    Hi,
    I need to get two properties from the properties file and i will use these properties across the application,How can i write the util class which get the two properties and i can use acrross the application.
    Can i use the staic block in the util class ?
    Pls suggest me.
    Thanks
    crr

    I would use a util class to lazily load the properties file. You will need to handle certain IO exceptions when loading props, which is too much for a static block to handle properly. For example,
    public synchronized Properties getProps() {
        if(this.props == null) }
            loadProps();
        return this.props;
    }-cheng

  • Regarding static IP Address

    Hi,
    Can I able to fetch the IPAddress of ISP (static IPAddress) through java code?

    DHURAI wrote:
    Have a look at this website,
    http://www.2privacy.com/
    start Java IP test
    They produce the IPAddress of the service provider with their host name.That doesn't explain what you are looking for.

  • Regarding static iview

    hi all,
      I need some clarifications regarding iviews. As per my understanding, whenever we navigate to different iviews/applications in portal, the whole is refreshed. So, if I place an application in portal through iview in the default framework page, while we navigate, the application would be initialized everytime. To be more specific, if I have a webdynpro iview, its wdDoinit() would be called on each navigation.
    so, is there any way out where the application is initialized just once?
    Any inputs or comments are most welcome.
    Thanks

    Hi,
    The way an iView will be refreshed is determined by:
    1. It's isolation method propery. Read <a href="http://help.sap.com/saphelp_nw70/helpdata/en/97/0be13dc2fd605ae10000000a11405a/frameset.htm">here</a> about Isolation Method of iViews.
    2. It's caching properties. Read <a href="http://help.sap.com/saphelp_nw70/helpdata/en/5f/2720a513ea4ce9a5a4e5d285a1c09c/frameset.htm">here</a> about Caching.
    Hope it helps,
    Roy

  • Confused regarding static methods

    Hello guys,
    I like to know the only purpose of static method is to call a method with out creating
    instance of that class.
    I am totaly confused why and where to use static methods.
    Thanks in advance
    aneesh

    Look at the API docs for some of the static methods in classes like java.lang.String, java.lang.Integer, java.lang.Thread, etc.
    An object--an instance of a class--has state and behavior. The state is captured in the instance variables--the array that holds the characters of a String, the name, SS#, and hireDate fields of an Employee object, etc.
    Static methods are used when the operation you're performing isn't associated with any particular instance of that class--it doesn't use or modify the state of a particular object. The operation is associated with the class as a whole.
    For instance, Integer.parseInt(String). You're not operating on an existing Integer object. Rather you're creating a new Integer from a String. It's a utility or "helper" method of the Integer class.
    And yes, do read the tutorial.

  • Lifetime of static classes in WebDynpro

    Hi,
    I have a question regarding static java classes in WebDynpro: Does anybody know details about their lifetime. I was searching for this information but I didn't find info.
    The background of this question is, that I would like to store configuration data (customizing) from the R/3 in a static class of my WebDynpro application, in order to minimize DB requests. Exists a static class for the whole WebDynpro session or is it destroyed after every user interaction?
    Thanks in advance,
    Martin

    Hi
    If  I have understood you
             You  want to create a static class,  you are expecting the values will remain same for the lifetime of the
    webdynpro app.
    In order to understand the use of the static keyword in class declaration, we need to understand the class
    declaration itself. You can declare two kinds of classes: top-level classes and inner classes.
    Top-level classes
    You declare a top-level class at the top level as a member of a package. Each top-level class corresponds to
    its own java file sporting the same name as the class name.
    A top-level class is by definition already top-level, so there is no point in declaring it static; it is an error to do
    so. The compiler will detect and report this error.
    you cant write a code like
    public static class hello {
    it gives an error like
    Illegal modifier for the class hello; only public, abstract & final are permitted
    Regards
    Abhijith YS

  • Re: static variables in beans

    That's GoF. Again I was responding to the question posted earlier and could not
    see it near by and not commenting on yours. I was questioning the original design
    of having to keep singletons as static fields in SLSBs.
    S
    "Cameron Purdy" <[email protected]> wrote:
    Is there a problem if you get the singleton (through a static methodas
    in GoF) objects in the methods as required and not store it as static
    variables in the SLSB?I am acronymically challened ("AC"). What is GoF? I know I've seen it
    before, but I can't remember what it means.
    Singletons should store their own reference. You should probably have
    a
    private constructor and a static "instance" accessor.
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    http://www.tangosol.com/coherence.jsp
    Tangosol Coherence: Clustered Replicated Cache for Weblogic
    "sri" <[email protected]> wrote in message news:[email protected]..
    >

    You are right. An EJB (all kinds) is restricted from using writtable static fields.
    Read only fields are allowed but recommended to use 'final' to denote so.
    S
    "Cameron Purdy" <[email protected]> wrote:
    That's GoF. Again I was responding to the question posted earlier and
    could not see it near by and not commenting on yours. I was questioning
    the original design of having to keep singletons as static fields inSLSBs.
    It gets difficult to follow these threads. I use Outlook Express (motto:
    "There's no message out there that we can't add a top-post to!") which
    isn't
    the world's best newsreader.
    Regarding static fields in SLSBs, you are right that it is certainly
    something to avoid. I believe that some containers even refuse to deploy
    EJBs that have static fields like that. (I believe it's a purposed
    limitation in the spec.)
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    http://www.tangosol.com/coherence.jsp
    Tangosol Coherence: Clustered Replicated Cache for Weblogic
    "Sri" <[email protected]> wrote in message news:3ea5b88e$[email protected]..
    >

Maybe you are looking for

  • How can I get windows explorer to read the files on my Mac external Hard Disk?

    I have copied a buch of files form my iMac to an external USB drive.  However my other laptop which is a Windows Vista one is unable to read the USB drive. Pl help what am I doing wrong?

  • Date Shifted Events in Calendar

    In the Month View and the Day View of Celandar under iOS 5 all of the entries appear correct. However, in the List View a major problem appears.  All of the entries appear to be shifted one day earlier.  So, for example, an event X which appears (cor

  • The added Apple dictionary iOS 7 not working!

    Hi everyone, when I added different dictionaries in manage to define words, all the dictionaries work except the Apple dictionary. So what is wrong? I did the same thing on my iPad 4, apple dictiontionary doesn't work there either. Your help would be

  • Check Event Alert ends in error, log file has no error message

    Hi, We are upgrading from 11.5.10 to 12.1.3. Check Event Alert ends in error, log file doesn't have any information. This alert is on oe_order_headers_all. Alert working fine in 11i. 12.1.3 10g database Appreciate any inputs. I noticed that Operating

  • Cisco 3905 failed but outgoing call still ringing on mobile phone

    Dear all, We setup Cisco Call Manager 10 with Cisco Voice gateway 2911 ( E1 port) and 3905. All outgoing call & incoming call are ok. But we meet a small issue as below: -Using 3905 do outgoing call to mobile number. Mobile number ringing. -3905 fail