final ???? Java?? ??? ???? ???? ???? ?? ???? ?? ? ?????. ??? ?? ?? ??? ? ?? ??? ???? ? ?????. ? ?????? ??? ???? final ???? ?? ??? ??, ?? ?? ? ???? ??? ??? ???????.
1. ??? ??? ??
??? ?? final? ???? ?? ???? ??? ??? ? ????. ??? ??? ??? ????.
- ?? ?? ??: ??? ??? ?????(?: COUNT).
- ??? ?? ??: ???? ??? ?? ????? ???.
- ?? ???? ????? ???: ????? ????? ?? ?? ???? ?? ???? ???.
- ?? ??: ?? ??? ??? ? ???? ?? ??? ?? ??? ??? ? ????.
final int COUNT; final char GENDER = 'F'; // Initialized at declaration public FinalKeyword() { // Initialized in Constructor COUNT = 90; // This will give a compile error // once initialized during declaration, cannot be changed GENDER = 'M'; }
?? ???:
- COUNT? ?? ? ????? ????. ? ????? ????? ???.
- GENDER? 'F'? ????? ?? ???? ??? ? ????.
2. ?? ??? ??? ??
?? ?? ??? ?? ? ?? ?? ???? ?????? ???. ???? ??? ?? ?? ?? ??? ??? ?? ??? ????? ???? ? ????.
- ?? ??? ?? ????? ?? ???? ????.
- Final? ???? ?????. ?, ?? ?? ????? ???? ??? ? ????.
static final int ID = 1; static final int DEPT; static { DEPT = 90; // Initialized in static block }
????? ?? ?? ??? ???? ? ?? ??? ??????
????? ??? ? ???? ???? ?? ??? (????? ??) ???? ????? ??? ??? ?????? ??? ? ????.
3. ?? ??? ?? ?? ??
final? ???? ??? ??? ????? ??? ? ????.
static int salary; // Default value 0 at class loading public FinalKeyword() { salary = 10; // Static variable modified in constructor }
Key Differences
- Static variables are shared across instances and can be modified by any of them.
- Static final variables are immutable and shared by all instances, ensuring they remain constant throughout the program.
4. Constructor Requirements for Final Variables
When a final variable is not initialized at the time of declaration, it must be initialized in all constructors to avoid a compile-time error.
public FinalKeyword() { COUNT = 90; // Initialized in default constructor } public FinalKeyword(int count) { COUNT = count; // Initialized in parameterized constructor }
If a constructor does not initialize a final variable, the compiler will throw an error, ensuring the value is always assigned exactly once.
4. Comparison of Final Keyword Usage in Methods and Classes
Usage | Effect | Example |
---|---|---|
Final Method | Cannot be overridden in subclasses. | public final void getType() in java.lang.Object |
Final Class | Cannot be inherited by any class. | java.lang.String, java.lang.Math |
- Final Methods: A final method ensures that subclasses cannot override it, enforcing consistent behavior across all instances. This is useful for methods like getType() in Object, which ensures critical functionality is not altered.
- Final Classes: Declaring a class as final (e.g., String or Math) ensures that no subclass can alter its behavior, maintaining data integrity and preventing misuse.
Conclusion
The final keyword is a powerful tool in Java to enforce immutability and prevent unintended modifications. It plays a crucial role in defining constants, ensuring class-level consistency, and making code easier to understand and maintain.
Stay tuned for other posts in this series, where we’ll cover more Java keywords in depth to help you master the nuances of the language!
Related Posts
Java Fundamentals
Array Interview Essentials
Java Memory Essentials
Collections Framework Essentials
Happy Coding!
? ??? Java? ?? ??? ?????: ??, ??? ?? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

Java? ??? ?? ??, ?? ? ??? (? : Projectreactor) ? Java19? ?? ???? ??? ??? ?????? ?????. 1. CompletableFuture? ?? ??? ?? ?? ??? ? ?? ??? ????? ?? ??????? ? ?? ??? ?????. 2. Projectreactor? ?? ? ??? ??? ???? ?? ???? ? ??? ???? ?? ? ?????? ?????. 3. ?? ???? ??? ??? ??? I/O ??? ? ??? ???? ?? ??? ????? ??? ???? ????. ? ???? ?? ??? ????? ??? ??? ??? ?? ??? ??? ?????? ???? ???? ?? ?? ??? ??????.

Java?? ??? ?? ?? ??? ???? ? ?????. ?? ???? ??? ?????. 1. ?? ?? ? ???? ??????? ?? ?? ?? ??? ???? ??? ?????. 2. ?? ??, ???, ??? ?? ?? ?? ???? ????? ?? ??? ??? ??? ?????. 3. ENUMMAP ? ENUMSET? ???? ?? ? ?? ???? ???? ??? ???? ? ?????? ?????. 4. ?? ?, ??? ?? ?? ??? ?? ????? ?? ??? ??? ?????.? ????? ?? ???? ????????. ??? ???? ???? ?? ??? ????? ??? ?? ? ??? ?? ?????? ???????.

Javanio? Java 1.4? ?? ? ??? IOAPI???. 1) ?? ? ??? ?????, 2) ??, ?? ? ??? ?? ?? ??, 3) ? ??? ??? ???? 4) ?? ??? ?? IO?? ? ????? ?????. 1) ? ?? IO? ??? ?? ??? ???, 2) ??? ??? ?? ???? ?????, 3) ???? ?????? ???? 4) ??? ?? ??? ?? ?? ? ??? ?????. 1) ??? ??/??? ??? ?? ?????, 2) ???? ???? ???? ?? ???? ???????. 3) ??? ??? ??? ???????.

