工欲善其事,必先利其器. 学java,先从ide入手.
快捷键
alt+command+v | Extract Variable | new Person() => Person person = new Person(); |
command+d | Duplicate current line or selected block | copy line |
双击括号 | select block | select block |
shift+enter | start new line at anywhere | |
command+shift+v | Paste from recent buffers... | paste history buffer |
command+alt+T | Surroundwith... (if..else, try..catch, for, synchronized, etc.) | ... => if (){...}else{} |
control + O | overide method | override method |
control + D | Debug | |
control + R | Run | |
command+; | Open Project Structure dialog | |
control + I | Implement methods | Implement class method |
option+enter | Show intention actions and quick-fixes | |
command+delete | delete line | |
hover red error of right side | show tips for error | |
command+/- | Expand / Collapse | |
; | 在括号里,输入分号,自动跳出 | |
command+opt+L | Reformat code | |
/** + command+opt+; | add comments | |
command+X | cut line | |
command+E | recent files |
以上是我用的比较多的快捷键. github也有大神专门整理了一番. https://github.com/xiaoxiunique/tool-tips
新建项目
Intellij IDEA 多module project :先创建empty project, add module
常见错误
1. Maven项目,运行时报错如下:Error : java 不支持发行版本5
project structure,修改language level , java compile 修改java版本
项目配置
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<target>13</target>
<source>13</source>
</configuration>
</plugin>
</plugins>
</build>
全局配置 ~/.m2/settings.xml
<profiles>
<profile>
<id>jdk1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>jdk1.8</activeProfile>
</activeProfiles>
maven-compile-plugin version
https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin
本地目录存储在:~/.m2/repository/org/apache/maven/plugins/maven-compiler-plugin
JSON
fastjson : https://github.com/alibaba/fastjson
//从字符串解析JSON对象
JSONObject obj = JSON.parseObject("{\"runoob\":\"菜鸟教程\"}");
//从字符串解析JSON数组
JSONArray arr = JSON.parseArray("[\"菜鸟教程\",\"RUNOOB\"]\n");
//将JSON对象转化为字符串
String objStr = JSON.toJSONString(obj);
//将JSON数组转化为字符串
String arrStr = JSON.toJSONString(arr);
多线程
//方法一
Thread tsub = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
while(true){
....
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
tsub.start();
//方法二
class ClockTick implements Runnable {
@Override
public void run() {
}
ClockTick clockTick = new ClockTick();
Thread thread1 = new Thread(clockTick);
thread1.start();
class.Class
String name = "hello world";
Class c = name.getClass();
System.out.println("getName:"+c.getName());
System.out.println("getName:"+c.getName());
System.out.println("isInterface:"+c.isInterface());
System.out.println("isPrimitive:"+c.isPrimitive());
System.out.println("isArray:"+c.isArray());
System.out.println("SuperClass:"+c.getSuperclass().getName());
输出结果:
getName: java.lang.String
isInterface: false
isPrimitive: false
isArray: false
SuperClass: java.lang.Object
Stream
Integer[][] integers = {
{1, 2, 3},
{4, 5, 6},
{23, 45, 2}
};
final List<Integer[]> list = Arrays.asList(integers);
List<Integer> collect = list.stream().flatMap(x -> Arrays.stream(x)).collect(Collectors.toList());
collect.forEach(System.out::println);
springboot
https://github.com/spring-projects/spring-data-examples
https://github.com/spring-projects/spring-data-book
springcloud
https://github.com/spring-cloud-samples/