Java基础教程

工欲善其事,必先利其器. 学java,先从ide入手.

快捷键

alt+command+vExtract Variablenew Person() => Person person = new Person();
command+d

Duplicate current line or selected block

copy line
双击括号select blockselect block
shift+enterstart 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 + Ooveride methodoverride method
control + DDebug  
control + RRun 
command+;

Open Project Structure dialog

 
control + I

Implement methods

Implement class method

option+enter

Show intention actions and quick-fixes

 
command+deletedelete line 
hover red error of right sideshow tips for error 
command+/-Expand / Collapse 
;在括号里,输入分号,自动跳出 
command+opt+L

Reformat code

 
/** + command+opt+;add comments   
command+Xcut line 
command+Erecent 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/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

anssummer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值