Introduction to Java for beginners Basic knowledge of Java language ①

Introduction

Starting today, I'll break it down into several parts to explain the basics of Java for those who want to learn Java and are currently learning Java. I chose Java among many programming languages because I decided to explain Java because it is a language that can learn the basics of object-oriented programming, a language that is reasonably popular, and a language that I am most confident in explaining .. Since this is the first time, I will explain what programs and programming languages are in the first place, and then I will explain the outline of Java and the standard output.

What is a program?

In Kotobank, it is described as follows.

Data that can be interpreted and operated by a computer. When an instruction to a computer is described as a program, the computer executes processing such as calculation and input / output according to the procedure instructed by the program. Source: Kotobank-Program

In other words, it shows the processing procedure executed by the program = computer. Windows, Linux basic software such as Windows, iOS, Mac OS and application software spreadsheet software, word processing software, e-mail software (mailer) are also one of the programs. Therefore, the computer will not work unless any programs are installed. In addition, by using many programs on a computer, you can improve the efficiency of your work.

Let's take LINE as an example. In the days when there was no LINE and only exchanges were made by email, it took time to enter the address each time, and it was not possible to check the exchanges before and after at a glance. With the advent of LINE, you can send a message just by selecting the other party, and since it is a chat format, you can check the contents before and after at a glance, and you can exchange messages with high real-time performance. You can see that the time to send a message, the time to reply to a message, and the time to check a message have been reduced and efficiency has been improved.

What is a programming language?

Simply put, a programming language is a language that writes source code for creating programs. The computer can only interpret the machine language represented by the enumeration of the numbers "0" and "1".

It's difficult for humans to understand, and if the program is machine language, many will be frustrated. Therefore, a programming language has been developed that allows the source code to be written in words that are easier for humans to understand than machine language. The computer translates the source code into machine language and executes the program. There are two methods for converting and executing machine language: compiler type and interpreter type. Compiler type </ b> </ span>: Convert to machine language and execute all at once before executing the source code. Interpreter type </ b> </ span>: Execute while interpreting the run-time source code line by line and converting it into machine language.

What is Java

In Wikipedia, it is described as follows.

Java (Java) refers to the programming language Java in a narrow sense. In a broad sense, in addition to language specifications, Java class libraries and Java virtual machines to which specifications are given, as well as official ones such as JDK and JRE, and in some cases third-party ones, etc. are vaguely Java. It may also refer to an ecosystem such as something that is collectively called a platform. Source: Wikipedia-Java

I don't think this is enough, so I will explain in detail.

First, Java is a technology with the following three aspects, which was developed by a company called Sun Microsystems and acquired by Oracle in 2010.

1. Programming language

Java is called Java language as a language, and it is a language that is object-oriented and has abundant class libraries without depending on the platform (the platform here is a specific OS or hardware).

2. Execution environment </ b> </ span>

The Java execution environment is JRE (Java Runtime Environment), which is provided for various platforms. Therefore, even if the OS type such as Windows, Mac, Linux is different, the same program can be operated by installing JRE.

3. Development environment </ span> </ b>

The JDK (Java SE Development Kit) provides the tools you need for Java development work.

The following three tools are mainly provided.

-Compiler: Converts source code to a class file (a compiled file of the source)

・ Interpreter: Execute while interpreting the class file line by line

-Class library: A collection of classes (program parts) provided by Java

Java type

When developing an application using Java, there are three things available. 1.Java SE(Java Platform Standard Edition)

It provides the basic functions that are the basis of Java application development, regardless of whether it is a server or client. In order to use the Java language, Java SE must be installed.

2.Java EE(Java Platform Enterprise Edition)

Provides the ability to develop server-side web apps, such as online shopping systems, and is used in combination with Java SE

3.Java ME(Java Platform Micro Edition)

You can develop applications that run on small devices with limited memory and CPU, such as Galapagos mobile phones and personal digital assistants, and use them in combination with Java SE.

Flow from Java application creation to execution

1. Source code creation </ span> </ b>

Write the source code and save it with the extension ".Java".

2. Compiler </ b> </ span>

The compiler is used to check and convert the source code and automatically generate a class file with the extension ".class".

3. Run </ b> </ span>

It uses the Java interpreter to interpret and execute the bytecode.

Create the source code with a text editor, open a command prompt, use the "cd" command to move to the location of the text editor folder, compile the text editor file with the "Javac" command, and then use the "Java" command. There is a method of executing a class file.

However, this method is so inefficient that most Java applications are created and executed in an integrated development environment such as Eclipse or IntelliJ IDEA. The integrated development environment can not only create, edit, and execute source code, but also perform automatic error checking, code input correction, and function expansion with plug-ins.

Source code creation

A Java application consists of one or more classes and starts with the main method. Classes and methods will be explained later, so please think about it.

The format is as follows.

class ClassName{
        public static void main(String[] args){
                /*
main method
                */
        }
}

Standard output

The output on the result screen such as the command prompt or console view is called standard output.

To output the value as standard output from Java application, use System.out.print () method or System.out.println method. In both cases, specify the value you want to print in (), but the System.out.println () method will start a new line after printing. Basically, Java puts a; (semicolon) at the end of a sentence. Enclose it in "" (double quotation marks) when handling a character string, and use + to concatenate a character string and a numerical value. The following is an example.

 System.out.print(12333);  //12333
 System.out.println("Hello.");  //New line and outputs the Hello
 System.out.println(3+"Chome"); //3とChomeを連結した3Chomeを出力して改行

Precautions when entering source code There are a few things to keep in mind when entering the source code.

・ (), {}, [], Space is half-width

・ Alphabet is case sensitive

・ Alphabets, symbols and numbers are half-width

-Indicate appropriate indentation and comments in an easy-to-understand manner to improve readability.


class ClassName{
        public static void main(String[] args){
               System.out.print(333);
        }
}

//Single line comment

/*Multi-line comment*/

Comment usage example

//I want to eat ramen
/*sleepy

hot

Cold*/

Summary

A programming language is a language for writing source code for creating programs.

Java is a technology that has three aspects: programming language, execution environment, and development environment.

There are three types of Java, Java SE JavaEE Java ME, and Java SE must be introduced.

When developing in Java, it is recommended to develop in an integrated development environment

Java application consists of one or more classes and starts from main method

Source code arranges comments and indents to improve readability

Since this is the first time, I've only explained the terms, but it's okay if you can get a rough idea of the program and Java.

Next time, I will mainly explain identifiers, variables, data types, and operators.

Recommended Posts