Last time I will continue with Progate free lessons.
From this time it will be Java. I did it for about two years in business. Knowledge and skills are still shallow.
Java lessons seem to be free up to Java II. Lesson List
Java I Official lesson
I would like to introduce Eclipse. Update to the following: https://mergedoc.osdn.jp/
I'm going to make it a Full Edition that includes Tomcat etc. Java is also included.
It takes a lot of time to download ...
・ ・ ・
** It takes too much **
It took more than an hour, and half of the downloads haven't progressed. I'm sorry, but I would like to use the previously downloaded version of Eclipse. It's about 2018 ...
It was June 2019 w
-Create a test project. I set the JRE to 12. What can 12 do ...
Eh ... what is module-info.java ...
I was allowed to reference. → Learn the module system
Let me run away from time to time ...
Let me create a class with Torima
public static void main.
Right click on src → add new → class
The package name is appropriate.
Check the item that automatically generates
public static void main.
Oh, I made the appearance (theme) of Eclipse look like C #, so I will change it to a dark theme.
I will return to the lesson from here.
-Java is for batch processing
public static void main
Method is called first. The beginning of all processing.
This method can be in any class.
However, at runtime
java class name argument
public static void main of the class specified in the class name of is called.
-Display processing on the command line
Will be. In terms of console in the browser, puts for Ruby, echo for PHP, Console.WriteLine for C # ...
By the way, this time it's Java, so it needs to be compiled. I didn't need it because it was an interpreted language.
** Exercise ** We will do this.
When executing from Eclipse, right-click the class with
public static void main → execute or debug → Java application
The console result is output in the window that appears at the bottom left!
** Try this from the command line ** If you run it on Eclipse, it will compile and run automatically, but for study purposes, I'd like to do it manually as well.
Launch the following with
Windows button + R
cmd to display the command prompt.
And run to find out the current java version. This will not be displayed unless the java path is set in the environment variable. If you have installed Eclipse with Full Edition, it should probably be set arbitrarily ...
It seems that version 1.8 is the current version for me.
I wrote it in version 12 on Eclipse, so I would like to match it.
Open the environment variable screen (Put it in cortana or go to the control panel) I would like to change the java part of the contents of Path. Press the edit button. ~~ (that? JAVA_HOME is good ...) ~~
Specifies where version 12 is located. It is in the Eclipse installation folder.
After making changes, close the command prompt, launch it again, and run
It's OK if it has changed.
** Run **
The command navigates to the path of the file created in Eclipse.
And run. It was displayed.
By the way, in Eclipse, it is saved in utf-8 and the command prompt is displayed in SJIS (MS932), so if you change
Hello World to Japanese or double-byte characters, the characters will be garbled.
To work around this, use the system property
-D as a command option.
I was allowed to reference.
→ [Java] System Properties Note
file.encoding = UTF-8 after
java -Dfile.encoding=UTF-8 ProgateTest.java
The garbled characters have healed.
** Compile and run ** I'm going to compile and run a file created in Eclipse.
An error with a different character code.
Compile by specifying the character code. At the time of compilation, the method of specifying the encoding changes a little.
javac -encoding UTF8 ProgateTest.java
Class files can be in the same hierarchy.
・ I will try it. If you want to run the compiled version, specify the class name.
An error will occur.
The reason is that the ProgateTest class has the package
package jp.test.testproject; specified.
Let's fix it and run it.
You will get the same error.
From the location where it was executed, an error will occur if it does not match the configuration of the dot connection of the package. In other words,
jp.test.testproject.ProgateTest is looking for ProgateTest.class
in jp / test / testproject / from where it is running.
If there is, it means OK. I actually tried it.
I will try it. It was displayed.
Based on this, in the previous case, if you go back to the position of
src and execute
java jp.test.testproject.ProgateTest, it will work.
However, it is troublesome to move each time, so I will give it through the classpath.
By passing through this path, you will be able to find ProgateTest.class
injp / test / testproject / from that path as well.
Use the -cp option.
If it is a relative path, it is three levels higher, so ...
java -cp ../../../ jp.test.testproject.ProgateTest
If it's an absolute pass
java -cp C:/pleiades/workspace/TestProject/src/ jp.test.testproject.ProgateTest
It's been a long time, but I'll return to the lesson.
Generally similar to or closer to other languages
-Enclose the character string in
・ The end of the instruction is a semicolon
・ Comments are double slashes
・ ｀ ＋ － ＊ ／% ｀
-For Java and C #,
+ is sufficient when adding a character string and a numerical value.
→ Become a character string
Example: 3 + "2" = "32"
・ Similar to other languages box. Can be taken out. Can be calculated.
・ On the left side, type inference of
var is the mainstream now.
・ Similar to other languages
Everything around here is the same as in other languages ...
·cast Type conversion.
・ Let's challenge the problem
It was inconvenient that the installation of Full Edition (Pleiades) took too long. It's Eclipse ...
It was only the foundation. Experienced people felt that free lessons were unnecessary.
Next time, I will do Java II. → Next time