- Java Programming Basics
- Java Tutorial
- Java Overview
- Java Environment Setup
- Java Program Structure
- Java Basic Syntax
- Java First Program
- Java Constants
- Java Separators
- Java Keywords
- Java Data Types
- Java Data Types
- Java Integers
- Java Floating Point
- Java Characters
- Java Booleans
- Java Numbers
- Java Programming Variables
- Java Variables
- Java Variable Types
- Java Variable Scope
- Java Type Conversion
- Java Type Casting
- Java Auto Type Promotion
- Java Type Promotion Rules
- Java Programming Arrays
- Java Arrays
- Java One Dimensional Array
- Java Multidimensional Array
- Java Programming Operators
- Java Operators
- Java Arithmetic Operators
- Java Increment Decrement
- Java Bitwise Operators
- Java Left Shift
- Java Right Shift
- Java Relational Operators
- Java Boolean Logical Operators
- Java Ternary(?) Operator
- Java Operator Precedence
- Java Control Statements
- Java Decision Making
- Java if if-else if-else-if
- Java switch Statement
- Java Loops
- Java while Loop
- Java do-while Loop
- Java for Loop
- Java for-each Loop
- Java Nested Loops
- Java break Statement
- Java continue Statement
- Java Class Object Method
- Java Classes and Objects
- Java Class
- Java Object
- Java new Operator
- Java Methods
- Java Constructors
- Java this Keyword
- Java Stack
- Java Overloading Recursion
- Java Method Overloading
- Java Constructor Overloading
- Java Object as Parameter
- Java Call by Value Reference
- Java Returning Objects
- Java Recursion
- Java Modifier Types
- Java Encapsulate Poly String
- Java Encapsulation
- Java Polymorphism
- Java Nested Inner Class
- Java Strings
- Java Command Line Arguments
- Java Variable Length Arguments
- Java Inheritance Abstraction
- Java Inheritance
- Java super Superclass
- Java Multilevel Hierarchy
- Java Method Overriding
- Java Abstraction
- Java Packages Interfaces
- Java Packages
- Java Access Protection
- Java Import Statement
- Java Interfaces
- Java Programming Exceptions
- Java Exception Handling
- Java try catch
- Java throw throws
- Java finally Block
- Java Built In Exceptions
- Java Exception Subclasses
- Java Chained Exceptions
- Java Multithreading
- Java Multithreading
- Java Thread Model
- Java Main Thread
- Java Create Thread
- Java Thread Priorities
- Java Synchronization
- Java Inter Thread Communication
- Java Suspend Resume Stop Thread
- Java Get Thread State
- Java Enum Autobox Annotation
- Java Enumerations
- Java Type Wrappers
- Java Autoboxing
- Java Annotation
- Java Marker Annotations
- Java Single Member Annotation
- Java Built In Annotations
- Java Type Annotations
- Java Repeating Annotations
- Java Data File Handling
- Java Files I/O
- Java Streams
- Java Read Console Input
- Java Write Console Output
- Java PrintWriter Class
- Java Read Write Files
- Java Automatically Close File
- Java Programming Advance
- Java Date and Time
- Java Regular Expressions
- Java Collections Framework
- Java Generics
- Java Data Structures
- Java Network Programming
- Java Serialization
- Java Send Email
- Java Applet Basics
- Java Documentation
- Java Programming Examples
- Java Programming Examples
Java Non Access Modifiers
There are following non-access modifiers available in Java programming:
- static
- abstract
- final
- synchronized
- volatile
Java static Modifier
The static modifier in Java, used to create variable, class, method.
You can use static keyword to define static variables in Java. The static variables will exist independently of any instance created for the class. One copy of a static variable exists regardless of number of stances of the class.
You are free to use static keyword to create static method in Java. Static method will also exist independently of any instance created for the class.
Java static Modifier Example
Here is an example program, illustrates the concept of static modifier in Java:
/* Java Non Access Modifier - Example Program */ public class MyTestClass { private static int myNum = 0; protected static int getCount() { return myNum; } private static void add_Instance() { myNum++; } MyTestClass() { MyTestClass.add_Instance(); } public static void main(String[] arguments) { int i; System.out.println("Starting with " + MyTestClass.getCount() + " instances"); for(i=0; i<500; i++) { new MyTestClass(); } System.out.println("Created " + MyTestClass.getCount() + " instances"); } }
Here is the output produced by the above Java program:
Started with 0 instances Created 500 instances
Java final Modifier
The final modifier in Java, generally used for finalizing the implementations of the variables, classes, methods.
A final variable in Java, can be explicitly initialized only once.
A final method in Java, can't be overridden by any subclass.
A final class prevent itself from being subclasses.
Java abstract Modifier
The abstract modifier in Java, used to create abstract method, class.
An abstract class in Java, can never be instantiated.
An abstract method in Java, is simply a method declared without any implementation.
Java synchronized Modifier
The synchronized keyword in Java, used to indicate that a method can be accessed through only one thread at a time.
Java volatile Modifier
The volatile keyword in Java, is used to let the JVM know that a thread accessing the variable must ever merge its own private copy of variable with master copy inside the memory.
« Previous Tutorial Next Tutorial »