1. 程式人生 > 其它 >Java基礎語法(1)

Java基礎語法(1)

Java基礎語法(1)

註釋

Java中有單行註釋、多行註釋、文件註釋

public class HelloWorld {
   public static void main(String[] args) {
       //輸出一個HelloWorld
       System.out.println("Hello,World!");
       /* 多行註釋
       *
       *
       *
       *
       *
       * */

       //JavaDoc:文件註釋

       /**
        *               ii.                                         ;9ABH,
        *             SA391,                                   .r9GG35&G
        *             &#ii13Gh;                               i3X31i;:,rB1
        *             iMs,:,i5895,                         .5G91:,:;:s1:8A
        *               33::::,,;5G5,                     ,58Si,,:::,sHX;iH1
        *               Sr.,:;rs13BBX35hh11511h5Shhh5S3GAXS:.,,::,,1AG3i,GG
        *               .G51S511sr;;iiiishS8G89Shsrrsh59S;.,,,,,..5A85Si,h8
        *               :SB9s:,............................,,,.,,,SASh53h,1G.
        *           .r18S;..,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....,,.1H315199,rX,
        *         ;S89s,..,,,,,,,,,,,,,,,,,,,,,,,....,,.......,,,;r1ShS8,;Xi
        *       i55s:.........,,,,,,,,,,,,,,,,.,,,......,.....,,....r9&5.:X1
        *       59;.....,.     .,,,,,,,,,,,...       .............,..:1;.:&s
        *     s8,..;53S5S3s.   .,,,,,,,.,..     i15S5h1:.........,,,..,,:99
        *     93.:39s:rSGB@A; ..,,,,.....   .SG3hhh9G&BGi..,,,,,,,,,,,,.,83
        *     G5.G8 9#@@@@@X. .,,,,,,..... iA9,.S&B###@@Mr...,,,,,,,,..,.;Xh
        *     Gs.X8 S@@@@@@@B:..,,,,,,,,,,. rA1 ,A@@@@@@@@@H:........,,,,,,.iX:
        *     ;9. ,8A#@@@@@@#5,.,,,,,,,,,... 9A. 8@@@@@@@@@@M;   ....,,,,,,,,S8
        *     X3   iS8XAHH8s.,,,,,,,,,,...,..58hH@@@@@@@@@Hs       ...,,,,,,,:Gs
        *   r8,       ,,,...,,,,,,,,,,..... ,h8XABMMHX3r.         .,,,,,,,.rX:
        *   :9, .   .:,..,:;;;::,.,,,,,..         .,,.               ..,,,,,,.59
        * .Si     ,:.i8HBMMMMMB&5,....                   .           .,,,,,.sMr
        * SS       :: h@@@@@@@@@@#; .                     ... .         ..,,,,iM5
        * 91 .   ;:.,1&@@@@@@MXs.                           .         .,,:,:&S
        * hS .... .:;,,,i3MMS1;..,..... . .     ...                     ..,:,.99
        * ,8; ..... .,:,..,8Ms:;,,,...                                     .,::.83
        *   s&: .... .sS553B@@HX3s;,.   .,;13h.                           .:::&1
        *   SXr . ...;s3G99XA&X88Shss11155hi.                             ,;:h&,
        *     iH8: . ..   ,;iiii;,::,,,,,.                                 .;irHA
        *     ,8X5;   .     .......                                       ,;iihS8Gi
        *         1831,                                                 .,;irrrrrs&@
        *           ;5A8r.                                           .:;iiiiirrss1H
        *             :X@H3s.......                               .,:;iii;iiiiirsrh
        *             r#h:;,...,,.. .,,:;;;;;:::,...             .:;;;;;;iiiirrss1
        *             ,M8 ..,....,.....,,::::::,,...         .     .,;;;iiiiiirss11h
        *             8B;.,,,,,,,.,.....         .           ..   .:;;;;iirrsss111h
        *           i@5,:::,,,,,,,,.... .                   . .:::;;;;;irrrss111111
        *           9Bi,:,,,,......                       ..r91;;;;;iirrsss1ss1111
        */

  }
}

識別符號

Java所有組成部分都需要名字。類名、變數名以及方法名都被稱為識別符號。

識別符號是大小寫敏感的

資料型別

強型別語言

要求變數的使用要嚴格符合規定,所有變數都必須先定義後使用。

弱型別語言

VB,JS

Java的資料型別分為兩大類

基本型別(primitive type)

數值型別
整數型別

byte佔1個位元組範圍:-128-127

short佔2個位元組範圍:-32768-32767

int佔4個位元組範圍

long佔8個位元組範圍

浮點型別

floa佔4個位元組

double佔8個位元組

字元型別

char佔2個位元組

Boolean型別:佔1位其值只有true和false兩個

引用型別(reference type)

類,介面,陣列

什麼是位元組

位(bit):最小儲存單位

位元組(byte):資料處理基本單位

1B (byte)= 8bit(位)

字元:字母、數字、字和符號

拓展

public class Demo03 {
   public static void main(String[] args) {
       //整數拓展 進位制   二進位制0b   十進位制     八進位制0     十六進位制0x
       int i = 10;
       int i2 = 010; //八進位制
       int i3 = 0x10;//十六進位制   0~9 A~F 16

       System.out.println(i);
       System.out.println(i2);
       System.out.println(i3);
       System.out.println("===================================================================");
       //===================================================================
       //浮點數拓展? 銀行業務怎麼表示?錢
       //BigDecimal 數學工具類
       //===================================================================
       //float   有限的   離散 舍入誤差 大約   接近但不等於
       //double
       //最好使用浮點數去比較

       float f = 0.1f;//0.1
       double d = 1.0/10;//0.1

       System.out.println(f==d);//false
       float d1 = 124131341231f;
       float d2 = d1 + 1;
       System.out.println(d1==d2);//true


       //===================================================================
       //字元拓展?
       //===================================================================
       System.out.println("===================================================================");
       char c1 = 'a';
       char c2 = '中';

       System.out.println(c1);

       System.out.println((int)c1);

       System.out.println(c2);

       System.out.println((int)c2);
       //所有的字元本質還是數字
       //編碼 Unicode   表:(97 = a 65 = A ) 2位元組     0 - 65536   Excel   2 16 = 65536

       //U0000 UFFFF

       char c3 = '\u0061';
       System.out.println(c3);

       //轉義字元
       // \t   製表符
       // \n   換行
       // ..........
       System.out.println("Hello\tWorld!");



       //

       System.out.println("===================================================================");
       String sa = new String("hello world!");
       String sb = new String("hello world!");
       System.out.println(sa==sb);

       String sc = "hello world!";