Java from entry - proficiency


foreword

Java entry and basic knowledge


1. JDK and JRE

What is JDK?

JDK is the Java Development Kit,
mainly composed of the following three parts

  • JVM virtual machine: where Java programs run
  • Core class library: things that have been written in Java and can be used directly
  • Development tools: javac, java, jdb, jhat...

What is JRE?

JRE is the running environment of Java,
mainly composed of JVM, core class library, and running tools

The relationship between JDK, JRE, and JVM

  • JDK contains JRE
  • JRE contains JVM

2. Keywords

1. What is a keyword

English words given specific meaning by Java

2. Keyword Features

  • Keywords are all lowercase
  • In commonly used compilers, keywords are marked with a special color

3. Literal volume

Classification of literals

insert image description here'abc' is a wrong spelling, in the character type, there can only be one content enclosed in single quotes

Special characters

  • \t Tab character: When printing, fill the length of the previous string to 8, or an integer multiple of 8. Fill in at least one and up to 8 spaces.
    When printing table-like data, you can aligninsert image description here

4. Variables

Basic usage of variables

data type variable name = data value;
insert image description here

How to use variables

  1. output print
  2. Participate in computing
  3. Modify the value of a record

code:

public class test1{
    
    
    public static void main(String[] args) {
    
    
//        1.变量赋值
        int a = 10;
        System.out.println(a);
        System.out.println(a);
        System.out.println(a);

        //2.参与计算  (变量不能重复定义)
        int b = 20;
        int c = 30;
        System.out.println(b + c);

        //3.修改值
        a = 50;
        System.out.println(a);
    }
}

insert image description here

Notice

  • A variable can only hold one value
  • Variable names are not allowed to be defined repeatedly
  • One statement can define multiple variables
  • Variables must be assigned a value before use
  • Pay attention to the scope of variables.
    One statement can define multiple variables.
    insert image description here

practise

Count the number of people on the bus: there are no passengers at the beginning. First stop: one passenger up, second stop: two passengers up, one passenger down, third stop: two passengers up, one passenger down, fourth stop: one passenger down fifth stop: up A passenger, may I ask: How many passengers are there in the car at the terminal.

public class test1 {
    
    
    public static void main(String[] args) {
    
    
     int count = 0;
     count += 1;
     count = count + 2 - 1;
     count = count + 2 - 1;
     count = count - 1;
     count = count +1;
     System.out.println(count);
    }
}
//输出结果:3

type of data

Classification of data types: divided into basic data types and reference data types (will be described in detail when learning object-oriented later).
Basic data types are divided into four categories and eight types:
insert image description herethe size relationship between integer and decimal value ranges:

  • double>float>long>int>shory>byte

Long type variables : need to add L logo (both uppercase and lowercase)
float type variables : need to add F logo (both uppercase and lowercase)

5. Identifier

Identifier: the name given to the class, method, variable, etc.

mandatory requirement

  • Consists of numbers, letters, underscores (_), and dollars ($)
  • cannot start with a number
  • cannot be a keyword
  • case sensitive

Soft Suggested
CamelCase: Methods, Variables

  1. When the identifier is a word, all lowercase
  2. When the identifier consists of multiple words, the first letter of the first word is lowercase, and the first letter of other words is capitalized

Big CamelCase: Class Names

  1. When the identifier is a word, the first letter is capitalized
  2. When the identifier is multiple words, the first letter of each word is capitalized

6. Keyboard entry

A class that Java has written for us is called Scanner. This class can receive the numbers entered by the keyboard.
There are the following steps:

  1. Import package - find Scanner (written above the class definition)
  2. Creating Objects - Getting Started with Scanner
  3. Receive data - get to work

insert image description here

Guess you like

Origin blog.csdn.net/qq_64451048/article/details/127555904
Recommended