李楚垚
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Java基礎 語言簡介 --- **特點** * **物件導向** * **安全性** * **跨平台性質** java的歷史還啥的,你們有興趣就自己上網查吧,在此就不贅述了。 **物件導向** > 不同於結構化的C語言,JAVA採用了另一種方式分解一個程式,也就是透過類別(Class)以及物件(Object)建構程式,讓程式能以模組化以及抽象層次化的方式撰寫。 (以下將一一詳細解釋) **安全性** > **java最早使用於消費性電子領域,因此這個語言程式的安全性相當足夠。** 至於為何那麼說呢?主要是因為在進行編譯時,他會做類型匹配的檢查,也就是絕對防止類型不一的賦值,而對於內存管理則有自動回收機制,以及指針(pointer)錯誤的偵測,除以上之外,java的異常處理機制做的相當好,可以讓寫出來的程式具有很完整的流暢性,對於各種異常都能做有效地處理。 (這也是其得以作為消費性電子程式的原因之一) **跨平台性質** > 另一種說法,就是說JAVA的移植性相當好,也是當初設計這個程式的人給予的思想: **寫一次程式,所有裝置都能運行** 在電腦上寫完程式,轉換編譯後的byte code,可以直接放到具有JVM(java virtual machine)的裝置上運行,源代碼編譯後就能在各種硬體上運行了。 撰寫程式準備 --- 建議的java編譯及撰寫程式其實有很多種,其中推薦**IntelliJ IDEA**這款軟體, 大家可以在[這裡](https://www.jetbrains.com/idea/download/#section=windows)下載,選擇Community版本即可。 安裝過程跟使用網路上都有資料,自己爬文,不贅述。 創建/開啟JAVA專案後,在左側的src中建立一個class,名稱取作Hello_world, 並在內容中打上以下的code, ```java public class Hello_world { public static void main(String[] args) { System.out.print("Hello world!"); } } ``` 若能在下方的小黑窗看到你打的東西,恭喜!你已經完成了學習JAVA很大的一步了! (也意味著你有更多的大步要走**ヾ(◎´・ω・`)ノ**) 數據類型&常/變數 --- **資料型別** 跟C的型態類別沒有太大的不同,以下參考。 Java語言所定義的基本資料型如表 | 型別名稱 | 位元長度 | 範圍 | | -------- | -------- | -------- | |boolean|1 | true或false| |byte |8 |-128 ~ 127| |short |16 |-32768 ~ 32767| |char |16 |Unicode characters| |int |32 |-2147483648 ~ 2147483647| |long |64 |-922337...775808 ~ 9223372...75807| |float |32 |+-3.4028237*10+38 ~ +-1.30239846*10-45| |double |64 |+-1.76...231570*10+308 ~ 4.9406...44*10-324| **運算符號** **>>略去<<** 大多(幾乎)跟C都一樣,所以C Programming好好學ㄅ。 **語法** 以下只列出較不常看到但有時候很好用的語法,至於if、for、while、switch等常見的就略過。 *字串print out* ```java public class StringTest { public static void main(String[] argv) { int x = 5; float y = 1.5; System.out.println("x = " + x + ", y = " + y); } } ``` 參考以上的code,可以發現,JAVA的程式編撰可以藉由java編譯器相對應的append Method結合變數和字串的print輸出。 當然,一個運算式也是可允許在print中的,如下, ```java public class Example { public static void main(String[] argv) { int n = 100; System.out.println("1+2+...+"+n+" = " + ( n * (n + 1) / 2)); } } ``` 一般人可能會把String作為一種基本類型,其實不然, 看一下下面這行, ```java String b = new String("456"); ``` 用這行,就能解說java及許多程式的精隨之一, 一般,我們宣告及initialize基本型態變數,是像是下面的程式例子, ```java int n = 100; ``` 如果,有學過程式的就知道,上面能拆成兩個部分, int n; 是宣告了一個變數n,型態為int, n=100; 則是initialize, 類似地,分解成兩部分來看, 首先, String b; 是宣告了一個**String類**的b(請注意在這邊,String是一種類別!!), 而那個b,是一個String類的一個pointer,用來指向一個String類的物件(Obj), 再來看看後半段, b = new String("456"); new是一個關鍵字,意義是創建新對象(Obj),那是創哪一類的對象呢? 在這個例子中,就是String類,而後面的()中,則是他的intial,(為何用括號initial,之後會解釋,先記著)。 總地說, ```java String b = new String("456"); ``` 創建一個String對象,Initial為"456",而這個對象,用b指向。 (至於更多關於物件導向的說明,下節繼續) 物件導向 --- 相信大家都有玩過角色扮演類遊戲,並操控一個角色,而角色有一些血量數值,以及很多的技能,在這邊我們就以這種方式比喻給大家,讓大家了解物件和類別的不同。 **物件** 在此,你可以把物件想像成一個角色,這個角色就是一個物件,而這個腳色包含了他的許多參數,還有他的技能(比喻作方法function), 物件(角色)的創建是這樣的 ```java Human myCharacter = new Human(); ``` 這樣就創建了一個角色,一個Human類別的物件,myCharacter, 跟變數宣告相同, Human 表示被宣告物件是哪種類別,myCharacter則是該物件的名稱, 至於Human這個類別怎麼被定義,myCharacter這個對象又有哪些實際操作,我們繼續往下看。 **類別** 延續上面的例子,你可以了解,Human是類別,myCharacter是物件, 至於類別又該怎麼被定義呢? 我們看下面定義類別的一個例子, ```java public class Human { String name; int age; int HP; int MP; void ATK(){ this.MP = this.MP-10; System.out.println("Attackt!!"); } void RUN(){ this.MP = this.MP-10; System.out.println("Run!!"); } } ``` 這樣我就定義了Human這個類別的相關參數及其方法, 其中,name age HP MP,是這個類別的參數,ATK() RUN(),則是參數的方法, 類別被定義後,就能把類別作為一種型態一般,宣告/創建該類別的對象, 即 ```java Human myCharacter = new Human(); ``` 定義了類別,宣告並創建了對象,就能讓對象進行操作,看以下例子, ```java myCharacter.name = "楚垚大帥哥"; myCharacter.age = 19; myCharacter.HP = 100; myCharacter.MP = 999999; myCharacter.ATK(); ``` 上面四行就是對myCharacter對象的參數操作,最下面一行則是使用了myCharacter對象的方法。 思考一下下面的例子,輸出結果是甚麼? ```java public class Test { public static void main(String[] args) { System.out.println("Hello world!"); Human ch1 =new Human(); Human ch2 =new Human(); ch1.name = "878"; ch1.MP = 150; ch2.name = "969"; ch2.MP = 250; ch1.ATK(); ch2.RUN(); System.out.println(ch1.name+"的MP是"+ch1.MP); System.out.println(ch2.name+"的MP是"+ch2.MP); } } class Human { String name; int age; int HP; int MP; void ATK(){ this.MP = this.MP-10; System.out.println("Attackt!!"); } void RUN(){ this.MP = this.MP-10; System.out.println("Run!!"); } } ``` 參考 --- 由於我們的重點放在android app的撰寫,所以java的部分就不再深入了,不然就能開一堂4學分的java程式設計了。如果對於java想更深入的研究,可以參考以下資料, * [類別與物件](https://programming.im.ncnu.edu.tw/J_Chapter2.htm) * [Java 官方入門教學](http://www.codedata.com.tw/book/java-basic/index.php) * [程式範例](https://www.ewdna.com/2011/12/java.html) Demo --- 日期: 未定 檢查內容: 1. 在IntelliJ IDEA中成功執行Hello world程式。 2. 隨機拷問你們(メ ゚皿゚)メ (メ ゚皿゚)メ (メ ゚皿゚)メ ###### tags: `Lab822教材`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    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

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully