Core Java Tutorials


Introduction

Java Hello World

Java Compilation

JDK New Features

JVM Architecture

Java OOPs Concepts

Java Package

Array

Exception Handling

String

Immutable Class

File Handling

Serialization

MultiThreading

Volatile

Concurrent Package

Collection

Collection Internal

Generics

Cloning

Reflection In Java

Annotation

Class Loader

Java Inner classes

Garbage Collector

JDBC

References In Java

Heap Dump & Thread Dump

static keyword in java

static keyword in Java is used to access attributes and behaviors of a class instead of it;s instance of class. So static keyword is features of a class not object or instance of a class. We can use static keyword with class , method ,block and variable.

static keyword static variable :-
Static variable is used to define class variable. Memory for static variable are created inside Method Area once class is loaded into the memory(Method Area) and static variable define the state of the class not state object. So we can access static variable with class name with out creating instance of the class.

static-variable

Main Method Code Snippet : -
static-keyword-in-java



static keyword static method :-
Static method is used to define behavior of a class. Unike non static method, static method is invoked with class name directly and it does not require to create instance of the class. Static method can access only static variables and other static methods of the class.

static-method-in-java


static keyword static class :-
static class is static class member inside the top level class.
Features of Static Inner Class..
   1.  Static inner class can access only static members of outer class.
   2.  Static inner class can not access not static members of outer class.
   3.  A static inner class is just like any other inner class, but it does not have the reference to its outer class object that generated it.

Example Code :
inner-static-class




static keyword static block :-
Static block is generally used to assign the default states to the static variables.static block gets executed when the class is loaded in the memory. Static block are executed automatically and it will be invoked only once. A Static blocks can come multiple times inside a class , which will execute in the same sequence in which they have been written into the program.

static-block-in-java