Java- volatile modifier / Chapter -10 / Access Modifier




Java Volatile modifier


1." volatile" is a modifier applicable only for variable and we can't apply for methods & classes.

2.If a value of a variable keeps on changing by multiple threads then there may be a chance of data inconsistency problem.We can solve this problem by using "volatile modifier".

3.If a variable declared as volatile then for every thread JVM will create a separate local copy.



Java- volatile modifier / Chapter -10 / Access Modifier


  1. "volatile" is a modifier applicable only for variable and we can't apply for methods & classes.
  2. If a value of a variable keep on changing by multiple threads then there may be a chance of data inconsistency problem.We can solve this problem by using "volatile modifier".
  3. If a variable declared as volatile then for every thread JVM will create a separate local copy.

Java- transient modifier / Chapter -9 / Access Modifier


java transient modifier

Java transient modifier


1. transient is the modifier applicable only for the variable.

2. We can use the transient keyword in serialization context.

3. At the time of serialization if we don't want to save the value of a particular variable to meet security constraint then we should declare that variable as transient.

 


Java- transient modifier / Chapter -9 / Access Modifier


  1. transient is the modifier applicable only for the variable.
  2. We can use the transient keyword in serialization context.
  3. At the time of serialization if we don't want to save the value of a particular variable to meet security constraint then we should declare that variable as transient.

Java- native modifier / Chapter -8 / Access Modifier

java native modifier

java native modifier


1. "native" is a modifier applicable only for methods and we cannot apply anywhere else. 2. The methods which are implemented in non-java (C or C++) are called native methods. 3. The main objective of native modifier are:-



  • Improve performance of the system.

  • To achieve machine level or memory level communication.

  • To use already existing legacy (non-java) code.



Java- native modifier / Chapter -8 / Access Modifier



1. "native" is a modifier applicable only for methods and we cannot apply anywhere else.
2. The methods which are implemented in non-java (C or C++) are called native methods.
3. The main objective of native modifier are:-

  • Improve performance of the system.
  • To achieve machine level or memory level communication.
  • To use already existing legacy (non-java) code.

Java- synchronized modifier / Chapter -7/ Access Modifier


java synchronized modifier

 Java synchronized  modifier


1." synchronized" is a modifier applicable for methods and blocks but not for classes and variables.

2.If multiple threads are trying to operate simultaneously on the same java object then, there may be a chance of data inconsistency problem.This is called "Race Condition".We can overcome this problem by using synchronized keyword or modifier.


Java- synchronized modifier / Chapter -7/ Access Modifier

  1. synchronized is a modifier applicable for methods and blocks but not for classes and variables.
  2. If multiple threads are trying to operate simultaneously on the same java object then, there may be a chance of data inconsistency problem.This is called "Race Condition".We can overcome this problem by using synchronized keyword or modifier.
  3. If a method or block declared as synchronized then at a time only one thread is allowed to execute that method or block on the given objects so that data inconsistency problem won't come.

Java- static modifier / Chapter -6/ Access Modifier



Java static modifier

Java static modifier




  1. "static" is a modifier applicable for methods & variables but not for classes.(not for top-level classes but for inner classes we can apply)

  2. We can't declare top level classes with static modifier but we can declare inner classes as "static".

  3. in the case of instance variables for every object a separate copy will be created but in the case of static a single copy will be created at the class level and this will be shared by every object of that class.  example:-
    class Test

    {

          static int x=10;

          int y=20;

          public static void main(String [ ]args)

          {

               Test    t1 =new   Test( );

                t1.x =  888;

                t1.y =  999;

               Test   t2 =new Test( );

               System.out.println(t2.x +".........."+t2.y);

          }

    }

     

    output is;

Java- static modifier / Chapter -6/ Access Modifier


  1. "static" is a modifier applicable for methods & variables but not for classes.(not for top-level classes but for inner classes we can apply)
  2. We can't declare top level classes with static modifier but we can declare inner classes as "static".
  3. in the case of instance variables for every object a separate copy will be created but in the case of static a single copy will be created at the class level and this will be shared by every object of that class.  example:-
    class Test
    {
          static int x=10;
          int y=20;
          public static void main(String [ ]args)
          {
               Test    t1 =new   Test( );
                t1.x =  888;
                t1.y =  999;
               Test   t2 =new Test( );
               System.out.println(t2.x +".........."+t2.y);
          }
    }

    output is;

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com