day02-Java基础语法

Java 基础语法

1. Notes

​ Comments are explanations and explanatory text for the code.

There are three types of annotations in Java:

  • Single-line comments:
// single line comment text
  • Multi-line comments:
/*
This is a multiline comment text
This is a multiline comment text
This is a multiline comment text
*/
  • Documentation notes:
/**

This is the doc comment text
*/

Techniques used

If we want to explain the code, then we can use comments.

​ When the content of the comment is relatively small, it can be written in one line, and a single line comment can be used.

​ If the comment has a lot of content and needs to be written in multiple lines, then you can use multi-line comments.

be careful

​ The content of the comment will not participate in compilation and operation, but only an explanation of the code.

​ Therefore, no matter what is written in the comment, it will not affect the result of the code running.

2. Keywords

2.1 Concept

​ An English word given a specific meaning by Java.

​ After we write keywords in the code, when the program is running, we know what to do.

Note: There are many keywords, so don’t deliberately remember them.

abstractassertbooleanbreakbyte
casecatchcharclassconst
continuedefaultdodoubleelse
enumextendsfinalfinallyfloat
forgotoifimplementsimport
instanceofintinterfacelongnative
newpackageprivateprotectedpublic
returnstrictfpshortstaticsuper
switchsynchronizedthisthrowthrows
transienttryvoidvolatilewhile

2.2 Keyword class

​ means to define a class. Create a class.

Class: The most basic unit of a Java project. A complete Java project may consist of thousands of classes.

Class is followed by the name of the class, abbreviated as: class name.

There will be a pair of curly braces after the class name, indicating the content of this class.

Example:

public class HelloWorld{
    
   
}

Explanation: class means to define a class.

​ Class name: HelloWorld

​ The braces after HelloWorld indicate the scope of this class.

3. Literals

Function: Tell the programmer the writing format of the data in the program.

字面量类型说明程序中的写法
整数不带小数的数字666,-88
小数带小数的数字13.14,-5.21
字符必须使用单引号,有且仅能一个字符‘A’,‘0’, ‘m’
字符串必须使用双引号,内容可有可无“HelloWorld”
布尔值布尔值,表示真假,只有两个值:true,falsetrue 、false
空值一个特殊的值,空值值是:null
public class Demo {
     public static void main(String[] args) {
         System.out.println(10); // output an integer
         System.out.println(5.5); // output a decimal
         System.out.println('a'); // output a character
         System.out.println(true); // output boolean value true
         System.out.println("helloworld"); // output string
     }
}

Differentiation skills

  1. Numbers without a decimal point are integer literals.
  2. As long as a decimal point is included, it is a literal value of the decimal type.
  3. As long as it is enclosed in double quotation marks, no matter what the content inside is, no matter whether there is content inside, it is a literal value of string type.
  4. The literal value of the character type must be enclosed in single quotation marks, no matter what the content is, but there is one and only one.
  5. The literal value of character type has only two values, true and false.
  6. Empty type literals have only one value, null.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值