This article is a record of what I understand for those who are studying Java.
From now on, Java functions and description methods will be described in the following list.
・ Variables, types, and type conversion https://qiita.com/pitan109/items/2538b234a2c6e20c037f -Variable scope https://qiita.com/pitan109/items/b30589bc4c2e8169734c ・ Character string operation (in preparation) ・ Array operation (in preparation) ・ Operator (in preparation) ・ Conditional branch (in preparation) ・ Repeat processing (in preparation) ・ Exception handling (in preparation) ・ About class (in preparation) ・ Abstract class (in preparation) ・ Interface (in preparation) ・ Encapsulation (in preparation) ・ About the module (in preparation)
This time, I will list an overview of what you should remember when using Java and a comparison with Ruby because I used Ruby myself.
5/11 update Added common points and advantages and disadvantages of each method 5/12 update Added table of contents
To put it simply, a compiler (compile) is to change all the code into a computer-readable form before executing it. This is adopted in Java. C ++ is also a compiler method. Ruby and python are interpreted methods. The interpreter translates line by line and executes it. Let's see what the difference is.
$ ruby hello.rb
When you run it in the interpreter, you'll see what's happening in your code. compiler #### **`$ javac hello.java `** ```java Since this example is Java, we will explain it with Javac commands. The compiler enters the commands to compile and produces a computer-aware class file. Now that you have a Hello class in the hello.java file, run it. ```$ java hello``` This will execute the processing in the class. Keep in mind that you can't run Java without following this procedure. ## Variable type, type conversion In Java, you need to statically type variables. String str = "character type"; I am creating a variable called str with a character type (String), but I cannot assign an element of another type such as a numeric type (int) to it. In Ruby str = "character type" Can be described as. After this because there is no association str = 1 It is okay to write. You can also type convert in Java. It is used when you want to refer to this variable with this type. Type conversion is also possible in Ruby, and the idea is the same, except that the description method is basically different. Java ```java String str = (String)10;
str = 10.to_s
Details on variable type specification and type conversion in Java can be found here. https://qiita.com/pitan109/items/2538b234a2c6e20c037f
In both Java and Ruby, the range in which variables can be referenced changes depending on where the variables are written and the description method. There are various ways of writing in Java and Ruby, but the idea is the same, and I think that what I learned in Java can be applied to Ruby.
The reference range and description method of variables in Java are described in detail here. https://qiita.com/pitan109/items/b30589bc4c2e8169734c
Since I was using Ruby this time, I will also describe the common parts as a bonus. It's an object-oriented language and you can use interfaces. I won't go into the details of how to write it here, but if you have an object-oriented or interface concept and you are learning one language, The other way of thinking can be used almost as it is, so I think it is recommended to learn one object-oriented language, not limited to Java and Ruby.
This time, I tried to summarize the main functions of Java while comparing it with Ruby. I also referred to this article. https://codezine.jp/article/detail/2144