Java basic grammar

Learning log

Program flow

  1. Write the source code.
  2. Compile the source code with a compiler and convert it to bytecode.
  3. The interpreter translates bytecode into machine language to run the CPU

--The extension of the java file will be .java.

name of the class.java


public class class name{
public static void method name(String[] args) {
    //processing
  }
}

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

Variable declaration statement

python


Data type variable name;

//For example
int age;  //Declare the variable first.
age = 30; //Next, assign the data to the variable.

You can also declare and assign variables at the same time. (Called variable initialization)

python


Data type variable name=value;

//For example
int age = 30;
Data type type
Classification Model name Data to store Example
integer long 大きなinteger long worldPeople; //World population
int Ordinary integer int salary; //Salary amount
short Small integer short age; //age
byte Smaller integer byte glasses; //Number of glasses you have
a few double Ordinary decimal double pi; //Pi
float Decimal numbers that can be a little vague float weight//body weight
Boolean value boolean true or false boolean isMarried;//Whether you are married or not
letter char 1つのletter char initial; //イニシャル1letter
String String Character sequence String name; //My name
Operand operator

python


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

python


a = 10;  // =>10,Substitute the right side for the left side
a += 10; // =>a = a +10. When the left side and the right side are added and assigned to the left side, and the characters are added, the left side and the right side 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 side and the right side 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

python


a++(Or++a); // =>a +1, only 1 is added to a.
a--(Or--a); // =>a -1, only 1 is subtracted for a.

Initialization of constants

Variables can be overwritten. However, since the tax rate and the circumference rate are basically the same, it would be troublesome if they could be overwritten. Therefore, such variables are assigned as constants.

python


Data type constant name=value;

final int PRICE = 100;
//Constant names are generally capitalized

Recommended Posts

Java basic grammar
Java basic grammar
Java basic grammar
Java basic grammar
Java basic knowledge 1
[Java] Basic structure
Java exercises [Basic]
[Java] I personally summarized the basic grammar.
Basic Java grammar you should know first
[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
[Java] Basic types and instruction notes
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
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
Studying Java ―― 3
[Java] array
Profiling with Java Visual VM ~ Basic usage ~
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)