Posted by: ahmedashfaque | March 7, 2015

Why Java is so popular? Part 7


So far in part 1, part 2, part 3, part 4, part 5 and part 6 we have covered many topics on Java. In this post we will see modifiers.

Modifiers are keywords that you add to those definitions to change their meanings. The Java language has a wide variety of modifiers, including the following:

  •     Java Access Modifiers
  •     Non Access Modifiers

To use a modifier, you include its keyword in the definition of a class, method, or variable. The modifier precedes the rest of the statement, as in the following examples:

Modifier for a class:

public class className {
// …
}

If a class is declared as public then this class can be accessed from anywhere in your source code. Suppose the class className is in package my_package then it can be accessed from another package as my_package.className.

Access Control Modifiers:

Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are:

Visible to the package, the default. No modifiers are needed.
Visible to the class only (private).
Visible to the world (public).
Visible to the package and all subclasses (protected).

Non Access Modifiers:
Java provides a number of non-access modifiers to achieve many other functionality.
The static modifier for creating class methods and variables
The final modifier for finalizing the implementations of classes, methods, and variables.
The abstract modifier for creating abstract classes and methods.
The synchronized and volatile modifiers, which are used for threads.

The modifiers make Java a strong programming language. You can set the access level for all entities including classes, methods and variables. This functionality ensures that you have flexibility as well as total control over what programming elements have access at what level.

Advertisements

Responses

  1. […] far in part 1, part 2, part 3, part 4, part 5, part 6 and part 7 we have covered many topics on Java. In this post we will see […]

  2. […] far in part 1, part 2, part 3, part 4, part 5, part 6, part 7 and part 8 we have covered many topics on Java. In this post we will see loop […]

  3. […] far in part 1, part 2, part 3, part 4, part 5, part 6, part 7, part 8 and part 9 we have covered many topics on Java. In this post we will see nested if […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: