[JAVA] [Personal memo] I learned a little about modifiers

Self-introduction

This is my first year as a member of society who has just studied Java. In the comments of the following article I wrote yesterday, the words "** access modifier " and " class design **" came up, so I am writing this article to study and summarize them. https://qiita.com/N46_myHearter/items/891b660b8748171779b1

We are looking for advice on Java.

What is a modifier?

It can be specified for classes, methods, and variables, and it seems that there are various effects depending on the specified modifier. I only knew about access modifiers such as public private when it was a modifier in Java, but there are a lot of modifiers lol

I knew about access modifiers, abstract, static, final, but what are transient, volatile, synchronized, native, strictfp ....! ?? LOL

Access modifier

There are public, protected, and private, and it seems to indicate where the class and its variables and methods that are designing access modifiers can be accessed.

  1. ** public ** accessible from all classes
  2. ** protected ** accessible from current class and its subclasses
  3. ** private ** Only accessible from the current class

The accessible range is like public> protected> private.

abstract modifier

Class methods that have abstract set are called abstract class methods. .. .. (The abstraction I studied yesterday came out right away ...) If the parent class has abstract set, its child class must be overridden.

** Abstract method ** A method that has no body and consists only of method names, arguments, and return values.

** Abstract class ** A class that contains abstract methods. You will not be able to instantiate and you will need to create an inherited subclass.

static modifier

If static is set, it can be accessed without instantiation (I think you can understand it because it was static even in C language ... lol). Can be specified for variables and methods. It cannot be overridden. It must be accessible by class name.member name.

** Instantiation ** Make the class accessible and available (Is it initializing the class !?).

final modifier

When final is set, it seems to prohibit overriding members, overriding in subclasses, inheritance in extends clause, etc. It can be specified for classes, variables, and methods, and the meaning changes depending on what is specified.

** If specified in class ** The specified class cannot be inherited.

** When specified as a variable ** The specified variable is a constant (initialization is required when the variable is declared, and after that, the variable The value cannot be changed).

** When specified in method ** The specified method cannot be overridden.

override Redefining what is defined in the parent class in the child class (like inheritance).

transient modifier

If transient is set, it seems to be excluded from serialization (what is serialization ... lol). Can be specified as a variable.

** Serialize ** Converting an object to a byte array.

volatile modifier

If volatile is set, it seems to exclude it from the cache. Can be specified as a variable.

synchronized modifier

If synchronized is set, the method will be executed synchronously. Can be specified in the method.

** Synchronous execution ** When there are multiple calls at almost the same time, give priority to the one who called first, and let the one who called later wait until the processing is completed.

native modifier

If native is set, it means that it is implemented in a language other than Java (maybe you can use another language in your Java program). Can be specified in the method.

strictfp modifier

If strictfp is set, it seems that it is possible to handle floating point strictly. Can be specified for a class or method.

end

It's just a note that Java beginners have studied, so the content is thin lol Since there are many modifiers, I'm thinking of studying more from access modifiers first (others will be postponed ww).

Recommended Posts

[Personal memo] I learned a little about modifiers
I learned about the existence of a gemspec file
[Personal memo] About Spring framework
Personal memo Progate Ruby I (2)
Personal memo Progate Ruby I (1)
What I learned about Kotlin
I tried a little digdag docker.run_options
A little summary about typesafe config
[Rails] I learned about migration files! (Adding a column to the table)
[MVC model] A memo that a beginner learned MVC
[Rails] What I learned from a little stumbling block when using ancestry
[Personal memo] Writing a file using BufferedWriter
I tried playing with BottomNavigationView a little ①
Rails: A little summary about data types
[Personal memo] Reading a file using BufferedReader
I have a question about Android studio.
[Personal memo] A small story about CPUs settings of Docker Desktop for Windows
Summary of what I learned about Spring Boot
[Rails] I learned about database data type types!
[Swift] [Beginner] I searched a lot about #selector
What i learned
About access modifiers
[Rails] I learned about the difference between resources and resources
I tried to decorate the simple calendar a little
I want to use a little icon in Rails
I will write what I learned about docker anyway (second)
[Personal memo] Make a simple deep copy in Java
[Personal application work memo] Make a calendar with simple_calendar
[Personal memo] I tried to study object orientation lightly
What I learned when building a server in Java
I will write what I learned about docker anyway (first)
I have a question about keyboard input of numbers