java基础知识
java基础语法
注释
-
单行注释 //
//单行注释
-
多行注释 /* */
/*
多行注释
多行注释
*/ -
文档注释
-
//JavaDos注释 /** */
/***
* .::::.
* .::::::::.
* ::::::::::: love YOU
* ..:::::::::::'
* '::::::::::::'
* .::::::::::
* '::::::::::::::..
* ..::::::::::::.
* ``::::::::::::::::
* ::::``:::::::::' .:::.
* ::::' ':::::' .::::::::.
* .::::' :::: .:::::::'::::.
* .:::' ::::: .:::::::::' ':::::.
* .::' :::::.:::::::::' ':::::.
* .::' ::::::::::::::' ``::::.
* ...::: ::::::::::::' ``::.
* ```` ':. ':::::::::' ::::..
* '.:::::' ':'````..
*/
/***
* ┌───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
* │Esc│ │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│ ┌┐ ┌┐ ┌┐
* └───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘ └┘ └┘ └┘
* ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
* │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │
* ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
* │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │ │
* ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
* │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter │ │ 4 │ 5 │ 6 │ │
* ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤ ┌───┐ ├───┼───┼───┼───┤
* │ Shift │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│ Shift │ │ ↑ │ │ 1 │ 2 │ 3 │ │
* ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
* │ Ctrl│ │Alt │ Space │ Alt│ │ │Ctrl│ │ ← │ ↓ │ → │ │ 0 │ . │←─┘│
* └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
*/
-
标识符和关键字
关键字
java 常用的关键字有

abstract, assert,boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum,extends, final, finally, float, for, if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while
标识符
-
所有的标识符都应该以字符(A~Z |a~z),美元符号($)或者(_)
-
不能以关键字作为变量名或者方法
-
标识符是大小写敏感
![]()
数据类型
强类型语言 :
要求变量使用严格规定,所有变量都必须先定义后使用
弱类型语言:

Java的数据类型分为两大类
-
基本数据类型
-
整数
-
byte
-
short
-
int
-
long
-
-
浮点数
-
float
-
double
-
-
字符数据类型
char
-
布尔
boolean 占一位 true or false
-
-
引用数据类型
-
类
-
接口
-
数组
-
//八大基本数据类型
//整数
int num = 10;
byte num1 = 20;
short num2 = 30;
long num3 = 40;
//小数,浮点数
float num4 = 50.1F;
double num5 = 50.2;
// 字符
char name = 'A';
//String 字符串不是关键字,是类
// String name = "monkey";
//布尔值
boolean flag = true;
字节和位

数据类型扩展
// 整数扩展 进制 二进制 0b 八进制 0 十六进制 0x
int i = 0b10;
int i1 = 010;
int i2 = 0x10;
System.out.println(i);
System.out.println(i1);
System.out.println(i2);
// ==================================
// 浮点数扩展
//银行业务用BigDecimal
// ========================================
float f = 0.1f;
double d = 1.0/10;
System.out.println(d == f);
float d1 = 234444444444444445555f;
float d2 = d1 + 1;
System.out.println(d1 == d2);
// ==================================
// 字符扩展
// ========================================
char c1 = '猴';
char c2 = 'c';
System.out.println(c1);
System.out.println((int) c1);
System.out.println(c2);
System.out.println((int) c2);
//转义字符
/*
\t 制表符
\n 换行符
*/
System.out.println("hello \n world");
System.out.println("hello \t world");
System.out.println("=======================");
String sa = new String("helloworld");
String sb = new String("helloworld");
System.out.println(sa == sb);
System.out.println("==========================");
String sc = "helloworld";
String sd = "helloworld";
System.out.println(sc == sd);
// ================================
// 布尔值的扩转
boolean flag1 = true;
if(flag1 == true){} //新手
if(flag1){} //老手


浙公网安备 33010602011771号