Program execution flow ⑴ Write the source code. (2) Compile the source code into bytecode (a list of numbers) with software called a compiler. (3) Bytecode is converted into machine language by software called interpreter (JVM) and sent to the CPU of the computer.
--Java files have a .java extension.
name of the class.java
public class class name{
public static void method name(String[] args) {
#Write the process;
}
}
I memorize this grammar as it is lol The inside of a class is called a class block, and the inside of a method is called a method block.
Output the value taken as an argument.
The definition of the variable is
java
Data type variable name;
#For example
int price; #Declare the variable first.
price = 100; #Next, assign the data to the variable.
You can also declare and assign variables at the same time. (This method seems to call variables initialization)
java
Data type variable name=value;
#For example
int price = 100;
Variables can be overwritten. However, since the pi and tax rates do not change, it will be troublesome if overwritten. Therefore, add final to make it a constant and substitute it. In principle, constants are declared in single-byte capital letters.
java
final int PRICE = 100; #If you declare it with final, you cannot rewrite the value.
Data type type
Classification | Model name | Data to store |
---|---|---|
integer | long | 大きなinteger(8 bytes of memory consumed) |
int | Ordinary integer(Memory consumption 4 bytes) | |
short | Small integer(2 bytes of memory consumed) | |
byte | Smaller integer(Memory consumption 1 byte) | |
a few | double | 普通のa few |
float | A few that can be a little vague | |
Boolean value | boolean | true or false |
letter | char | 1つのletter('でletterを囲む) |
String | String | Character sequence("Enclose the characters with) |
--Operand operator
java
age = 20 + 5; #Operator=Or+以外のageOr20、5(変数Or値のこと)Is called the operand.
#All formulas consist only of these two elements.
Among the operands, the values assigned to variables and the values of numbers, characters, and character strings described in the source code are called literals. Each literal has a data type.
--Assignment operator
java
a = 10; # =>10,Substitute the right side for the left side
a += 10; # =>a = a + 10,Add the left side and the right side and substitute for the left side,When characters are added, the left and right sides are connected
a -= 10; # =>a = a - 10,Subtract the left and right sides and substitute for the left side
a *= 10; # =>a = a * 10,Multiply the left and right sides and substitute for the left side
a /= 10; # =>a = a / 10,Divide the left and right sides and substitute for the left side
a %= 10; # =>a = a % 10,Divide the left and right sides and substitute the remainder for the left side
--Increment decrement operator
java
a++(Or++a); # =>a + 1,Only 1 is added to a.
a--(Or--a); # =>a - 1,Only 1 is subtracted for a.
However, if you use the increment / decrement operator together with other operators, there will be subtle differences, so use it alone as much as possible.
--Type conversion
(1) Automatic type conversion at the time of substitution byte < short < int < long < float < double Small ← → Large When assigning a value of a small type to a large type, the assigned value is automatically converted to the type of the variable to be assigned, and then the assignment is performed.
Recommended Posts