✔ JAVA CHAPTERS:-
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
Super Keyword in Java: Previous Next: Final Keyword in Java
Static Keyword In Java
Static is a keyword in java used to represent the class members. It can be used with variable, method, initializer block and nested class.
Types of class members:
- 1. Static data members.
- 2. Static initializer block.
- 3. Static method.
- 4. Static nested class.
1. Static data members:
Data members declared with static keyword are known as static data members. These are mainly used to represent those properties which are common to every object. At the time of class loading a single copy is created for static data members, which is shared by all objects.
Memory division in a java program execution.
In a java program execution memory is divided into three parts:
- 1. Stack.
- 2. Heap.
- 3. Class/Method area.
1. Stack: Stack is used to local variables of the methods.
2. Heap: Heap is used to store objects.
3. Class Area: Class area is used to store static data members.
Static data members are used to represent those properties which are common to every object.
Example:
StaticExample1.java
Output:
Non-static data members have different memory locations for different objects.
Example:
StaticExample2.java
Output:
Static data members use the same memory locations for all objects.
Example:
StaticExample3.java
Output:
Note: Constructor is not used to initialize the static data members because constructor initializes many times but static data members only once. So instead of constructor static initialize block is used to initialize static data members.
Static methods:
Static methods represent the behavior of whole class. An instance of a class is not required to execute static methods. They can be called using class name.
Syntax: ClassName.methodName
Syntax: ClassName.methodName
Example:
StaticExample4.java
Output:
Note: We can execute a program without main method.
Example:
Output:
Limitations of static methods and static initialize blocks.
- 1. Non-static data members can’t be accessed in static methods and static initialize blocks.
- 2. Non-static methods can’t be invoked in static methods and static initialize blocks.
- 3. This or super keyword can’t be refers in static methods and static initialize blocks.
1. Non-static data members can’t be accessed in static methods and static initialize blocks.
Example:
StaticExample5.java
Output:
2. Non-static methods can’t be invoked in static methods and static initialize blocks.
Example:
StaticExample6.java
Output:
3. This or super keyword can’t be refers in static methods and static initialize blocks.
Example:
StaticExample7.java