day1-Java learning-getting started (Java introduction, jdk download and installation and environment variable configuration, IDEA download and installation)

Title# Introduction to Java Basics

Hello, friends, welcome to the world of Java, we are officially here! ! !

1. Java background knowledge

Before we officially start working, let’s first understand the background knowledge of Java so that you can talk about Java with everyone in the future.

1.1 History of Java language

  • Which company's product is Java?

    Java is a computer launched by Sun (Stanford University Network, Stanford University Network) in the United States in 1995.High-level programming language. But in 2009, Sun was acquired by Oracle (Oracle), so the Java language is currently a product of Oracle.

  • Where does the name Java come from?

    In the early days, the name of this language was not actually Java. It was called Oak (meaning oak tree) at that time. Why was it called Oak? The reason is that there are many oak trees planted in front of Sun Company. However, when the trademark was registered, the Oak trademark was already registered by another company, so it was later renamed Java. So some people are curious why it is called Java? Java is an island in India that is rich in coffee. It may be because the programmers of their company like to drink coffee, so it was renamed Java.

  • Who is the founder of Java?

  • After talking about the origin of the name Java, let’s talk about who is the ancestor of Java? There are many co-founders of Java, but the founder of Java that is generally recognized by the industry isJames Gosling, known as the father of Java >
    Insert image description here

1.2 What Java can do

After understanding the history of the Java language, the next question that everyone is more concerned about may be what can Java do?

Insert image description here

In fact, Java can do a lot of things. It can do desktop application development, enterprise Internet application development, mobile application development, server system development, big data development, game development, etc.

1.桌面应用开发:能够在电脑桌面运行的软件
	举例:财务管理软件、编写程序用的IDEA开发工具等,可以用Java语言开发
	
2.企业级应用开发:大型的互联网应用程序
	举例:淘宝、京东、大家每天都用的tlias教学管理系统等

3.移动应用开发:运行的Android手机端的软件
	举例:QQ客户端、抖音APP等

4.服务器系统:应用程序的后台(为客户端程序提供数据)
	举例:服务器系统为用户推荐那你喜爱的视频

5.大数据开发:大数据是一个互联网开发方向
	举例:目前最火的大数据开发平台是Hadoop,就是用Java语言开发的

6.游戏开发:游戏本质上是给用户提供娱乐的软件,有良好的交互感受
	举例:我的世界MineCraft就是用Java语言开发的

