Static vs. Non-Static Java
Categories: Java 8(JDK1.8)
A method in Java is a collection of statements with a name or a method name that are grouped together to perform a task. You can execute the group of statements by calling the method by its name.
1. Suppose you wanted to make a dress from a dress that you already have. You can simply use the original dress to make the new dress. Or, you could make a paper pattern from your original dress and use the paper pattern to create new dresses.
2. A static method in Java belongs to the class and is like the blue print or the original dress. A non-static method in Java belongs to the object of a class and is like the paper pattern made from the blue print or original dress.
3. To create a static method in Java, you prefix the key word 'static' before the name of the method. A static method belongs to the class, and you do not have to create an instance of the class to access the static method. Referring to the dress analogy, a static method would get its design from the original dress.
4. A non-static method in Java does not have the key word 'static' before the name of the method. A non-static method belongs to an object of the class, and you have to create an instance of the class to access the non-static method. From the dress example, a non-static method would get the measurements from a pattern of the original dress.