[Java] How to use static modifiers (What are static final and static import)

Programming study diary

November 7, 2020 I didn't understand Java's static final and static import, so I'll summarize the static modifiers.

What is a static modifier?

Used to access methods and variables directly without instantiating the class. Methods with static are called static methods, and variables are called static variables.

How to use static class

In Java, static class is used in the inner class (inner class) that defines the class in the class. The inner class can access members such as variables of the outer class. Adding the static modifier to the inner class allows access only to the static members of the outer class.

How to use static methods and static variables

A static method is a method that can be called without creating an instance using new by adding a static modifier to the method, and it is not necessary to create an instance every time the method is called, so the code can be written short. ..

A static variable can be accessed by adding the static modifier to the variable without instantiating the class that contains the variable. A static variable is a value shared by all instances created from that class, so it can be used like a global variable.

How to use static final and static import

static final can be used when you don't want the value of a variable to change, and can be a constant whose value cannot be changed </ b>. There are methods such as initializing multiple constants using a static initializer and using List and Map as constants.

static import is a function to simplify the reference of static members of external classes. Calling methods and constants is simplified, allowing you to write processing in concise code.

References

[Introduction to Java] Summary of how to use static modifiers

Recommended Posts

[Java] How to use static modifiers (What are static final and static import)
How to use Java classes, definitions, import
[Java] How to use FileReader class and BufferedReader class
[Java] How to use Calendar class and Date class
[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
[java] Reasons to use static
How to use Java variables
[Java] How to use Optional ①
What happened in "Java 8 to Java 11" and how to build an environment
How to call and use API in Java (Spring Boot)
How to use StringBurrer and Arrays.toString.
How to use Java HttpClient (Get)
How to use EventBus3 and ThreadMode
How to use Java HttpClient (Post)
How to use equality and equality (how to use equals)
[Processing × Java] How to use variables
[Java] How to use LinkedHashMap class
[JavaFX] [Java8] How to use GridPane
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
[Java] What are overrides and overloads?
How to use OrientJS and OrientDB together
[Java] How to use the File class
[Java] How to use the hasNext function
JAVA learning history final modifier and static modifier
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
[Java] How to output and write files!
How to set up and use kapt
[Easy-to-understand explanation! ] How to use Java polymorphism
[Java] [Maven3] Summary of how to use Maven3
[Processing × Java] How to use the class
How to use Java Scanner class (Note)
[Processing × Java] How to use the function
[Easy-to-understand explanation! ] How to use ArrayList [Java]
How to use substring and substr methods
[Java] How to use the Calendar class
[Java] Learn how to use Optional correctly
How to use @Builder and @NoArgsConstructor together
[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
[Java] Note how to use RecyclerView and implementation of animated swipe processing.
[Java] How to use Thread.sleep to pause the program
[Ruby] How to use gsub method and sub method
[Swift vs Java] Let's understand static and final