我的Java知識複習回顧筆記

來源:互聯網
上載者:User

標籤:命名   不能   bsp   java   知識   one   數字   限制   nbsp   

  1 public class JavaSE {  2   3     public static void main(String[] args) {  4       /*  5        * JDK JRE JVM  6        * 注釋  7        * 標識符:給變數、類、方法命名   8        * 首字元只能以字母、底線、$開頭  9        * 其他部分可以是字母、底線"_"、$、數位任意組合 10        * 區分大小寫,且長度無限制 11        * 不可以是Java關鍵字 12        * 可以是中文  13        *  14        * java內部採用了Unicode字元集(2個位元組表示一個字元),universal 15        * 8種基本類型:(數值型)byte、int、short、long、(字元型)char、(浮點型)double、float、(布爾型)boolean 16        * 數值型:byte(1個位元組 -128~127)、short(2位元組 -2^15~2^15-1 -32768~32767) 17        * int(4個位元組 -2^31~2^31-1)、long(8位元組 -2^63~2^63-1) 18        * int a1 = 10;(十進位)int a2 = 010;(八進位)int a3 = oxf;(十六進位) 19        * 十-->二:Integer.toBinaryString(a1); 20        * 十-->八:Integer.toOctalString(a1); 21        * 十-->十六:Integer.toHexString(a1); 22        * byte a4 = 10;short a5 = 100;long a6 = 1000; 23        * 如果資料的大小沒有超過byte/short/long的表述範圍,則可以自動轉型 24        * long a7 = 1000L; 25        * 浮點數:double(預設)、float 26        * double d = 3.14; float = 0.1f; 27        * float(4位元組):-3.403E38~3.403E38 28        * double(8位元組):-1.798E308~1.798E308 29        * 使用總結:浮點數存在舍入誤差,很多數字不能精確表示。 30        * 由於有無限小數,我們不可能用有限的數來表示無限的數,只能盡量精確。 31        * 如果需要進行不產生舍入誤差的精確數字計算,需要使用BigDecimal 32        * 字元型:char(2個位元組 0~2^16(65536))char類型用來表示在Unicode編碼錶中的字元 33        * Unicode編碼被設計用來處理各種語言的所有文字,它佔2個位元組,可以允許有65536個字元 34        * Unicode具有從0到65535之間的編碼,他們通常用從’\u0000’到’\uFFFF’之間的十六進位值來表示(首碼為u表示Unicode) 35        * ASCII碼佔1個位元組,可允許有128個字元,是Unicode編碼錶中前128個字元。 36        * char是在0~65535範圍,運算時直接當作整數來運算。 37        * 可以把0~65535之間的整數直接轉型為char 38        * 逸出字元:\t、\n、\r、\\、\b、\‘、\‘‘ 39        * 布爾類型:boolean(1位、不是1個位元組,一個位元組有8位,只有兩個值true和false) 40        *  41        * 自動類型轉化和強制類型轉化 42        * 自動類型轉化規則:(1)byte-->short-->int-->long 43        * (2)無資料丟失:char-->int  float、int-->double 44        * (3)可能丟失精度:long-->float、double  int-->float 45        */ 46         47         //列印a-z 48         char c = ‘a‘; 49         for(int i = 0; i < 26; i++) { 50             char temp = (char) (c + i); 51             System.out.print(temp); 52         } 53          54         //測試強制轉換 55         int a = -100; 56         char b = (char)a; 57         System.out.println(b);//?,出現無意義的數 58         System.out.println("---------------------"); 59          60         //運算式中的型別提升問題 61         int i1 = 3; 62         long lo = 4; 63         double dou = 5.3; 64         //做所有的二元運算子(+-*/%都會有型別提升問題) 65         int i2 = (int)(lo+dou); 66         float f1 = (float)(i1+lo); 67          68         int money = 1000000000;//10億 69         int years = 20; 70         //long total = (long)(money*years);//返回的是負數,超過其表示數值範圍,要先進行類型轉換 71         long total = (long)money * years; 72         System.out.println(total); 73         System.out.println("---------------------"); 74          75         //一個人70年心跳多少次 76         long times = 70L*60*24*366*70*60;//最好將long類型放在最前面,以防前面的數相乘容易溢出 77         System.out.println(times); 78          79         //JDK7新特性:底線分隔字元 80         int i3 = 0b0000_0000_0000_0011;//3,如果沒有0b,則是八位元9 81         int i4 = 1_1234_1234;//112341234 82         System.out.println(i3); 83         System.out.println(i4); 84          85         //Java語言支援如下運算子: 86         /*算術運算子:+、-、*、/、%、++、--、 87          *賦值運算子:= 88          *關係運算子:>、<、>=、<=、==、!=、instanceof 89          *邏輯運算子:&&、||、! 90          *位元運算符:&、|、^、~、>>、<<、>>> 91          *條件運算子:?: 92          *擴充賦值運算子:+=、-=、*=、/= 93         */ 94          95       //debug調試 96       /** 97        * 控制語句:順序、選擇、迴圈 98        * if語句、if/else語句、switch/case/default語句 99        * JDK1.7新特性:switch case:"字串"可以編寫100        */101         double d = Math.random();102         int e =1 + (int)(d*6);//強制轉換的數結果取整數部分103         System.out.println(e);104         if(e > 3) {105             System.out.println("大象!");106         } else {107         System.out.println("麗麗");108         }109     }110 }

 

我的Java知識複習回顧筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.