This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1、编码算法 | |
ASCII码就是一种编码,字母A的编码是十六进制的0x41,字母B是0x42,以此类推: | |
字母 ASCII编码 | |
A 0x41 | |
B 0x42 | |
C 0x43 | |
D 0x44 | |
… … |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd /home 进入根目录 | |
cd filename 进入当前目录下的filename文件 | |
sz filename 下载该文件 | |
ps -ef|grep filename | |
grep 用于查找文件里符合条件的字符串 | |
grep –n “查找内容” 文件名 | |
ps 格式:ps [options] [--help]。说明:显示进程的名称、占用资源、状态等。 | |
ps -e 显示环境变量 | |
ps -f 显示进程间的关系 | |
ps -ef 显示所有命令,连带命令行 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
正则表达式简介 | |
几个非常常见的问题: | |
如何判断字符串是否是有效的电话号码?例如:010-1234567,123ABC456,13510001000等; | |
如何判断字符串是否是有效的电子邮件地址?例如:test@example.com,test#example等; | |
如何判断字符串是否是有效的时间?例如:12:34,09:60,99:99等 | |
一种直观的想法是通过程序判断,这种方法需要为每种用例创建规则,然后用代码实现。下面是判断手机号的代码: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java语言内置了多线程支持。当Java程序启动的时候,实际上是启动了一个JVM进程,然后,JVM启动主线程来执行main()方法。在main()方法中,我们又可以启动其他线程。 | |
要创建一个新线程非常容易,我们需要实例化一个Thread实例,然后调用它的start()方法: | |
public class Main { //多线程 | |
public static void main(String[] args) { | |
Thread t = new Thread(); | |
t.start(); // 启动新线程 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
一个Java项目首先需要确定引入哪些依赖包。 | |
其次,我们要确定项目的目录结构。例如,src目录存放Java源码,resources目录存放配置文件,bin目录存放编译生成的.class文件。 | |
此外,还需要配置环境,例如JDK的版本,编译打包的流程,当前代码的版本号。 | |
最后,除了使用Eclipse这样的IDE进行编译外,还必须能通过命令行工具进行编译,才能够让项目在一个独立的服务器上编译、测试、部署。 | |
如果每一个项目都自己搞一套配置,非常琐碎且耗时,需要一个标准化的Java项目管理和构建工具。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java的方法分为实例方法,例如Integer定义的equals()方法: | |
public final class Integer { | |
boolean equals(Object o) { | |
... | |
} | |
} | |
以及静态方法,例如Integer定义的parseInt()方法: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java的反射是指程序在运行期可以拿到一个对象的所有信息。 | |
正常情况下,如果我们要调用一个对象的方法,或者访问一个对象的字段,通常会传入对象实例: | |
// Main.java | |
import com.itranswarp.learnjava.Person; | |
public class Main { | |
String getFullName(Person p) { | |
return p.getFirstName() + " " + p.getLastName(); | |
} | |
} |
NewerOlder