Java beginners stop relying solely on their senses

Change log

--July 21, 2020 Data types do not need to be memorized in detail! ~~ Add ~~ Add </ font> --July 20, 2020 ~~ Tag correction ~~ Tag correction </ font>
** Before change ** #Java #Beginner #Programming beginner
** After change ** Java beginner programming beginner
@shiracamus Thank you for your editing request m (_ _ "m) | --July 19, 2020 Preface / Naming convention / Type inference ~~ Addition ~~ Addition </ font>

The reason for writing an article (preface)

I want to output something, I want to develop the ability to communicate well! I want to improve my writing skills! I thought about writing for various reasons such as. (I can't really say I want a lot of LGTM) If you like it, please push it and go home ♪

  • There are strikethroughs in some places. I'm just modifying the article later to make it easier to read, so don't worry, m (_ _ "m)

In this article, I will only describe the knowledge that I re-understood with the feeling of "Hey, was that so?" Please note that this article is not intended for those who want to cover the basics. Also, I would appreciate it if you could point out any mistakes m (_ _ "m)

The link I referred to this time is also posted at the end of this article. I want to know more details! Please refer to that for those who are.

From the conclusion, The opportunity for me to relearn the basics came from one red shame ♪

Please read the following if you are free! (^^)!

I started programming in April a year ago! I was completely inexperienced, when I was an amateur who didn't even understand how the html table works (゚ Д ゚) I can't do it better than others in the training. .. The first site was an integration test, and I was actually allowed to do the coding around mid-January this year. I was rushed to the site with my basic knowledge halfway, and I didn't know right or left, so I caused trouble to my seniors so much that I couldn't fit with both hands (~ _ ~;) Although I am such a person, I coded with a complete sense while being taught, and for about half a year, my seniors said, "Why don't you help educate newcomers if you like Chibi Maro?" \ (^ _ ^) / (I wasn't confident, but I also wanted to experience OUTPUT (*  ̄ ▽  ̄)

So when I tried to teach it, I realized that ** I couldn't convey what I was asked ** + ** There were many things I didn't understand because I thought I understood it **. Explaining what I understand doesn't convey well. After all, I was ashamed that my seniors pointed out mistakes in front of my juniors (_ _.) ... Shun

table of contents

-[Notation used for class name / variable naming convention](# link1) -[Java had a guy (specification) called "type inference"! ](# Link2) -[Data types do not need to be memorized in detail! ](# Link3)


We will start the main subject from here!

Notation used for class name / variable naming conventions

Notation name Notation example rule
Upper camel case SampleWord Start writing in uppercase. In the case of multiple words, only the beginning of the word is capitalized.
Lower camel case sampleWord Start writing in lowercase. For multiple words, capitalize the beginning of the second word.
Snake case sample_word Write in all lowercase. Use underscores for word joints instead of using uppercase letters.
Pascal case SampleWord アッパーキャメルケースと同じ。一般的にキャメルケース=ローワーキャメルケースと考える人が多いため、アッパーキャメルケースはPascal caseと呼ばれる。

There was a thing (specification) called "type inference" in Java!

In Java 10 and later, the data type can be omitted when declaring a variable by using the var keyword. Hmm? ** What do you mean? ** Upon closer examination, I found that it was as follows!

//Variable initialization without type inference

Stiring sampleWord = "Hello Wordl!";  /*String type*/ 
int sampleNum = 10;   /*Numeric type*/ 

//Variable initialization when using type inference
var sampleWord = "Hello World!";
System.out.println(samoleWord); //Result Hello World!

var sampleNum = 10;
System.out.println(samoleNum); //Result 10

What a surprise! !! Σ (゚ Д ゚) It seems that the Java side (compiler) automatically infers what type ** it is from the initial value and automatically specifies the type (type inference) without specifying the data type of String or int. is! However, please note that "a thing that specifies a type once cannot be replaced with another type". You can see it by looking at the following. Looking at the above example, the type of the variable to which "Hello World!" Is assigned is String as a result of inference. Since the variable "sampleWord" is determined to be a String at the time of declaration, an int type value cannot be assigned.

var sampleWord = "Hello World!";
sampleWord = 10;

//Result compilation error

There are the following points to note when using other vars.

--Initial value cannot be omitted (to infer the type from the initial value) --Cannot enumerate multiple variables (enumeration is something like * 1) --Only local variables can be used

※1  var sampleNum = 1, sampleNum2 = 2;

Data types don't have to be remembered in detail!

There are two main types of data.

--Primitive type (basic type) --Reference type

Let's start with a light explanation from primitive types

** I don't remember integer and floating point ~ bytes! !! ** **

To explain in detail, there is a rule that each integer type is up to ~ digits.

1 byte = 1 single-byte alphanumeric character 2 bytes = 1 Japanese character

・ 5=1 byte
・ K=1 byte

·Ah=2 bytes
・ Vertical=2 bytes

Integer type byte is a byte unit. You can assign a larger number for int than for short. You can substitute a number whose long is larger than int. About (laughs)

The small number of digits will be a hit as soon as you google. (In my case, I've only used int for integer types)

Floating point is similar to integer type. You can assign a number that is larger for double than for float.

Even if you don't memorize it completely, you can just google it if you know the mechanism and existence to some extent. The net is convenient (*  ̄ ▽  ̄)

** Reference type ⇒ Interfaces will be described later in the chapter on inheritance and interfaces. ** **

データ型 img.png

Reference site

-Classification of notation used for variable / class name naming convention -Variable and function naming convention: Difference between snake case, camel case and Pascal case -Type inference -Data type