Java review ① (development steps, basic grammar, variables, data types)
Part 1 "Steps of java program development"
- Creating source code
- Compile
- Run
The above 3 steps
Part 2 "Let's take a closer look"
- What is source code creation?
A statement to a computer that can be read by humans. It's just called sauce.
A source file is a description of the source file.
Therefore, the java file written as 〇〇.java is applicable.
- Compile
It is done by software called a compiler.
Convert the source file to a class file (〇〇.class).
The contents of the class file are bytecodes
Bytecode is computer readable (binary).
- Run
Use an interpreter to convert bytecode to machine code and execute it.
The JVM is included in the interpreter, and it is the JVM that actually reads and converts the bytecode.
The converted machine code is sent to the CPU.
[Summary of Part 2]
・ Human readable = source code
-File containing source code = source file
-Computer (with JVM) can read = bytecode
-File containing bytecode = class file
-What is required to convert the source code to bytecode = compiler
-Compile the above work
-It is the interpreter that executes bytecode as machine code.
-To use Java, you need to install an interpreter and compiler on the net.
Part 3 "Basics of Java"
- Block
{} Blocks are surrounded by curly braces.
If public class Main {}, class block
public static void main (String [] args) If {} is a method block
Write the instruction in the method block.
- Class name rules
Class names start with an uppercase alphabet.
- java file rules
クラス名.java
- How to write the source
(1) Be sure to close the block and write.
The following description is ✖️
—————————————————
public static void Hello(){
System.out.println(“hello”);
—————————————————
② Incident
Utilize tabs and spaces. Readable code.
③ Comment
/ * * / Or //
- Code execution order
It is executed in order from the top.
- Add a semicolon.
";" ← Source of error
Part 4 "Variables"
- What are variables?
A box that holds various values that are not constant.
If it is a number, it can be from minus to 0, tens of thousands or more values can be entered, and it can be called a character string or a boolean value.
Various values are entered.
- Declaration of variables
int number;
Type + variable name + semicolon
- Variable name rules
① You cannot use what is called a reserved word. For example, since int is used as a type, int cannot be used as a variable name.
② If you have already used it, you cannot use it. It cannot be used exactly within the same scope.
However, it is better to make it so that it will not be covered.
③ Characters are case sensitive.
④ Basically lowercase. When two words are connected like myName
Capitalize only the first letter of Name.
- Variable declaration and assignment
int number = 30;
Type + variable name + equal + value to be assigned + semicolon
- Overwrite variables
Please note that it is executed in order from the top.
The values below are displayed on the screen.
- Constant
Variables that you do not want to be rewritten are made constants and set to constant values.
final double number = 3.14;
Part 5 "Data type"
int integer
long big integer
double Ordinary decimal (L is added at the end like 10000000000L)
float Ambiguous decimal (F at the end like 30.2F)
boolean Boolean (only true or false can be entered)
char single character (use single quotes like'turtle')
String String (uppercase)
Tips "Purpose of java"
Java is built on the idea that it works everywhere.
To work anywhere means to create bytecode that can be understood by any CPU.
The JVM in the computer reads the bytecode
The JVM inside the computer is executing the bytecode, not just the computer
It is called a JVM (java virtual machine) because it looks like this.
(JVM passes the machine code that converted the bytecode to the CPU, so it is actually just converting) "