Results 1 to 8 of 8
  1. #1
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default cofusion with static and ordinary variables and methods

    I am confusing when i am using static variables in a class
    my confusion is when to use like i am declaring as below

    1) public static varaible1;
    2) private static variabl2;

    and methods like this ,for example we have class like this

    Java Code:
    public class StaticEx(){
      private static stVarible = "XXXX";
     
      public static String  getStVarible(){
        returtn stVarible; 
     }
      
     public static void setStVarible(String varr){
      stVarible = varr;
     }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    I have no idea what it is you're complaining about.

  3. #3
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    what i mean is .when we use this kind of classes .

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    When it's appropriate. When the information concerned is applicable to all instances of a class collectively and is not something that is specific to a specific instance of the class. (which is the definition of static)

  5. #5
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    thank u.
    I heard that static varibles are not synchronised is it true?If it is true why
    static variables are not eligible for synchronisation

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Per default, no. You can synchronize them though (or at least the access to them).

  7. #7
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    confused,I think when ever a static variable is created in a class it is placed some memory location and each and every object of class shares the same memory location to acess it[in case it is needed] not like just instance variables.when ever multiple objects acessing a static variable how synchronisation can be done.[because it is not object related it is refered to class] .

    I am not sure whether i am wrong or correct.

    If i am wrong please explain how synchronising can be done on static variable.

  8. #8
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    ok i am just stoping here. i start new thred for this.thanks for your replies

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Replies: 6
    Last Post: 02-15-2010, 04:31 AM
  3. What are Instance variables and static variables?
    By sandeshforu in forum New To Java
    Replies: 3
    Last Post: 09-09-2009, 05:48 PM
  4. accessing instance variables from static methods
    By ravian in forum New To Java
    Replies: 7
    Last Post: 03-01-2009, 10:09 PM
  5. significance of static variables and methods
    By imran_khan in forum New To Java
    Replies: 4
    Last Post: 08-02-2007, 09:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •