This article is a memorandum. Although it is a reference book level content, the code posted in this article is about ** Wrong ** are the main things. This is for the purpose of posting the part that was actually mistaken during coding and posting it for self-reflection. In addition, I will not touch on the deep part here because I will review it later while also studying the Java Silver exam questions.
Language: Java11, JDK13.0.2 Operating environment: Windows 10
If you've ever touched programming, you've probably written it. In my vague memory, I think I wrote it in Basic
or C
in a computer class in junior high school (I didn't think I would jump into the world of programming at this time). By the way, I was studying to take the ** "Python3 Engineer Certification Basic Exam" ** at Python
, so I wrote this from the command prompt.
Hello,world!.py
>>> python
(abridgement,python3.7.Message when starting 2)
>>>print("Hello,world!")
>>>Hello,world! #result
I asked print
and it came out immediately.
After that, when I read Java, it was like this.
Hello,world!.java
//Let's make a class first
class helloWorld
{
public static void main(String[] args)
{
System.out.println("Hello,world!");
}
}
helloWorld.java
//Next, let's compile. Open the command prompt.
>>>cd C:\JavaSample
//Move directory.
//In other words, please specify where it is in the file.
>>>javac -encoding UTF-8 helloWorld.java
//Now it's compilation.
//The encoding setting doesn't work, so please specify that as well.
//Make sure that the compiled data is in the specified folder.
>>>java helloWorld
Hello,world!
//It's finally completed!
...... What is this effort? !! I can't say good or bad because there are differences between Python and Java depending on the type of language (I was confused at the time, but I'm used to it).
For the time being, I wrote a few in the method and remembered it, but the problem remained. What do these in Java mean? ?? ?? I don't understand at all.
There is almost no explanation for these strangely long descriptions in the introductory book (I regretted it after a little research based on interest). It's a little too long to say, "Let's remember this as a makurakotoba," so I wanted him to talk a little. Qiita has already dealt with this story, so I would like to introduce one (I will mention that it was an article three years ago and the latest Java is SE11).
@tomz65k9nfy Challenge to explain Java's Hello World while referring to the language specifications
Also, here is a reference issued by ʻOracle`, a company that handles Java. If you say **, I can explain if you understand this page **.
Java® Platform, Standard Edition & Java Development Kit Version 11 API Specification
I've given you two reliance, but to be honest ** I haven't swallowed enough to explain it **. However, as a beginner, I want to write what to connect next, so I want to break down that long makurakotoba. Items to be divided by disassembly
The target of disassembly is
A sentence of public static void main (String [] args)
.
public static void
/ main(String[] args)
The former has three ** modifiers **, the latter has ** methods ** and their arguments You can see that.
First of all, about the method
The main ()
method is the java.lang.Object class
, which is a ** process ** contained in the ** standard class ** prepared by Java even if nothing is declared. .. The part containing this main ()
becomes the ** entry point ** and the actual processing starts, and when the main () method is exited, the processing ends.
(String [] args)
is an argument required by the main ()
method. It is divided into ** String type array ** and ʻargs argument name. It doesn't have to be named ** ʻargs
** (it doesn't matter if it's a different name, but it seems to be customary to name it).
The String type is also a member of the java.lang.Object class
(it has a bad word, but it is omitted here), and it can handle character strings (the char type can handle some integers and simple substances. Only one letter).
In other words, it is an array of type String, and it seems that it is prepared to receive processing by giving args or another name.
Next is the modifier.
After processing the
void
</ li> method, the value evaluated by each expression can be assigned to the variable declared inside the class. We call it ** return value **, but in the case of the method declared with this void
, it is possible to have no return value.
For a method with no return value, the processing of the block ends or the processing is returned to the original class that was called at the return statement.
...... Is it? I'm thinking now, just as the mystery has deepened.
This time I limited it to two, but what is "public static void main (String [] args)
"? I saw many articles on the internet. After all it seems that there are many voices with doubts. It seems that we need to know more in order to be able to explain the question clearly.
The road to the program is deep and steep.
I write variables and expressions as much as possible and compile them, so if I want to quote them completely, I will describe that.
Easy Java 7th Edition Java SE11 Silver Problem Collection (commonly known as Kuromoto) Python Tutorial 3rd Edition (Note that this is the O'Reilly Japan store page)
Recommended Posts