Java foundation
Note
Write notes is a very good habit
- Single-line comments: // , shortcut keys Ctrl + /, again according to revoke comments
- Multi-line comments: / * * / , shortcut keys Ctrl + shift + / Undo Ctrl + shift + \
- Document Note: It / * * Start to *** / ** end, the shortcut keys shift + alt + j
Identifier
In Java, class names, variable names and method names are called tags.
- Identifier should be uppercase and lowercase letters, the dollar sign $, or underscore start
- After the first character can be uppercase and lowercase letters, numbers, the dollar sign $, underscore _
- You can not use keywords as identifiers
- Identifiers are case sensitive
- Chinese and pinyin names can be used, but not recommended
Keyword
保留字
goto const
基本类型
boolean byte char double float int long short null true false
类,方法和变量修饰符
abstract class extends final implements interface native new
static strictfp synchronized transient volatile
访问控制
private protected public
程序控制
break continue return do while if else for instanceof switch
case default
异常处理
try cathc throw throws
包相关
import package
变量引用
super this void
type of data
Basic data types
type name | Keyword | used internal memory | Ranges |
---|---|---|---|
Byte | byte | 1 byte | -128~127 |
Short integer | short | 2 bytes | -32768~32767 |
Integer | int | 4 bytes | -2147483648~2147483647 |
Long integer | long | 8 bytes | -9223372036854775808L ~ 9223372036854775807L |
Single-precision floating-point | float | 4 bytes | +/- 3.4E + 38F (6 ~ 7 significant digits) |
Double-precision floating-point | double | 8 bytes | +/- 1.8E + 308 (15 significant digits) |
Character | char | 2 bytes | ISO single character set |
Boolean | boolean | 1 byte | true or false |
FIG Java data type structures
Example :
//整数
int a = 10;
short b = 100;
long c = 1000L;
byte d = 1;
//浮点型
float f = 1.1F;
double e = 3.14;
//字符
char ch = 'a';
//字符串
String str = "Hello";
boolean flag = true;