--- title: Java(1) tags: Java --- {%hackmd @themes/orangeheart %} ## 1.0 Java 入門 總而言之呢,Java的整合開發環境也是五花八門,但本系列文章主要著重在**eclipse**和**IntelliJ IDEA**上。  每個程式語言都一樣,設置好環境第一件事情就是"Hello, world!"。 相信來碰java的人都不是第一次寫程式,所以那些一看就懂的就不解釋了~~ #### :coffee:程式碼 1.0.1 (Hello, world!) ```java= // 這是註解符號沒問題吧~~ class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!");//這行是輸出,其他都當殼看 } } ``` 確定執行沒有bugs以後,來深入了解java的內容。 java裡面的應用程序,幾乎都是用`class`定義的,就像上一個程式碼,那是一個名為`HelloWorld`的程式,功能是輸出`Hello, World!` 先了解一下java是一個寫起來令人安心的語言,它是一種強類型語言,也就是它的數據型態不會被後面的改變,藉由以下程式碼,我們可以知道: #### :coffee:程式碼 1.0.2 (不能隨便更改數據型態喔) ```java= //輸出60 int speed = 50; speed = 60; //error int speed = 50; float speed; ``` #### :coffee:程式碼 1.0.3 (這是數據型態block) ```java= //一些見怪不怪的基本常識 int a = 1;//32位元 float b = 2.5; char c = 'F';//16位元 boolean d = false;//這居然是小寫,我也是剛剛才發現 byte e = -128//八位元可以儲存-128~127的整數資料,比int省空間 short f = -32768//16位元,-32768~32767,還是比int省空間 long g = -9223372036854775808L//64位元,要記得L ///////////////////////////////////////////////////////// //整數4型態 ////binary int binaryNumber = 0b10010; ////octal int octalNumber = 027; ////decimal int decNumber = 34; ////hexadecimal int hexNumber = 0x2F; // 0x represents hexadecimal ///////////////////////////////////////////////////////// //這些運行起來一樣,但注意float要加f double d = 3.445e2d;//64位元 float f = 3.445e2f;//32位元 System.out.println(d); System.out.println(f); ///////////////////////////////////////////////////////// //unicode編碼,從\u0000~\uffff;ascii編碼從0~128 char letter1 = '?'; char letter2 = '\uffff';//unicode char letter3 = 128;//ascii ///////////////////////////////////////////////////////// //你可能期待string很久了,但它仍然不會出現,因為它不是原始數據型態。 ``` ### :strawberry:算術運算子(arithmetic operator):  #### :coffee:程式碼 1.0.4 (各種運算符) ```java= int a=24, b=7; System.out.println(a + b);//加 System.out.println(a - b);//減 System.out.println(a * b);//乘 System.out.println(a / b);//除 System.out.println(a % b);//取餘數 ///////////////////////////////////////////////////////// System.out.println(9 / 4);//出來整數 System.out.println(9.0 / 4);//出來浮點數 System.out.println(9 / 4.0);//出來浮點數 ``` ### :strawberry:賦值運算子(assignment operator): 這應該是不用多說了吧~~  ### :strawberry:比較運算子(comparison operator): 這也是~  ### :strawberry:邏輯運算符(logical operator)  ### :strawberry:一元運算符(unary operator)  ### :coffee:程式碼 1.2 ```java= ``` ### :coffee:程式碼 1.2 ```java= ``` ### :coffee:程式碼 1.2 ```java= ``` ### :coffee:程式碼 1.2 ```java= ``` ## C++ Variables #### :rabbit:基礎數據類型  #### :six:整數 Integers  可以儲存`-2147483648 ~ 2147483647`的值。如果超出這個範圍會怎樣? #### :A:字符、寬字符 Characters 就像`float`和`double`的關係一樣,`wchar_t`就是2 bytes的`char`。 #### :snake:轉義序列 Escape Sequences  codeblock、DevC++,編譯+組譯=執行檔 make file
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up