
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
What are the differences between access modifiers and non-access modifiers in Java?
Access Modifiers
Access modifiers are the keywords which are used with classes, variables, methods, and constructors to control their access level.
There are four access modifiers in Java.
Default
When no access modifier is specified, java is treated as a default modifier. The scope of the default modifier is limited to within the package.Public
The scope of public modifier is to access everywhere and even outside the package.Private
The scope of private modifier is to access within the class itself.Protected
The scope of the protected modifier is limited within the package and all subclasses.
Non-access Modifiers
Non-access modifiers are those keywords that do not have anything related to the level of access but they provide a special functionality when specified.
Final
Final keyword can be used with variable, method or class. It prevents from its content from being modified. When declared with class, it prevents the class from being extended.Static
The static modifier is used with class variables and methods which can be accessed without an instance of a class. Static variables have only single storage. All objects share the single storage of static variable. They can be accessed directly without any object. Static methods can also be declared. the main() method is the popular static method. Static blocks can also be declared and are executed before main() method.Abstract
abstract can be used with class and methods. An abstract class can never be instantiated and its purpose is only to be extended. Abstract methods are declared without body and end with a semicolon. If a class contains an abstract method, it should also be specified as abstract. A class which extends an abstract class must implement all of its abstract methods.Synchronized
It indicates that the method can be accessed only by one thread at a time.Transient
An instance variable is marked as transient to indicate the JVM to skip the particular variable when serializing the object containing it.Volatile
Volatile keyword is used to mark a java variable as "being stored in main memory". It means that every read of a volatile variable will be read from the computer's main memory and not from the CPU cache and writes to a volatile variable will be written to main memory and not just to the CPU cache.Strictfp
Strictfp keyword in java ensures that you will get the same result on every platform if you perform operations in the floating-point variable.
- Related Articles
- What are access modifiers and non-access modifiers in Java?
- Access and Non Access Modifiers in Java
- Non Access Modifiers in Java\n
- What are final, abstract, synchronized non-access modifiers in Java?
- How many non-access modifiers are there in Java?
- Access Modifiers in Java
- What are access modifiers in C++?
- Types of access modifiers in Java?
- What are private, public, default and protected access Java modifiers?
- Access Modifiers in C#
- Access Modifiers in C++
- java access modifiers with method overriding
- method overriding with access modifiers in Java
- What are different types of access modifiers available in C#?
- Access Modifiers in Python : Public, Private and Protected

Advertisements