Category: Access Modifiers
Summary table of Java Modifiers and Access Specifiers. The only applicable modifier for the local variable is final. The only applicable modifiers for constructor are public, private, default, protected. The modifiers which are applicable only to the method is native. The modifiers which are applicable only for variables volatile and . . . Read more
What is Volatile keyword in Java? Volatile is the modifier applies only to variables and we can’t apply anywhere else. If the 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 the . . . Read more
What is Transient Keyword in Java? Transient modifier applicable only for variables but not for methods and classes. We can use a transient keyword in serialization context. At the time of serialization if we don’t want to save a value of a particular variable to meet security constraint then we . . . Read more
What is Native modifier in Java? Native is the modifier applicable only to the method and we can’t apply anywhere else. The method which is implemented in non-java(mostly c and c++) are called native methods or foreign methods. The main objectives of a native keyword are To improve the performance . . . Read more
What is synchronized modifier in Java? Synchronized is the modifier applicable for methods and blocks but not classes and variables. If multiple threads 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 . . . Read more
What is the static modifier in Java? Static is a modifier applicable to methods and variables but not for classes. You can think of a ‘static’ method or field as if it were declared outside the class definition. In other words, there is only one ‘copy’ of a static field/method. . . . Read more
Summary table for Java access specifiers Visibility Private Default Protected Public Within the same class Yes Yes Yes Yes From child class of the same package No Yes Yes Yes From a non-child class of the same package No Yes Yes Yes From child class of outside package No No . . . Read more
What is Strictfp modifier in Java? Introduce in 1.2 version. We can declare Strictfp for classes and methods but not for variables. By using the strictfp keyword, we can ensure that floating point operations take place precisely. Usually, the result of floating point arithmetic is varied from platform to platform. . . . Read more
What is the use of Abstract modifier in Java An abstract is a modifier applicable to classes and methods but not for variables. Abstract Method Even though we don’t know about implementation still, we can declare a method with abstract modifier i.e. for the abstract method the only declaration . . . Read more
What is final in Java? Final is the modifiers applicable for classes, methods, and variables. The main advantage of final keyword is we can achieve security and we can provide the unique implementation. Final keyword improves performance. Not just JVM can cache final variable but also application can cache frequently use final . . . Read more