How to name variables in Java

Summary articles everywhere

Among them, there are good articles that are concisely organized.

Java language naming guidelines https://qiita.com/rkonno/items/1b30daf83854fecbb814

I agree with what is written here and think it should be. But what if you can't think of a good name?

basic rule

Assuming that you follow the coding conventions in your project, I think the following is desirable:

Concrete example

FileOutputStream

For example, consider the name of a variable that stores a FileOutputStream that is used to output some processing result.

And so far. As the wise reader may have noticed, ** putting a type in a variable name doesn't make much sense **. Nowadays, it's easy to see what the variable type is in the IDE, and even if you don't use the IDE like me, it's okay if you make the class or method ** simple enough to easily see where the declaration is. .. The method arguments are of course explained in the ** API documentation **, so you don't need to put the type name in the argument name.

So what is a better name? As mentioned in the above article, ** I think the name is good because you can imagine the contents of the data by looking at the name **. In my own words, ** give it a name that describes who it is **.

For example

It feels like.

XxxxService

Example


public class XxxxController {
    /**
     *A service that handles the business of Xxxx.
     *Since it is an implementation policy to substitute by constructor injection, here{@code @Autowired}Do not attach.
     */
    private final XxxxService service;

I want to hear the pride of having a good name

I would be grateful if you could introduce in the comments what kind of class, what kind of field, what kind of method, what kind of local variable, with such a good name (or I thought it was amazing).

Recommended Posts

How to name variables in Java
How to use Java variables
How to learn JAVA in 7 days
[Processing × Java] How to use variables
How to use classes in Java?
How to concatenate strings in java
How to get the class name / method name running in Java
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
How to change app name in rails
How to name variables 7 selections of discomfort
How to do base conversion in Java
How to implement coding conventions in Java
How to get the date in java
How to use environment variables in RubyOnRails
How to display a web page in Java
How to get Class from Element in Java
How to hide null fields in response in Java
[Java] How to substitute Model Mapper in Jackson
How to solve an Expression Problem in Java
How to write Java String # getBytes in Kotlin?
How to get Excel sheet name list in Java (POI vs SAX)
[Java] How to use Map
How to lower java version
[Java] How to use Map
How to uninstall Java 8 (Mac)
Java --How to make JTable
How to write java comments
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to display Wingdings
How to use Java Map
How to set Java constants
How to convert Java radix
[Java] How to implement multithreading
[Java] How to use Optional ①
How to initialize Java array
How to embed JavaScript variables in HTML with Thymeleaf
How to call functions in bulk with Java reflection
How to create a Java environment in just 3 seconds
[Java] How to omit the private constructor in Lombok
How to input / output IBM mainframe files in Java?
[Java] How to extract the file name from the path
How to create a data URI (base64) in Java
How to generate / verify ID token in Java Memo
How to convert a file to a byte array in Java
How to Git manage Java EE projects in Eclipse
Summary of how to implement default arguments in Java
How to put old Java (8 series) in macOS 10.15 Catalina
Notes on how to use regular expressions in Java
How to use Lombok in Spring
How to find May'n in XPath
How to study Java Silver SE 8
How to use Java HttpClient (Get)
How to hide scrollbars in WebView
How to run JUnit in Eclipse
How to iterate infinitely in Ruby
Studying Java # 6 (How to write blocks)
How to use JSON data in WebSocket communication (Java, JavaScript)