Although Java can do a lot of things, not every direction is recognized by the market (for example, it is not convenient to use Java language to develop desktop applications, and using C# language is more recommended). The current mainstream development direction of Java is to use Java to develop enterprise-level Internet applications (Many companies’ OA systems, customer relationship management systems, including Chuanzhi Podcast use The teaching implementation management system is developed in Java language)

1.3 Java technical system

After talking about what the Java language can do, let's introduce the technical system of Java to the students. The so-called technical system means that Java provides different technical versions to meet different application scenarios, and there are mainly three versions.

  • Java SE (Java Standard Edition): It is called the Standard Edition. It is the basis of the next two versions. That is, to learn the latter two versions, you must first learn JavaSE. What our basic class is currently learning is the technology in this version.

  • Java EE (Java Enterprise Edition): Called Enterprise Edition, it is a set of solutions provided for enterprise-level application development. In the subsequent employment class courses, you will mainly learn the technology in this version .

  • Java ME (Java Micro Edition): called the small version, it provides a set of solutions for developing applications for mobile devices. It is currently not recognized by the market (eliminated), and has been replaced by application development based on the Android system.


The relevant background of the Java language has been introduced to you here. Friends do not need to deliberately memorize these contents, just simply understand them. Below we briefly review

1.Java是什么?
	答:Java是一门高级编程语言
	
2.Java是哪家公司的产品?
	答:Java以前是Sun公司的产品,现在Java是属于Oracle公司的产品
	
3.Java之父是谁?
	答:詹姆斯●高斯林
	
4.Java主流的开发方向是什么?
	答:企业级互联网应用开发
	
5.Java技术平台有哪些?
	答:JavaSE(标准版)、JavaEE(企业版)、JavaME(小型版)

2. Quick Start with Java

In the last chapter, we introduced the relevant background of Java to our friends. Do you want to use Java right now? Don't worry, we must first install the Java development environment before we can use the Java language to develop programs (ps: just like you need to install WeChat before you can use WeChat to chat with friends).

The Java development environment mentioned here is actually a software officially provided by Java, called JDK (full name is Java Develop Kit), which means Java Development Kit when translated. We first need to download JDK from the official website, and then install it on our own computer. Then we can use JDK to develop Java programs on our own computer

There are many versions of JDK. The following figure shows the update process of JDK versions. Those marked with LTS are long-term support versions (which means Oracle will update them from time to time). Currently, the most commonly used version in the company is the JDK8 version. In this current course, we will use the JDK17 version in order to incorporate some new features.

Insert image description here

The detailed screenshots of the JDK download and installation process have been provided below. You only need to follow the steps.

2.1 JDK download and installation

  • Download of JDK

This is the official URL for JDK download https://www.oracle.com/java/technologies/downloads/. You need to copy the URL to the address bar of the browser and hit Enter.

Insert image description here

After entering the website, select the JDK17 version, find the Windows tab, and select the x64 Installer version. As shown below

Insert image description here

After the download is completed, a JDK installation package will appear in the directory you downloaded, as shown in the figure below

Insert image description here

The JDK download is now complete. Next, you need to follow the steps below to complete the JDK installation.

  • JDK installation

Double-click the installation package, follow the instructions below, and click Next to install. It should be noted that after installing JDK, unlike when you install QQ, an icon will be displayed on the desktop. After JDK is installed, there will be no icon on the desktop! ! !

Insert image description here

How to verify that the installation is successful?

Didn’t I just ask you to remember the installation directory? Do you remember it? If you have modified the directory yourself, open the directory you modified (ah!! I forgot o(╥﹏╥)o, then I can’t help you, who told you not to listen carefully); if you have not modified the installation directory, By default, it is in the C:\Program Files\Java\jdk-17.0.3 directory.

Open the bin directory of the JDK installation directory in the file explorer, and you will find two command toolsjavac.exe java.exe, which are what the JDK provides for us to useCompilation tools and running tools, as shown in the figure below

Insert image description here

Let’s use these two tools now javac.exe java.exe to test whether the JDK is available

  1. Step one: In the JDK bin directory, enter cmd in the address bar and press Enter.

Insert image description here

After entering cmd and pressing Enter, a black window will appear, which is technically calledCommand Line Window

Insert image description here

  1. Step 2: Enter javac -versionEnter in the command line window, then enter java -versionEnter

    If the following red box prompts the correct version number, which is consistent with the JDK version number we installed, it means that the JDK installation is successful.

Insert image description here

After completing the above steps, congratulations, friends_, you will already have a Java development environment on your computer. Next, you can Developed Java program.

2.2 cmd common commands

To test whether the JDK is installed successfully, you need to enter javac -version and java -version in the black window. This is actually how the JDK checks the version numbers of the compilation tools and running tools. Order.

This way of interacting with the computer by entering commands is called command line interaction. In other words, you can use commands to direct the computer to do things. Next, we will learn about several common commands in Windows systems, which may be used later.

The following are common commands and functions in Windows systems. Friends, you can try them yourself. It should be noted that after each command is typed, pressing Enter immediately means executing this naming.

E:  //切换到E盘
cd [目录]        //进入指定的目录
cd ..         //退回到上一级目录
cd /         //退回到根目录
dir             //显示当前目录下所有的内容
cls             //清空屏幕

2.3 Java introductory program

We have installed the JDK in the previous section. Next, we will officially start developing the first entry-level Java program. According to international practice, the first case of learning any programming language is called Hello World, which means to say hello to the world and start using programs to communicate with the world. 's door.

Steps to write a Java program

Writing a Java program requires 3 steps:Write code, compile code, run code

Insert image description here

  • Write code: You can write code with any text editor, such as the Notepad that comes with Windows system
  • Compile code: Convert human-readable source code (.java files) into bytecode files (.class files) that can be executed by the Java virtual machine
  • Run the code: hand the bytecode file to the Java virtual machine for execution

Write your first Java introductory program

Follow the steps provided below to complete the writing, compilation and execution of the first Java entry program step by step.

Step 1: Create a new text file with the suffix .javaHelloWorld.java, and use Notepad to write the code as follows.

public class HelloWorld {
    
    
   public static void main(String[] args) {
    
    
     System.out.println(" HelloWorld ");
    }
}

Second step: Enter the directory where the HelloWorld.java file is located, enter cmd in the address bar and press Enter to open the command line window here.

Insert image description here

Compile: Enter the compile command in the command line windowjavac HelloWorld to complete the compilation. After compilation, a HelloWorld.class file will be generated.

Insert image description here

Step 3: Then enterjava HelloWorld to run. The results are as follows.

Insert image description here

2.4 Common problems in Java programs

When you guys were writing the first HelloWorld program just now, was it easy to get an error? I have observed that when writing code for the first time, 90% of students will have some minor problems, such as writing wrong words! Write one less bracket! etc! What I want to tell you is that it is normal to write wrong code.A programmer who has made all kinds of mistakes is a real programmer.

Below we summarize the common problems in the program. Just pay attention to these issues when writing code.

  • Windows file extension is not checked
  • I wrote the code but forgot to save it
  • The file name and class name are inconsistent.
  • English capitalization errors, word spelling errors, Chinese symbols exist, and the main method cannot be found.
  • The brackets don't match.
  • Improper use of compilation or execution tools.

  • File extension not opened

If the file extension checkbox in the picture below is not checked, the file you create will be an ordinary text file (.txt) file instead of a java file.

The correct way is to check the file extension

Insert image description here

  • File name and class name are inconsistent

Look at the picture below. The file name is HelloWorld, but the class name is Helloworld. Can you see the difference? One is a capital W, and the other is a lowercase w. You really can't tell if you don't look carefully.

**The correct way to write it is that the file name isHelloWorld, and the class name is also calledHelloWorld**

Insert image description here

  • Wrong capitalization of words Wu

In the picture below, the words string and system are not spelled incorrectly. They are strictly case-sensitive.

The correct way to write it is String and System

Insert image description here

  • The main method is written incorrectly

As shown in the figure below, the name of the main method is written asmian, which is wrong.

The correct way to write the main method: it must be public static void main(String[] args){}, not a single letter is wrong.

Insert image description here

  • Punctuation mark is wrong

In the picture below, the semicolon at the end of the print statement is written as a Chinese semicolon.

The correct way to write it is an English semicolon ; You really can’t tell the difference if you don’t look carefully, so be careful

Insert image description here

2.5 Composition of JDK

In the previous lessons, we have installed the JDK and developed a Java introductory program, compiled with the javac command and run with the Java command, but there is not much introduction to the execution principle of the Java program.

Next, we will introduce to you the composition of JDK and the cross-platform principle, which will help students understand the execution process of Java programs.

JDK consists of JVM, core class library, and development tools, as shown in the figure below

Insert image description here

Let’s introduce what each part of the JDK is used for.

- 什么是JVM?
    答:JDK最核心的组成部分是JVM(Java Virtual Machine),它是Java虚拟机,真正运行Java程序的地方。
    
- 什么是核心类库?
	答:它是Java本身写好的一些程序,给程序员调用的。 Java程序员并不是凭空开始写代码,是要基于核心类库提供的一些基础代码,进行编程。
	
- 什么是JRE?
    答:JRE(Java Runtime Enviroment),意思是Java的运行环境;它是由JVM和核心类库组成的;如果你不是开发人员,只需要在电脑上安装JRE就可以运行Java程序。
    
- 什么是开发工具呢?
	答:Java程序员写好源代码之后,需要编译成字节码,这里会提供一个编译工具叫做javac.exe,编写好源代码之后,想要把class文件加载到内存中运行,这里需要用到运行工具java.exe。 
	除了编译工具和运行工具,还有一些其他的反编译工具、文档工具等待...

The relationship between JDK and JRE can be summed up in one sentence: use JDK to develop programs and leave them to JRE to run.

2.6 Cross-platform principles of Java

After learning the composition of JDK, we know that the execution of Java programs depends on the Java virtual machine. It is because of the Java virtual machine that Java programs have an important feature called cross-platform nature.

  • What is cross-platform?

    The so-called cross-platform means that programs developed in Java language can run on multiple operating systems. Common operating systems include Windows, Linux, and MacOS systems.

    If there is no cross-platform capability, if the same application wants to run on multiple operating systems, it needs to develop separate applications for each operating system. For example, WeChat has Windows version, MacOS version, Android version, and IOS version.

  • Why can Java programs be cross-platform?

    The principle of cross-platform is that there aredifferent versions installed indifferent versions of operating systems The Java virtual machine, the running of the Java program only depends on the Java virtual machine and has no direct relationship with the operating system. So that it can be compiled in one place and run everywhere.

Insert image description here

2.7 JDK environment variable configuration

After JDK is installed, let's learn a supplementary knowledge called Path environment variable.

  • What is the Path environment variable?

    The Path environment variable is the path of the system program, making it convenient for programmers to start the program in any directory in the command line window;

  • How to configure environment variables?

    For example, by configuring the QQ startup program under the Path environment variable, you can start QQ in any directory and follow the steps below.

    **Step 1:** First find the directory where the QQ startup program is locatedC:\Program Files (x86)\Tencent\QQ\Bin, copy this path

Insert image description here

**Step 2:** Follow the steps below to find the Path environment variable.

First find this computer, right-click Properties, and follow the interface below; click [Advanced System Settings], then click [Environment Variables]

Insert image description here

Double-click Path, click New, paste the QQ startup directory in, don’t forget to click OK_

Insert image description here

**Step 3:**After configuration, check whether the configuration is successful

1.Win+R 输入cmd回车,打开命令行窗口
2.输入QQScLanucher,可以看到QQ启动了

Insert image description here


  • Configure JDK to Path path

    Above we configured the QQ startup directory to the Path environment variable, then next, we configure the JDK bin directory to the Path environment variable, so that we can start javac and java commands in any directory to complete compilation and operation.

    **Step one:**Find the JDK bin directoryC:\Program Files\Java\jdk-17.0.3\bin and copy it

    **Step 2:** Paste the JDK bin directory after the Path environment variable

Insert image description here

Step 3: Check whether the configuration is successful

1.按住Win+R输入cmd 回车,打开命令行创建
2.输入javac -version 看提示信息是否显示你安装JDK的版本号
  输入java -version 看提示信息是否显示你安装JDK的版本号
【如果显示版本号都是JDK17就表示配置安装成功】

Insert image description here

If you follow the previous steps to get here, it means that the JDK environment variables have been configured, and you can use JDK commands to run in any directory.

3. Java development tools

When you wrote the code just now, you all used Notepad to write it, but did you find it inconvenient to write code in Notepad? When writing code in Notepad, there is no prompt if the wrong words are written, and the format is not easy to adjust. After writing the code, we still need to go to the command line to use the javac command to compile it manually, and then run it.

Is there a software that can integrate coding, compilation, running and other tools together? Yes, this is the Integrated Development Environment (IDE). In addition, IDEA also has functions such as code prompts and code error checking, thereby improving programmers' development efficiency.

There are many kinds of IDEs, the common ones are Eclipse, MyEclipse, Intellij IDEA, JBuilder, NetBeans, etc. However, the most popular among these IDEs is Intellij IDEA (hereinafter referred to as IDEA), which is regarded by many Java programmers as the most useful Java integrated development environment. Therefore, we use IDEA as a development tool to write code in our courses. From now on, everyone will go to The company also recommends using IDEA as a development environment.

Insert image description here

3.1 IDEA download and installation

In order to guide everyone to download and install IDEA correctly, a separate document "IDEA Installation, Use, Configuration.pdf" is provided for the friends. The document provides detailed installation and usage steps of IDEA. You only need to follow the instructions in the document. Just do it step by step.

Insert image description here

3.2 IDEA writes Java programs

After we installed IDEA in the previous section, we can use IDEA to develop a HelloWorld program and play with it! The purpose is to let everyone know the steps of developing Java programs in IDEA.

If you want to correctly write a Java program in IDEA, you must first understand IDEA's project structure for managing Java programs.

  • Step 1: First, you must create a Project (also called a project) in IDEA, which will be collectively referred to as a project from now on.
  • Step 2: You need to create a Module in the Project. A project can contain multiple modules.
  • Step 3: You need to create a new Package in Module. There can be multiple packages in a module.
  • Step 4: You need to create a new Class in Package. A package can contain multiple classes.

Software engineering is actually similar to construction engineering. We understand it by comparing it with construction engineering.

  • Project: You can understand it as the yard of the community
  • Module: You can understand it as every building in the community yard
  • Package: You can understand it as one floor of each building
  • Class: You can understand it as the residents on each floor

Insert image description here

In actual development, projects such as Taobao website have many functions, so Taobao website is divided into different modules. The homepage is a module, the shopping cart is a module, and the order is also a module;

Insert image description here

Insert image description here

  • Create Project

    There are many steps to create a project. The detailed guidance steps provided in "IDEA Installation, Use, Configuration.pdf" can be followed step by step.

    Use a browser to open "IDEA Installation, Use, Configuration.pdf" and click on the navigation bar on the left to navigate to the corresponding location. Each part has screenshot steps.

Insert image description here

3.4 Various configurations of IDEA

When some students were using IDEA to write programs just now, they may feel that the font is relatively small, the background color is black, and the comments are gray, which makes it difficult to see clearly, and may be bad for the eyes for a long time. We can use IDEA-related settings to make the font larger, the background color to an eye-friendly color, and the comments to green.

  • Theme configuration

Insert image description here

  • Font configuration

Insert image description here

  • Background color configuration

Adjust the color value of the background color to 204, 238, 200; it is the eye protection color of bean paste green.

Insert image description here

For more configuration, you can refer to "IDEA Installation, Use, Configuration.pdf"

3.5 Commonly used shortcut keys

After talking about the related configuration of IDEA, let me tell you a very important tip for using IDEA. This is the shortcut key of IDEA. The so-called shortcut key is a combination of keys on the keyboard, which can help us generate code. Using shortcut keys can greatly improve our development efficiency.

Below are several common shortcut keys and their functions. You can try them yourself.

shortcut key Functional effect
main/psvm、sout、… Quickly type relevant code
Ctrl + D Copy the current row data to the next row
Ctrl + Y To delete the line, it is recommended to use Ctrl + X
Ctrl + ALT + L Format code
ALT + SHIFT + ↑ , ALT + SHIFT + ↓ Move current code up or down
Ctrl + / , Ctrl + Shift + / Comment the code (we’ll talk about it later)

There are actually many shortcut keys. The ones listed here are the ones we use more frequently at this stage. It doesn’t matter if you remember them now. You will use them frequently in the future. Just use them and you will remember them.

When we talk about some new knowledge points in the following courses, we will continue to teach you some new shortcut keys.

4. Java basic syntax

All the content mentioned above is to make some preparations for Java program development. We have not officially taught you how to write code.

If you want to write Java code, you must learn Java syntax. The most important thing to learn syntax is to do the following two points.

  • Remember the syntax format
  • Make it clear what effect this syntax format can achieve

Here I need to explain something to you: the syntax format is specified by the designers of the Java language. We don’t need to care about why it is written this way, because it is written this way when it is created.

4.1 Notes

Let’s start with the simplest syntax and learn comments first!

  • What are annotations?

    Comments are used to explain problems in the program, making it easier for you and others to read the code.

  • What kinds of comments are there? What's the format?

    1.单行注释:
    	//后面根解释文字
    2.多行注释
        /*
        这里写注释文字
        可以写多行
        */
    3.文档注释
        /**
        这里写文档注释
        也可以写多行,文档注释可以利用JDK的工具生成帮助文档
        */
    
  • Below is a piece of code explained with comments

    /**
    目标:学会使用注释
         这是程序的讲解注释
    */
    public class NoteDemo{
          
          
        //这是程序的主方法,是程序的入口
        public static void main(String[] args){
          
          
            System.out.println("我开始学习Java程序,好嗨皮~~");
            /*
            窗前明月光
            疑是地上霜
            举头望明月
            低头思故乡
            */
            System.out.println("播仔");
            System.out.println("deli");
        }
    }
    

One more trick to learn: It is troublesome to add comments manually every time. You can also use shortcut keys to add comments.

Ctrl + / 	单行注释(对当前行进行注释)
Ctrl + Shift + / 	对选中的代码进行多行注释。

Insert image description here

4.2 Literals

After learning annotations, let's learn a brand new knowledge point called literals.

  • What is a literal?

    Don’t be confused by this word. It is actually very simple. We know that computers are used to process data. Literals actually tell programmers the writing format of data in the program. The following is the commonly used format for writing data in programs

Insert image description here

  • Write a program to print out various types of literal values ​​on the command line
/*
目标:需要同学们掌握常见数据在程序中的书写格式
*/
public class LiteralDemo{
    
    
    public static void main(String[] args){
    
    
        //1.整数
        System.out.println(666);
        
        //2.小数
        System.out.println(3.66);
        
        //3.字符: 字符必须用单引号引起来
        System.out.println('a');
        System.out.println('0');
        System.out.println('中');
        System.out.println(' '); //空格也算字符
        //特殊字符:\t表示制表符 \n表示换行
        System.out.println('\t'); //这相当于一个tab键,专业叫做制表符
        System.out.println('\n'); //这是换行的意思
        
        //4.字符串:字符串是双引号引起来的
        System.out.println("我爱你中国abc");
        
        //5.布尔值:只有两个值true和false
        System.out.println(true);
        System.out.println(false);
    }
}

To sum up: for literals, everyone just needs to be able to write various data correctly.

4.3 Variables

After learning about literals, let’s learn about variables. The learning path for variables is as follows

  1. First, let’s understand what a variable is?

  2. Learn why variables are used?

  3. What are the application scenarios of learning variables?

Insert image description here

  • What are variables?

Variables are used to record data in the program. It is essentially an area in memory. You can think of this area as a small box.

Insert image description here

Let’s demonstrate it through a piece of code and explain the meaning of the variables.

Insert image description here

int age = 18;
System.out.println(a);

When executingint age = 18; this code, the JVM will apply for an area in the memory, and store an integer 18 in this area. The name of this area is age; quite There is a data 18 stored in the box. The name of this box is age. When we print age, we take the data in the box out of the box and then print it.

  • Why use variables?

Using variables to record data makes data management more flexible. For example, we use an integer 10 in multiple places,

//1.假设4多个地方用到整数10; 现在我想把10改为20,这时你得一条语句一条语句的修改
System.out.println(10);
System.out.println(10);
System.out.println(10);
System.out.println(10);

//2.同样这里还是在多个地方用到整数10,你可以先用一个变量记录这个整数10
int x = 10;
//然后在需要用到整数10的地方,用x代替就行;
//如果我们把x值改了,那么后面用到x的值的地方就都一起改变了
System.out.println(x);
System.out.println(x);
System.out.println(x);
System.out.println(x);
  • Do variables have application scenarios?

The application scenarios of variables are everywhere. As long as the data can change in the program, variables can be used to store it. For example: the balance in your WeChat wallet, your WeChat nickname, and your WeChat personalized signature; whether the balance is getting smaller as you spend money, your nickname and personalized signature can also be modified frequently.

//比如:你现在有188.8元,一会要发100元,再收20元。
double money = 188.8;
//发100元
money = money - 100;
//再收20元
money = money + 20;
//再打印money记录的值是多少
System.out.println(money);


//再比如:公交车大人2元,小孩一元,公交车经过2站
//第一站:3个大人1个小孩上车
//第二站:1个大人1个小孩上车,请问一共上了多少人,一共收入多少钱?
//刚开始公交车箱子里没有钱,用money2表示箱子里的钱
int money2 = 0;
//刚开始公交车上也没有人,用count变量表示上车的人数
int count = 0;

//经过两站的人数:第一站3人,第二站1人,总的人数是3+1
count = 3+1;
//经过两站的钱数:
money2 = money2+3*2+1; //经过第一站后
money2 = money2+2+1; //经过第二站后

//打印人数和钱数
System.out.println(count);
System.out.println(money);
  • Notes on variables

In the last class, I have taught you the basic use of variables. Variables are used a lot in actual development. I need to explain to you the precautions for using variables.

The purpose of mentioning these precautions is to let everyone know which writing methods are allowed and which writing methods are not allowed, so that everyone can distinguish right from wrong and know why they are wrong.

1.变量定义在哪个{
    
    }范围内,就只在哪个大括号内有效。变量的有效范围称之为变量的作用域
	{
    
    
		int a = 10;
		System.out.println(a); //这是是对的
	}
	System.out.println(a); //这里会出错

2.在同一个作用域内,不能有两个同名的变量
	{
    
    
		int a = 10;
		int a = 20; //这里会出错
	}
	
3.变量没有初始化只,不能直接使用
	int a; //仅仅定义了变量,但是没有初始值
	System.out.println(a); //这里会出错

4.变量可以定义在同一行
	如:int a=10, b=20; //a和b都是int类型

At this point, we have finished learning about all the ways to use variables and the issues that need to be paid attention to with variables.

Let’s summarize a few more points

  • Variables are used to record data in the program. Variables can be understood as small boxes in memory. The things placed in the boxes are the data recorded by the variables.
  • Variable definition format:数据类型 变量名 = 初始值;
  • The data recorded by the variable can be changed during the running of the program:变量名 = 值;

4.4 Keywords

After learning variables, let's get to know Java keywords.

  • What are keywords?

    Keywords are words with special meanings in the Java language. For example, use int to represent integers, use double to represent decimals, and so on!

  • What are the keywords?

    The essence of our learning Java syntax is to learn the meaning of these keywords. There are more than 50 keywords in total. We will not learn these keywords all at once. We will learn a little bit every day in subsequent courses, and gradually you will learn them all. Learned.

abstract assert boolean break byte
case catch char class const
continue default do double else
enum extends final finally float
for goto if implements import
instanceof int interface long native
new package private protected public
return strictfp short static super
switch synchronized this throw throws
transient try void volatile while
  • How to identify which words are keywords?

Now we don’t need to know what these keywords mean. We can mainly identify which ones are keywords based on their characteristics.

关键字的特点:
	1.关键字都是小写的
	2.关键字在idea中有特殊颜色标记(如果你没有修改关键字的颜色,默认是蓝色的)

The words framed in red in the picture below are keywords; the words that are not framed are not keywords.

Insert image description here

4.5 Identifiers

Next, let’s learn about identifiers. The so-called identifiers are actually the names we choose ourselves. Like the class names we took earlier, variable names are actually identifiers.

The purpose of talking about identifiers is to let everyone know the rules of naming, and we cannot just pick them randomly. Some rules are mandatory and an error will be reported if not followed. There are also some rules that we recommend that everyone abide by, so that choosing a name will make us appear more professional_.

强制要求:必须遵守,不遵守就会报错
	1.最好是字母、数字、下划线、$组成
	2.不能以数字开头
	3.不能是Java的关键字

建议遵守:按照下面的方式取名字会显得更加专业
	1.所有的名字要见名知意,便于自己和别人阅读
		举例: class Student{
    
    } //一看这个类就知道表示一个学生
			  int age =10;    //一看这个变量就知道表示年龄
		
	2.类名:首字母大写(大驼峰命名)
		举例: class Student{
    
    }
		
	3.变量名:第二个单词开始首字母大写(小驼峰命名)
		举例: double money = 6.88;  
			  double applePrice = 7.5; 

At this point, congratulations, friends, you have finished learning all the content today, come on Oli! ! !

  | **volatile**   | **while**  |
  • How to identify which words are keywords?

Now we don’t need to know what these keywords mean. We can mainly identify which ones are keywords based on their characteristics.

关键字的特点:
	1.关键字都是小写的
	2.关键字在idea中有特殊颜色标记(如果你没有修改关键字的颜色,默认是蓝色的)

4.5 Identifiers

Next, let’s learn about identifiers. The so-called identifiers are actually the names we choose ourselves. Like the class names we took earlier, variable names are actually identifiers.

The purpose of talking about identifiers is to let everyone know the rules of naming, and we cannot just pick them randomly. Some rules are mandatory and an error will be reported if not followed. There are also some rules that we recommend that everyone abide by, so that choosing a name will make us appear more professional_.

强制要求:必须遵守,不遵守就会报错
	1.最好是字母、数字、下划线、$组成
	2.不能以数字开头
	3.不能是Java的关键字

建议遵守:按照下面的方式取名字会显得更加专业
	1.所有的名字要见名知意,便于自己和别人阅读
		举例: class Student{
    
    } //一看这个类就知道表示一个学生
			  int age =10;    //一看这个变量就知道表示年龄
		
	2.类名:首字母大写(大驼峰命名)
		举例: class Student{
    
    }
		
	3.变量名:第二个单词开始首字母大写(小驼峰命名)
		举例: double money = 6.88;  
			  double applePrice = 7.5; 

At this point, congratulations, friends, you have finished learning all the content today, come on Oli! ! !

Supongo que te gusta

Origin blog.csdn.net/Coastlise/article/details/130238526
Recomendado
Clasificación