Try the free version of Progate [Java I]

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

Environment

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 ...

image.png

It was June 2019 w

-Create a test project. image.png I set the JRE to 12. What can 12 do ...

image.png 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 image.png The package name is appropriate. Check the item that automatically generates public static void main. image.png It's done.

Oh, I made the appearance (theme) of Eclipse look like C #, so I will change it to a dark theme. image.png

Like this image.png

I will return to the lesson from here.

Let's touch Java

-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

The public static void main of the class specified in the class name of is called.

-Display processing on the command line

System.out.println("Hello World");

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 ** image.png We will do this.

When executing from Eclipse, right-click the class with public static void main → execute or debug → Java application image.png

The console result is output in the window that appears at the bottom left! image.png

** 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 image.png

Type cmd to display the command prompt. image.png

java -version

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. image.png

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) image.png I would like to change the java part of the contents of Path. Press the edit button. ~~ (that? JAVA_HOME is good ...) ~~ image.png

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 java -version. image.png It's OK if it has changed.

** Run ** The command navigates to the path of the file created in Eclipse. cd ~ image.png image.png

java ProgateTest.java

And run. image.png 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. image.png image.png To work around this, use the system property -D as a command option. I was allowed to reference. → [Java] System Properties Note

Write file.encoding = UTF-8 after -D.

java -Dfile.encoding=UTF-8 ProgateTest.java

image.png The garbled characters have healed.

** Compile and run ** I'm going to compile and run a file created in Eclipse.

-Compile with javac

javac ProgateTest.java

image.png 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

image.png

Class files can be in the same hierarchy. image.png

・ I will try it. If you want to run the compiled version, specify the class name.

java ProgateTest

image.png 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.

java jp.test.testproject.ProgateTest

image.png 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.

/src/jp/test/testproject/jp/test/testproject/ProgateTest.class

If there is, it means OK. I actually tried it. image.png

I will try it. image.png 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.classinjp / 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

result image.png

It's been a long time, but I'll return to the lesson.

Java basics / strings

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 //

Numerical value, numerical calculation

・ ` + - * /% `

String concatenation

-For Java and C #, + is sufficient when adding a character string and a numerical value. → Become a character string Example: 3 + "2" = "32"

Define variables, try using variables, update variables

・ Similar to other languages box. Can be taken out. Can be calculated.

・ On the left side, type inference of var is the mainstream now.

Self-substitution, omission of self-substitution

・ Similar to other languages

Roles of variables and precautions

Everything around here is the same as in other languages ...

Automatic type conversion to handle decimal numbers

·In particular···

Forced conversion

·cast Type conversion.

・ Let's challenge the problem image.png image.png

Cleared. image.png

Impressions

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

Recommended Posts

Try the free version of Progate [Java I]
Try the free version of Progate [Java II]
[Java version] The story of serialization
[day: 5] I summarized the basics of Java
[Java] Access the signed URL of s3 (signed version 2)
I compared the characteristics of Java and .NET
I touched on the new features of Java 15
I couldn't run it after upgrading the Java version
I summarized the types and basics of Java exceptions
[Java] I implemented the combination.
I studied the constructor (java)
Switch the version of bundler
The handling of Java Future is too dull, so I will try various ideas.
I didn't understand the behavior of Java Scanner and .nextLine ().
I tried to summarize the basics of kotlin and java
[Java] Try editing the elements of the Json string using the library
[Java] I thought about the merits and uses of "interface"
I want to find out which version of java the jar file I have is available
[Java] Delete the elements of List
Check the version of Cent OS
I read the source of ArrayList I read
I read the source of Integer
I read the source of Long
I tried the Java framework "Quarkus"
I read the source of Byte
I read the source of String
The origin of Java lambda expressions
I tried using GoogleHttpClient of Java
I checked the automatic unit test creation tool (end of 2019 version)
Switch the version of java installed by SDKMAN when moving directories
I tried the input / output type of Java Lambda ~ Map edition ~
I tried to summarize the methods of Java String and StringBuilder
I passed the Oracle Java Bronze, so I summarized the outline of the exam.
I was addicted to the API version min23 setting of registerTorchCallback
Try using || instead of the ternary operator
About the version of Docker's Node.js image
Check the contents of the Java certificate store
Examine the memory usage of Java elements
[Java] Get the day of the specific day of the week
Try using the Stream API in Java
Memo: [Java] Check the contents of the directory
I tried the new era in Java
Installation of OMC APM Agent --Java version-
Compare the elements of an array (Java)
I investigated the internal processing of Retrofit
Try calling the CORBA service in Java 11+
What are the updated features of java 13
Easily measure the size of Java Objects
How to find out the Java version of a compiled class file
[Java] I personally summarized the basic grammar.
Looking back on the basics of Java
How to install the legacy version [Java]
Output of the book "Introduction to Java"
I went to the Java Women's Club # 1
I want to get the field name of the [Java] field. (Old tale tone)
The story of writing Java in Emacs
I translated the grammar of R and Java [Updated from time to time]
Check the version of the standard Web software.
[Java] Check the number of occurrences of characters
[Java] [Spring] Test the behavior of the logger
Try using the Wii remote with Java