Java基础01:注释
注释不会被执行,是给我们写代码的人看的,书写注释是一个非常好的习惯,平时写代码一定要注意规范
注释的种类
- 单行注释:一般在最前面加上//
public class Hello{
public static void main(String[] args){
//发出对编程世界的呐喊
System.out.print("Hello World");
}
}
- 多行注释:可以注释一段文字
public class Hello{
public static void main(String[] args){
/*
我是多行注释
我是多行注释
我是多行注释
我是多行注释
*/
System.out.print("Hello World");
}
}
- 文档注释:// JavaDoc /** */
public class Hello{
public static void main(String[] args){
/**
* @Description HelloWorld
* @Author 苏兮梦
*/
System.out.print("Hello World");
}
}
有趣的代码注释
hello kitty 可爱的小猫咪
/*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!` `4!!!!!!!!!!~4!!!!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <~: ~!!!~ .. 4!!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ~~~~~~~ ' ud$$$$$ !!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ~~~~~~~~~: ?$$$$$$$$$ !!!!!!!!!!!!!!
* !!!!!!!!!!!` ``~!!!!!!!!!!!!!! ~~~~~ "*$$$$$k `!!!!!!!!!!!!!
* !!!!!!!!!! $$$$$bu. '~!~` . '~~~~ :~~~~ `4!!!!!!!!!!!
* !!!!!!!!! $$$$$$$$$$$c .zW$$$$$E ~~~~ ~~~~~~~~ ~~~~~: '!!!!!!!!!!
* !!!!!!!!! d$$$$$$$$$$$$$$$$$$$$$$E ~~~~~ '~~~~~~~~ ~~~~~ !!!!!!!!!!
* !!!!!!!!> 9$$$$$$$$$$$$$$$$$$$$$$$ '~~~~~~~ '~~~~~~~~ ~~~~ !!!!!!!!!!
* !!!!!!!!> $$$$$$$$$$$$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$$$$$u. `~!!!!!
* !!> .:!h '$$$$$$$$$$$$ed$$$$$$$$$$$$Fz$$b $$$$$$$$$$$$$$$$$$$$$F '!h. !!!
* !!!!!!!!L '$**$$$$$$$$$$$$$$$$$$$$$$ *$$$ $$$$$$$$$$$$$$$$$$$$F !!!!!!!!!
* !!!!!!!!! d$$$$$$$$$$$$$$$$$$$$$$$$buud$$$$$$$$$$$$$$$$$$$$" !!!!!!!!!!
* !!!!!!! .<! #$$*"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$* :!!!!!!!!!!!
* !!!!!!!!!!!!: d$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# :!!!!!!!!!!!!!
* !!!!!!!!!!!~ : '#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*" !!!!!!!!!!!!!!!
* !!!!!!!!!! !!!!!: ^"**$$$$$$$$$$$$$$$$$$$$**#" .:<!!!!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!:... .::!!!!!!!!!!!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
*/
简易计算器
/*
* +---------------------------+
* | / |
* +---------------------------+
* | [ 1,264.45 ] |
* +---------------------------+
* | |
* | |
* | [sto] [rcl] [<--] [AC/ON] |
* | |
* | [ ( ] [ ) ] [sqr] [ / ] |
* | |
* | [ 7 ] [ 8 ] [ 9 ] [ * ] |
* | |
* | [ 4 ] [ 5 ] [ 6 ] [ - ] |
* | |
* | [ 1 ] [ 2 ] [ 3 ] [ + ] |
* | |
* | [ 0 ] [ . ] [+/-] [ = ] |
* | |
* +---------------------------+
*/
猪宝宝
// _,--. ,--._
// \ > `|>o<|' < /
// `-. .-'
// / 'e___e` \
// ( (o o) )
// _\_ `=' _/_
// / /(`-._.-')\ \
// / / `.___,' \_\
// _/ / _____ \ \_
// / _(_,--' `--._)_ \
// `' )______@______( `'
// hjw / \
// /_________________\
// \ )( /
// \ / \ /
// ) | | (
// /`-'] [`-'\
// `--' `--'
//
狗头
/***
* ii. ;9ABH,
* SA391, .r9GG35&G
* &#ii13Gh; i3X31i;:,rB1
* iMs,:,i5895, .5G91:,:;:s1:8A
* 33::::,,;5G5, ,58Si,,:::,sHX;iH1
* Sr.,:;rs13BBX35hh11511h5Shhh5S3GAXS:.,,::,,1AG3i,GG
* .G51S511sr;;iiiishS8G89Shsrrsh59S;.,,,,,..5A85Si,h8
* :SB9s:,............................,,,.,,,SASh53h,1G.
* .r18S;..,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....,,.1H315199,rX,
* ;S89s,..,,,,,,,,,,,,,,,,,,,,,,,....,,.......,,,;r1ShS8,;Xi
* i55s:.........,,,,,,,,,,,,,,,,.,,,......,.....,,....r9&5.:X1
* 59;.....,. .,,,,,,,,,,,... .............,..:1;.:&s
* s8,..;53S5S3s. .,,,,,,,.,.. i15S5h1:.........,,,..,,:99
* 93.:39s:rSGB@A; ..,,,,..... .SG3hhh9G&BGi..,,,,,,,,,,,,.,83
* G5.G8 9#@@@@@X. .,,,,,,..... iA9,.S&B###@@Mr...,,,,,,,,..,.;Xh
* Gs.X8 S@@@@@@@B:..,,,,,,,,,,. rA1 ,A@@@@@@@@@H:........,,,,,,.iX:
* ;9. ,8A#@@@@@@#5,.,,,,,,,,,... 9A. 8@@@@@@@@@@M; ....,,,,,,,,S8
* X3 iS8XAHH8s.,,,,,,,,,,...,..58hH@@@@@@@@@Hs ...,,,,,,,:Gs
* r8, ,,,...,,,,,,,,,,..... ,h8XABMMHX3r. .,,,,,,,.rX:
* :9, . .:,..,:;;;::,.,,,,,.. .,,. ..,,,,,,.59
* .Si ,:.i8HBMMMMMB&5,.... . .,,,,,.sMr
* SS :: h@@@@@@@@@@#; . ... . ..,,,,iM5
* 91 . ;:.,1&@@@@@@MXs. . .,,:,:&S
* hS .... .:;,,,i3MMS1;..,..... . . ... ..,:,.99
* ,8; ..... .,:,..,8Ms:;,,,... .,::.83
* s&: .... .sS553B@@HX3s;,. .,;13h. .:::&1
* SXr . ...;s3G99XA&X88Shss11155hi. ,;:h&,
* iH8: . .. ,;iiii;,::,,,,,. .;irHA
* ,8X5; . ....... ,;iihS8Gi
* 1831, .,;irrrrrs&@
* ;5A8r. .:;iiiiirrss1H
* :X@H3s....... .,:;iii;iiiiirsrh
* r#h:;,...,,.. .,,:;;;;;:::,... .:;;;;;;iiiirrss1
* ,M8 ..,....,.....,,::::::,,... . .,;;;iiiiiirss11h
* 8B;.,,,,,,,.,..... . .. .:;;;;iirrsss111h
* i@5,:::,,,,,,,,.... . . .:::;;;;;irrrss111111
* 9Bi,:,,,,...... ..r91;;;;;iirrsss1ss1111
*/
Java基础02:标识符和关键字
Java所有的组成部分都需要名字。类名、变量名以及方法名都被称为标识符。
标识符注意点:
- 所有的标识符都应该以字母(A-Z或者a-z),美元符($)、或者下划线(_)开始
- 首字符之后可以是任何字符的组合
- 不能使用关键字作为变量名或方法名
- 标识符是大小写敏感的
- 合法标识符举例:age、$salary、_value、__1_value
- 非法标识符举例:123abc、-salary、#abc
- 可以使用中文命名,但是一般不建议这样去使用,也不建议使用拼音,比较Low
public static void main(String[] args){
String 王者荣耀 = "最强王者";
System.out.print("Hello World");
}
以下是Java阶段常见的关键字:
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 |
Java基础03:数据类型讲解
强类型语言:要求变量的使用要严格符合规定,所有变量都必须先定义后才能使用
弱类型语言
Java的数据类型分为两大类
基本类型(primitive type)
- 整数类型
- byte占1个字节范围
- short占2个字节范围
- int占4个字节范围
- long占8个字节范围
- 浮点类型
- float占4个字节范围
- double占8个字节范围
- 字符类型
- char占2个字节范围
- boolean类型:占1位其值只有true和false两个
public class Demo{
public static void main(String[] args){
//八大基本数据类型
//整数
int num1 = 10; //最常用
byte num2 = 20;
short num3 = 30;
long num4 = 40L; //Long类型要在数字后面加个L
//小数:浮点数
float num5 = 50.1F; //float类型要在数字后面加个F
double num6 = 3.141592653589793238462643;
//字符
char name = '中';
//布尔值:是非
boolean flag = true;
//boolean flag = false;
}
}
什么是字节
- 位(bit):是计算机内部数据储存的最小单位,11001100是一个八位二进制数
- 字节(byte):是计算机中数据处理的基本单位,习惯上用大写B来表示
- 1B(byte,字节)= 8bit(位)
- 字符:是指计算机中使用的字母、数字、字和符号
- 1bit表示1位
- 1Byte表示一个字节 1B = 8b
- 1024B = 1KB
- 1024KB = 1M
- 1024M = 1G
引用类型(reference type)
- 类
- 接口
- 数组