Skip to main content

Posts

Showing posts from July, 2020

Difference between Final, Finally and Finalize in Java

In your java journey sometimes you confuse about these three final words. but now we remove this confusion in this article. so lets go differentiate these three terms. What is final, finally and finalize in simple terms? Final :- Final is keyword in java. final means it can not be changeable. We can use final keyword in following three cases:- Final Class Final Variable Final Method If we declare class as final then we can not extends that class. if we try to extends final class then we get error. If we declare variable as final means we can not reassign its value means we can not change if we declare variable final. And last id we declare method as final then we can not override that methods. means can not overridden final method. I created full article about Final keyword in java you can check here. FINAL KEYWORD IN JAVA Finally :- Finally is block in java. It is simple block. Finally {     // Finally block     System.out.print("In finally block"); }

Final keyword in Java (Final class, method and variable)

In this article we discuss about what is final keyword, why final keyword is used. What is final in Java? | What is final class, method and variable? In java final is like constant. In java final keyword used with following ways:- final class final variable final methods If final used in java following restriction happens:- If final use with class then that class can not inherited. If final use with variable then we can not change its value. If final use with method then we can not override. In java, String is immutable means we can not change its value. You can see String class is final class. Lets see all of them. Final Class When class declared with final keyword, it is called final class. If class declared with final then that class does not inherited means another class can not extends final class. If we extends final class then it programs give compile time error. Example :- Final Class final class FinalClass {     } public class FinalDemo extends FinalClass{  ...

Static keyword in Java (Static class, variable, method and block)

In this blog we learn about Static Class, Variables, Methods and Block in Java. What is Static Keyword in Java? | What is static class, variable, method and block in java? Static keyword is used for memory management in java. Static keyword used in java with class, variables, methods. We can also use static block in java. Static members are class specific means we can directly access without creating object of class. that is main advantage of static. We can directly use static members using class. In java, Math class have almost static data member using that we can directly work on math function without creating object of that. Static keyword is reserved in java means we can not used as identifiers. Static can be from following :- Static Class Static Variables Static Methods Static Blocks Example :- Static demo using Math class method and variable. class StaticDemo{     public static void main(String args[]) {         double piValue = Math.P...