[java] Reasons to use static

Since it was unclear how to use java properly, such as static, I investigated it.


If you add a static modifier to a method or member variable, it becomes a static method or static variable. What changes with the static modifier is that you can access the method and member variables without new.


In other words, use it when you want to share common methods and variables between classes. I wrote an article about exchanging data through the Application class before, but it's the same. https://qiita.com/QiitaD/items/549fb2143b2774c30d72

(Even so, the static uncle laughed as expected ...)

Another thing is that it can be used without instantiation. It seems that the Utility class etc. do not need to be instantiated because the processing is completed by the method alone, that is, the usage is fixed when the class is defined. In that case, it is also static. https://teratail.com/questions/13203


I understand static, but I don't know public or final yet. Needless to say, public and private are used properly from the viewpoint of object-oriented design. But I don't know why protected or defaults exist (although I know there are differences in access), so I'd like to find out too.

Recommended Posts

[java] Reasons to use static
[Java] How to use Map
[Java] How to use Map
How to use java Optional
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to use string.format
How to use Java Map
How to use Java variables
[Java] How to use Optional ①
Java static
How to use Java HttpClient (Get)
How to use Java HttpClient (Post)
[Processing × Java] How to use variables
[Java] How to use LinkedHashMap class
How to use class methods [Java]
[Java] How to use List [ArrayList]
How to use classes in Java?
[Processing × Java] How to use arrays
How to use Java lambda expressions
[Java] How to use Math class
How to use Java enum type
Reasons to use Servlet and JSP separately in Java development
Whether to use Java Comparable or Comparator
[Java] How to use the File class
Use TMDA to parse IBM Java javacore
Java static story
[Java] How to use the hasNext function
Java Artery-Easy to use unit test library
How to use submit method (Java Silver)
[Java] How to use the HashMap class
[Easy-to-understand explanation! ] How to use Java instance
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
How to use Java classes, definitions, import
[Easy-to-understand explanation! ] How to use Java polymorphism
[Java] [Maven3] Summary of how to use Maven3
[Java] Introduction to Java
[Processing × Java] How to use the class
How to use Java Scanner class (Note)
[Processing × Java] How to use the function
[Java] Use Collectors.collectingAndThen
Introduction to java
[Easy-to-understand explanation! ] How to use ArrayList [Java]
[Java] How to use the Calendar class
[Java] Learn how to use Optional correctly
[Easy-to-understand explanation! ] How to use Java overload
try-catch-finally exception handling How to use java
[Easy-to-understand explanation! ] How to use Java encapsulation
Use static initialization block to initialize List / Set of static fields in Java
Use jenv to enable multiple versions of Java
[Java] How to use FileReader class and BufferedReader class
[Java] How to use Thread.sleep to pause the program
How to use Java framework with AWS Lambda! ??
I want to use java8 forEach with index
How to use Java API with lambda expression
[Easy-to-understand explanation! ] How to use Java inheritance [Override explanation]
How to use the replace () method (Java Silver)
How to use Alibaba Cloud LOG Java Producer
[Java] How to use Calendar class and Date class