java修飾符和基本操作符

來源:互聯網
上載者:User

標籤:object   三元運算   按位元運算   static   邏輯   技術分享   follow   三元   關係運算   

Java修飾符可以分為兩種

  • 可存取修飾詞
  • 不可存取修飾詞

使用修飾符,可以使用在class,方法,變數的定義

可存取修飾詞

  • 包可見,預設,不需要修飾符
  • 只能被類可見(private)
  • 都可見(public)
  • 只可以被當前包和所有類可見的(protected)

不可存取控制符

  • 用於建立類方法和變數的靜態修飾符static
  • 用於完成類,方法,變數實現的最終修飾符final
  • 用於建立抽象類別和方法的抽象修飾符abstract
  • synchronized和volatile修飾符,用於線程。

Java操作符

  • Arithmetic Operators(算術運算子)
  • Relational Operators(關係運算子)
  • Bitwise Operators(按位元運算符)
  • Logical Operators(邏輯運算子)
  • Assignment Operators(分配運算子)
  • Misc Operators(其他運算子)
算術運算子- +- -- *- /- % (模)- ++- --
關係運算子- == - !=- >- <- <=- >=

按位元運算符

a = 0011 1100b = 0000 1101a&b = 0000 1100(與,都為1為true)a|b = 0011 1101(或,有1就是true)a^b = 0011 0001(異或,不同就是true)~a  = 1100 0011(取反)a<<2 左移擴大 1111 0000a>>2 右移縮小0000 1111

邏輯運算子

- A && B 都真為真- A||B有真為真- !A 取反

分配運算子

- =- +=- -=- *=- /=- %=- >>=- &=- ^=- |=

三元運算子

- varible x =(expression)?value if true:value if false

instanceof

( Object reference variable ) instanceof  (class/interface type)
public class Test {   public static void main(String args[]) {      String name = "James";      // following will return true since name is type of String      boolean result = name instanceof String;      System.out.println( result );   }}

優先順序表

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.