[Java] [Java] Appropriate introduction Java version by Tenpa people Part 0 (Code rules)

2 minute read

Code rules

The 0 is an extra edition, or something that you will understand, but it is very important. The main part is from 1. I also write a description of the series. https://qiita.com/Shodai-Kurasaki/items/99cf6b0ec1a8e80640b1

{ } about

Sample1.java


class Sample1
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

As you can see, {} exists in the code. As you move through a lot of code, you’ll find out where it is, but remember, Ensure that the number of {and} is the same (Exception: {as a character does not count). I think I’ll soon be writing a program that uses a lot of this set, but if I don’t have at least one then it won’t work. **In order to prevent it, each set of {} is stepped. It is normal to press the tab key once. **

; about

System.out.println(“Hello World!”); ← this **Basically always put at the end of a sentence. **Exceptions are followed by {}.

class Sample1
{← Except for the ones that {} follow behind like this;

It won’t work without it. By the way, if you do not insert a line break after this, it will not work,

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

There is no problem. However, it is basically difficult to read, so please break the line.

File name and class name

Sample1.java


class Sample1  This is the class name
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

The class name must be the same as the file name. It can be different, but don’t think about it first and make it the same. By the way, the file extension should be saved as .java.

Comment text

In the program, you will gradually come to the place where you want to make a note. “This sentence is for displaying “Hello World!”, etc. In that case, write // and write a memo after that. After //, it is completely ignored when the program is executed, so you can write it as you like. However, // only notes the content after // on that line. If you want to make a memo over multiple lines, insert the memo with /* */.

Sample1.java


class Sample1
{
public static void main(String[] args)
{
System.out.println("Hello World!"); // note here

            /* Also here ~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Memo */
}
}

end

If there are any points that need to be corrected, please let us know.