Java basic grammar

An article released exclusively on October 09, 2017. I referred to "** Introduction to Java that can be understood clearly **".

Construction of development environment

Java SE from Oracle, IntelliJ from JET BRAINS DL and install IDEA. The Atom editor is also useful.

Basic matters

Variable declaration

Main.java


public class Main{
    public static void main(String args[]){
int variable name=value;
final int constant name=value; //Constant name is uppercase
    }
}
Classification Model name Stored data
integer long Big
int usually
byte -128 ~ 127
Decimal double usually
float ambiguous
Boolean value boolean true / false
letter String String
char One character

operator

Main.java


int age = 15;
operator function Evaluation direction
++ Left side=Left side+ 1 ->
-- Left side=Left side- 1 ->
* Multiply ->
/ division ->
% Surplus division ->
+ Addition ->
String concatenation ->
- Subtraction ->
= Substitution <-
+= Left side=Left side+right side <-
"Left side" = "Left side" + "right side" <-
-= Left side=Left side-right side <-
*= Left side=Left side*right side <-
/= Left side=Left side/right side <-
%= Left side=Left side%right side <-

Basic instruction execution

Main.java


//Screen output(With line breaks)
System.out.println("String");
//Screen output(No line breaks)
System.out.print("String");
//Convert strings to numbers
int n = Integer.parseInt(String);
//Random number generation
int r = new java.util.Random().nextInt(upper limit);
//Input reception from keyboard
String m = new java.util.Scanner(System.in).nextLine();
int n = new java.util.scanner(System.in).nextInt(); 

Conditional branch

operator

operator meaning
== Left side=right side
!= Left side ≠ right side
> Left side>right side
< Left side>right side
>= Left side ≧ right side
<= Left side ≤ right side
&& Conditional expression 1 ∨ Conditional expression 2
|| Conditional expression 1 ∧ Conditional expression 2

If-ElseIf-Else Statement --Branch Branch

Main.java


if (Conditional expression 1) {
Block 1
} else if(Conditional expression 2) {
Block 2
} else {
Block 3
}

Switch statement

When evaluating ** a match between the left and right sides of ** integers, strings, and characters **, the If-ElseIf-Else statement can be rewritten as a Switch statement.

Main.java


switch(Condition value) {
case value 1:
Process 1
case value 2:
Process 2
        break; //Suspend the process itself
    default:
Default processing
}

Do-While Statement-Repeat

Main.java


do{
block
}while (Conditional expression) {
block
}

For statement

You should use a For statement when you know the number of iterations.

Main.java


for (int i = 0; i < 10; i++) {
block
    if (i == 7) {
        continue; //Cancel the current lap
    }
}

while (true) {
block//infinite loop
    for (;;) {
block//infinite loop
    }
}

Array

Main.java


int[]Array name= {Value 0,Value 1...Value n}
Array name= null; //Cut the array
Number of elements in int array=Array name.length;

//Extended For statement
for(int arbitrary variable name:Array name) {
block
}

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 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 learning content 5 (modifier)
[Java] Thymeleaf Basic (Spring Boot)
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 types and instruction notes
Java basic learning content 3 (operator / ternary operator)
Basic data types and reference types (Java)
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 protected
[Java] Annotation
[Java] Module
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)