Java? ????? ????? ??? ??? ?? ???? ?? ?? ??????, ?? ? ???? ? ??? ????. ?? ???? ??? ??? ???? ??? ??? ???? ?? ??? ??? ????. ???? ???? ??? ??, ?? ??? ???? ???? ?? ??? ?? ???? ?? ?????. ???? ?? ?? ??? ?? ?? ??? ?????. ?????? ?? ??? ??? ???? ?? ??? ??? ?? ??? ???? ???? ??? ?? ??? ?????? ???? ????? ??? ?? ?? ???, ?? ? ?? ???? ??? ??? ?????. ???? urlclassl? ?? ??? ??? ??? ?? ? ? ????

Java ?? ??? ??? ?? ? ??? ???? ?? ??? ???? Try-Catch? ???? ????? ????? ???? ????. 1. IoException? ?? ?? ? ??? ???? ?? ??? ??? ?? ???????. 2. NullPointerException? ?? ???? ?? ??? ????? ???? ?? ??? ?? ???? ??? ?????. 3. ??? ?? ? ?? ??? ???? ??? ??? ?? ????? ???????. 4. CODE? ?? ??? ??? ?? ??? ???? ??? ???? ??? ???? ?? ?? ????. 5. ?? ???? ??? ??? ?? ??? ??? ?? ???? ??? ???????.

?? ?? Java? ?? ???? ?? ? ? ? ????? ????, ? ??? ??? ??? ??? ???? ? ????. 1. ?? ?? hashcode () ???? ???? ?? ?? ???? ?? ??? ?? ?? ???? ?????. 2. ?? ??? ??? ?? ?? ???? ??? ??? ? ????. ?? ??? ?? ? ??? ??? ?????. JDK8 ? ?? ? ??? ?? ?? (?? ?? 8) ??? ????? ?? ???? ?? ? ??? ?????. 3. ??? ?? ???? ?? ???? ?? equals () ? hashcode () ???? ?? ???????. 4. ?? ?? ??? ???? ?????. ?? ?? ??? ???? ?? ?? (?? 0.75)? ??? ?? ? ???; 5. ?? ?? ??? ??? ??? Multithreaded?? Concu? ???????.

???? Java ?? ?? ?????? ?? ?? ? ?????. ??? "??? ?????, ?? ??"? ????. ??, ??? ? ?? ? ?? ??? ?? ?? ??? ??? ???? ?? ?? ? ?????? ?????. 1. ???? ?? ???? ?? ??? ??? ?? ? ?????, ?? ??? ??? ?? ?? ??? ?? ?????. 2. ??? ?? ??, ?? ? ?? ? ?? ??? ? ?? ??? ??????. 3. ?? ?? ?? ??? ??, ??? ?? ? ??? ?? ??? ???? ???? ? ?????. 4. ???? ?? ???? ?? ?? ? ??? ? ?? ? ? ????. ?? ???? ?? ? ??? ??? ????? ???? ??????? ?? ?????? ???????.

Java ??? ??? ???? ??? ??? ??? ?????, ???? ????, ?????? ??? ? ????. 1. ??? ????? ???? ??? ? ? ??? ?? ?? ????? ???? ? ???? ??????. 2. ???? ?? ?? ???? ??? ??? ???? ?? ?? ???? ??? ??? ? ????. 3. ???? ???? ??? ??? ?? ??? ?? ? ? ??????. 4. ?? ?? ?? ??? ? ??? ??? ?? ????? ?? ?? ??? ??? ? ????. 5. ??, ?? ?? ??, ?? ?? ?? ???, ????? ?? ?? ? ???? ??? ????? ??????.
