Java basic grammar

What I learned today

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.

Variable definition

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

Java basic grammar
Java basic grammar
Java basic grammar
Java basic grammar
Java basic knowledge 1
[Java] Basic structure
[Java] [Basic] Glossary
Java exercises [Basic]
[Java] I personally summarized the basic grammar.
Basic Java grammar you should know first
About Android basic grammar
java basic knowledge memo
[Java] Data type ①-Basic type
Java basic date manipulation
Java basic naming conventions
Java learning memo (basic)
[Java] Basic method notes
Java basic data types
Basic Java OOps concepts
Java basic learning content 7 (exception)
Basic Authentication with Java 11 HttpClient
Java basic syntax + α trap
[Java] Basic statement for beginners
Java basic learning content 5 (modifier)
[Java] Thymeleaf Basic (Spring Boot)
Implement Basic authentication in Java
Java review ① (development steps, basic grammar, variables, data types)
Java
Java
JavaScript overview and basic grammar
Java Basic Learning Content 8 (Java API)
[Beginner] Java basic "array" description
Java basic learning content 4 (repetition)
Review of Ruby basic grammar
[Java] Basic terms in programming
New grammar for Java 12 Switch statements
Java basic learning content 3 (operator / ternary operator)
Basic data types and reference types (Java)
Java basic learning content 9 (lambda expression)
Basic usage of java Optional Part 1
Java basic learning content 2 (array / ArrayList)
Reading and writing Java basic files
Memorandum (Ruby: Basic grammar: Iterative processing)
Basic processing flow of java Stream
Java basic data types and reference types
[Basic knowledge of Java] Scope of variables
[Java] Exception types and basic processing
Basic structure of Java source code
Java learning (0)
Studying Java ―― 3
[Java] array
Profiling with Java Visual VM ~ Basic usage ~
[Java] Annotation
[Java] Module
Java array
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque