IDEA 2021簡單設置與優化
- 將工具條顯示在上方
View–>Appearance–>Toolbar
- 鼠標懸停顯示
File–>setting–>Editor–>General–>CodeCompletion–>勾選show zhe documentation popup in 1000 ms
- 忽略大小寫
File–>setting–>Editor–>General–>CodeCompletion–>將Match case的勾去掉
-
intellij IDEA中 introduce local variable 快捷鍵自動補全
解決:Alt+Enter 就會彈出如下界面 選擇后 便可以自動補全 -
找到IDEA安裝目錄 選擇idea64.exe.vmoptions文件用notepad++打開並修改
默認的設置太小的
-Xms128m -Xmx750m-XX:ReservedCodeCacheSize=240m
建議電腦4G內存以上的配置為:
-Xms2048m-Xmx2048m-XX:ReservedCodeCacheSize=1024m
需要注意的是,每次更新idea時該配置文件會自動復原,記住每次更新后重新設置一下。
運算符
-
java語言支持如下運算符: 優先級 ()
- 算數運算符:+ - * / % ++ --
- 估值運算符: =
- 關系運算符: < > >= <= == !=(不等於)
-
重點理解下 ++ -- 運算符 知道程序如何運行的
練習:
package operator; public class Demo01 { public static void main(String[] args) { // 二元運算符 //ctrl + D :復制當前行到下一行 int a = 10; int b = 20; int c = 25; int d = 25; System.out.println(a+b); System.out.println(a-b); System.out.println(a*b); System.out.println(a/(double)b); } }
package operator; public class Demo02 { public static void main(String[] args) { long a = 123123123123L; int b = 123; short c = 10; byte d = 8; System.out.println(a+b+c+d); //long System.out.println(b+c+d); //int System.out.println(c+d); //int //有一個long輸出后即為long 按高級別運算后輸出,由double輸出即為double,其余全為int } }
package operator; public class Demo03 { public static void main(String[] args) { //關系運算符返回結果: 正確 錯誤 布爾型 int a = 10; int b = 20; int c = 21; System.out.println(c%a); // c/a 21/10.....1 取余數 模運算 System.out.println(a<b); //true System.out.println(a>b); //false System.out.println(a==b); //false System.out.println(a!=b); //true } }
package operator; public class Demo04 { public static void main(String[] args) { // ++ -- 自增 自減 一元運算符 int a = 3; int b = a++; //執行完這段代碼后,先給b賦值,再自增 //a++ a=a+1 System.out.println(a); //++a a=a+1 int c = ++a;//執行完這段代碼前,先自增,再給b賦值 System.out.println(a); System.out.println(b); System.out.println(c); //冪運算 2^3 2*2*2 =8 很多運算類會使用工具類操作 double pow = Math.pow(2, 3); System.out.println(pow); } }
- 邏輯運算符: && || ! 即 與 或 非
public class Demo05 { public static void main(String[] args) { // 與(and) 或(or) 非(取反) boolean a = true; boolean b = false; System.out.println("a && b: " + (a&&b));// false 兩個變量都為真 結果才為true System.out.println("a || b: " + (a||b));// true 兩個變量有一個為真 結果才為true System.out.println("!(a && b): " + !(a&&b));// true 如果是真則為假 如果是假則為真 //短路運算 int c = 5; boolean d = (c<4) && (c++ <4); System.out.println(d); //false 說明直接判斷c<4為false后不會在進行c++判斷 System.out.println(c); //5 如果判斷了則c值不可能是5,即為短路運算 } }
- 位運算符 & | …… ~ >> << >>>
package operator; public class Demo06 { public static void main(String[] args) { /* A = 0011 1100 B = 0000 1101 ----------------------- A&B = 0000 1100 A|B = 0011 1101 A^B = 0011 0001 ~B = 1111 0010 ----------------------- 一道面試題: 計算2*8 = 16 如何效率最高? 可拆分為 2*2*2*2 位運算,效率極高!!! << 即 *2 >> 即 /2 0000 0000 0 0000 0001 1 0000 0010 2 0000 0011 3 0000 0100 4 0000 1000 8 0001 0000 16 */ System.out.println(2<<3); //輸出 16 } }
- 擴展賦值運算符 += -= *= /=
package operator; public class Demo07 { public static void main(String[] args) { int a = 10; int b = 20; a+=b; // a = a+b 偷懶寫法 a-=b; // a = a-b 偷懶寫法 System.out.println(a); //30 //字符串連接符 + , String System.out.println(a+b); //30 //------------------------------ //一道面試題:計算a+b+"" 和 ""+a+b System.out.println(a+b+""); //30 字符串在后,則先計算在加字符串 System.out.println(""+a+b); //1020 字符串在前 則直接執行字符串連接 } }
- 條件運算符 ? :
package operator; public class Demo08 { public static void main(String[] args) { // x ? y : z // 如果x==true 則結果為y,否則結果為z int score = 80; String type = score < 60 ? "不及格 " : "及格"; //必須掌握 // if 也可以做判斷 建議用條件運算符 System.out.println(type); //及格 } }
包機制
-
包 即為文件夾
-
一般利用公司域名倒置作為包名: com.kuang.www
3.例新建com.kuang的包
如果是com.kuang一個包則操作如下,取消Compact Middle Package即可
變為
-
為了能夠使用某一個包的成員,我們需要在java程序中明確導入該包。使用“import”語句即可完成此功能。
import package1[.package2.....].(classname |*);
-
切記包與包內名字不要重復
可以直接導入包內的所有文件