[Java] Muscle Java Basics Day 1

1 minute read

Program diary of fledgling brain muscle
Summarize what you have learned

Java features

–Grammar type that follows C / C ++
–Object-oriented language
–Static type language
–Variables, arguments and return values must be typed! !!

Java Virtual Machine(JVM/JavaVM)
–A virtual machine that can interpret and execute Java binary format as it is
–Get common execution results by using a dedicated Java VM for each OS

What is a class? !!

–Defining a program that can collectively define states / situations and behaviors / behaviors

Car class condition Behavior / behavior
car_character3_wagon.png Vehicle type
color
Number of doors
Run
Bend
Go down

__ How to define a class __

class class name(){
Define state / situation
Define behavior / behavior
}

What is a method? !!

–Definition of __ “behavior” and “behavior” __ in the class

__ How to define a method __

class class name(){
Define state / behavior

Return type method name(argument){
Behavior / behavior processing
 }
}

–Use (call) a method
–When the caller calls the method, the processing in the method is executed and the processing result is returned to the caller.
–Arguments
–When calling the method, pass the information required for processing as __ “argument” __

  • Return value
    –When the method is finished, the value returned to the caller is returned as __ “return value” __

image.png

definition of main method

–What is the main method?
–Method executed when the program is started
――The way of definition is decided

public static void main(String[] args){

}

Data type

Data type Model name Contents Range of values
Integer type int
long
byte
32-bit integer
64-bit integer
8-bit integer
abridgement
abridgement
abridgement
Real type float
double
32-bit single precision real number
64-bit single precision real number
abridgement
abridgement
Character type char 1 character abridgement
Logical type boolean Two-valued logical value true or false
  • In Java, integers are defined as int type and real numbers are defined as double type.

How to define variables

–Java variables
–Java variables always require “type definition”
-Unable to assign a value other than the defined type to a variable
――This is called “static typing”

Type name Variable name = Initial value;
int a = 10;

Fields and local variables

–Field
–Variables declared inside the class definition
–Local variables
–Variables declared inside the method definition

public class sample{
  //field
  String name = "Taro";

  //Method
 public void walk(){
  //Local variables
  int age = 20;  
 }
}