Java Notes Chapter 1 (Grammar)

0. Comments

// --Single-line comments.
/* */ --Mulitiline comments.
/** --Documention comments.

1. Identifiers

a. keyWord
b. varName
c. className


2. Data Types

在这里插入图片描述
Tips:
a. Long type need a “L” at the end of expression.
b. Float type need a “F” at the end of expression.
c. String is a class , not a keyWord.

Expands:
a. Base

  • Binary starts with 0b.
  • Octal starts with 0.
  • Hex starts with 0x.

b. Do not use floating-points for comparing.
c. Java can convert character to Unicode.


3. Type Convert

a. Forced convert

( Type ) [varName] 

When capacity from high to low

b. Auto convert

When capacity from low to high

c. Tips
①Do not convert booleans.
②Forced convert maybe occur a accuracy problem.
③When the number is too large, the underline can be used for segmentation.


4. Vars and Consts

a. Scopes
①Class var: Outside the method , need “static” to state.
②Instance var: Outside the method , state directly.( I do not know the differences between them temporarily ( _ _)ノ|)
③Local var: Inside the method , must state and initialize.

b. Define a const

final [CONST_NAME] = [Value] 

b. Naming conventions
①All names need to be clear.
②Var names use camel case ( uppercasing the first letter of each word)
③Const names need to uppercase every letter.


5. Calc

a. Priority of data types
double > long > int

b. Self-added operator
a++: Assign first and then increase.
++a: Increase first and the assign.

c. Logic calculations
①&&(Short circuit AND): If the first value is 0 , do not judge the second value and then output 0.
②||(Short circuit OR): If the first value is 1 , do not judge the second value and then output 1.
③!(NOT): Convert 1 to 0 and also 0 to 1.
④&(Bit AND): If the input data type is int , this is a bit operator ,It will convert the values on both sides into binary first , and then carry out logical calculation according to each bit. Else this is a logical operator , it will judge both values and output.
⑤I(Bit OR): The same as mentioned above.
⑥^(XOR): The same is zero, and the different is one.
⑦~(Reverse): When use as a logical operator , it’s function as same as NOT. When use as a bit operator , it can reverse according to each bit.

d. String connector
"+"
From left to right , if there is a string , execute string connection automatically.

e. Ternary operator

public class Hello {
    public static void main(String[] args) {
        int s=98;
        String t = s < 100 ? "junk" : "new bee" ;
        System.out.println(t);
    }
}

6. Package

  • The essence of package is a folder.
  • Use “import” to import external packages.
  • Use javadoc to create docs of a java program(include structure and so on) , the method is on below
javadoc -encoding UTF-8 -charset UTF-8

This day is finished , if you have any problem , welcome to question me.ヾ(•ω•`)o

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值