Non Access Modifiers in Java

In this article you will learn about Non Access Modifiers. Below are the Non Access Modifiers available in Java.

  • Final
  • Abstract
  • Static
  • Strictfp
  • Native
  • Synchronized
  • Transient

Final Non Access Modifiers

Final modifiers are applicable to :

  1. Class
  2. Method
  3. Instance Variable
  4. Local Variable
  5. Method arguments

Final Class :

A Class when set to final cannot be extended by any other Class.

Example: A String Class in java.lang package

Final Method :

A Method when set to final cannot be overridden by any subclass.

Final Variable :

When a variable is set to final, its value cannot be changed. Final variables are like constants.

Example : public static final int i = 10;


Abstract Non Access Modifier

Keyword: abstract

Abstract modifiers are applicable to:

  1. Class
  2. Method

Abstract Class:

An abstract Class can have abstract Methods. A Class can also be an abstract class without having any abstract Methods in it. If a Class has an abstract Method , the Class becomes an abstract Class.

Abstract Method :

Abstract Methods are those Methods which does not have a body but only a signature.

Example : public abstract void method();

 

Synchronized Non Access Modifier

Synchronized modifiers are applicable to

  1. Method

Synchronized Method

Synchronized Methods can be accessed by only one thread at a time.

 


Native Non Access Modifier

Native modifiers are applicable to

  1. Method

Native Method

Naive Methods indicate that the method is implemented on a platform dependent code.

 

Strictfp Non Access Modifier

Strictfp modifiers are applicable to

  1. Class
  2. Method

Strictfp Class / Method

Strictfp non access modifier forces floating point or floating point operation to adhere to IEEE 754 standard.

Note*: Strictfp non access modifier cannot be applied on a variable.

Cheat sheet

  • Non Access Modifiers available in Java are Static, final, abstract, synchronized & Volatile
  • Static keyword can be applied to Variables & Methods.
  • Static Variable  are those variables which are not associated to any instance but it is associated to class means all instances will access the same single copy of variable.
  • Local variables can not be declared as Static.
  • Static keyword can also be applied to Methods. They will work for all the instances and they will not be dependent on instances created.
  • Final modifier can be applied to method and variables.
  • Final is the only modifier which will be available to local variable.
  • Once declared as final value of the variable can not be changed.
  • Final variable don’t get default value opposed to instance variable coz value can’t be changed once assigned.
  • Final method can not be overriden.
Series Navigation<< Access Modifiers in JavaOperators in java programming language >>
By | 2017-07-09T12:07:38+00:00 April 21st, 2012|Core Java|26 Comments

About the Author:

26 Comments

  1. Manishkumar August 29, 2012 at 9:22 am - Reply

    Nice Information

  2. […] Access Modifiers can be applied to Local Variables. Only one Non Access Modifer can be applied to Local variable and that  is […]

  3. npk March 27, 2014 at 8:43 am - Reply

    when –> public final class String…how could we able to change the value?
    String x = “abc1”;
    x = “543”;

    • vin May 31, 2016 at 9:07 am - Reply

      A Class when set to final cannot be extended by any other Class.

    • sibin June 22, 2016 at 5:51 am - Reply

      No ot will givecompile tym error.because a reference variable I already set .

  4. naresh April 4, 2014 at 7:06 am - Reply

    you have missed the volatile keyword any have nice info…

  5. Mrunmayi April 17, 2014 at 10:08 am - Reply

    Where the final variables are allocated space in memory ??
    stack /heap ????

  6. saravanan May 29, 2014 at 1:30 pm - Reply

    your website is pretty awesome. it will still more helpful to new beginner if you explain non-access modifier concept with example for program.

  7. vandana June 11, 2014 at 11:35 am - Reply

    i couldn’t find explanation for few things in the article such as, 1.difference b/w JDK/JRE/J2EE, 2.Transient, 3.Assignment Statement Topic

  8. Rashmi July 2, 2014 at 4:25 pm - Reply

    could you please explain this statement ?
    “A class can also be an abstract class without having any abstract method in it. But once a class have an abstract method class becomes abstract class.”

    • Vivekanand Gautam July 2, 2014 at 5:53 pm - Reply

      Hi Rashmi,

      There could be 2 different scenarios.
      1- A class is having abstract Method
      2- A class doesn’t have abstract Method

      Scenario 1: If a class is having an Abstract method in that case there is no option but class needs to be declared as Abstract and you have to use abstract keyword with class.

      Scenario 2 : If a class doesn’t have any abstract method. In that case there is no reason to use abstract keyword with class. And you are not forced to do that. But you can use abstract keyword with class. So in this case you are free to declare class as abstract or normal class.

      Hope now it is clear. In case of any query let me know.

      Regards

    • Ravikiran May 12, 2016 at 12:37 pm - Reply

      A class is known as abstract in both the cases with and without abstarat method present in the class

    • sibin June 22, 2016 at 5:48 am - Reply

      It says tat if in a class any method is abstract,tat class will automatically become abstract class..so we cant make object of the abstract class..so class also become abstract.(pls do refer others.my info. Will not be true)

  9. Vinod August 4, 2014 at 9:05 am - Reply

    You have declared a method as abstract method but it doesn’t have the keyword “abstract”. Please update…

  10. geetha August 6, 2014 at 4:51 pm - Reply

    String belongs to java.lang package …please correct

    • Vivekanand Gautam August 6, 2014 at 6:27 pm - Reply

      Hi Geetha,

      Thanks for your comment. Article has been updated.

      Regards

  11. Harikrishna November 3, 2014 at 12:34 pm - Reply

    Hi Gautam why don’t u provide navigation….

  12. mobil porno December 30, 2014 at 1:21 am - Reply

    Good web site you’ve got here.. It’s difficult to find excellent
    writing like yours these days. I truly appreciate individuals like you!
    Take care!!

  13. Balan January 14, 2015 at 2:14 pm - Reply

    You have listed Transient as one non access modified; but not explained it. Pl do the same.

  14. Sunil January 20, 2015 at 6:55 pm - Reply

    Nice website dude. Simple and awesome. One suggestion, think you missed to provide explanation about Transient.

    • Vivekanand Gautam January 24, 2015 at 5:59 am - Reply

      Thanks for your nice comment. There is already an Article on Transient please refer the same.

      Regards

  15. sandhya February 3, 2015 at 2:49 am - Reply

    Good job man! Is it possible for you to give some real time example?

  16. Suma April 27, 2015 at 12:51 am - Reply

    Hi,
    I am new to Java. Could you please provide more programming details on Abstract Class/Method.
    I would like to practise more on this.

    Thanks!!!

  17. Rajeeev February 19, 2016 at 1:56 pm - Reply

    seriously, y you doesn’t write applicable to interface ?

  18. Anonymous July 18, 2017 at 12:22 pm - Reply

    very informative

Leave A Comment