`
JasonRight
  • 浏览: 72923 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

difference between & and && for boolean

    博客分类:
  • Java
阅读更多

Core Java chapter3.5.3讲到,

 

&和|应用于boolean运算与&&和||的运算类似,只是不按 “短路”方式计算。

 

Bytecode Outline 插件便可以看到执行的差别

 

Bit And

 

public class TestBitAnd {
    
    public static void main(String[] args) {
        boolean a = false;
        boolean b = true;
        
        boolean bitAnd  = a&b;
        //System.out.println(a +"&" +b+":" + bitAnd);
    }
}

//bytecode
/*
public class corejava_ch3_5_3/TestBitAnd {

  // compiled from: TestBitAnd.java

  // access flags 0x1
  public <init>()V
   L0
    LINENUMBER 21 L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init>()V
    RETURN
   L1
    LOCALVARIABLE this Lcorejava_ch3_5_3/TestBitAnd; L0 L1 0
    MAXSTACK = 1
    MAXLOCALS = 1

  // access flags 0x9
  public static main([Ljava/lang/String;)V
   L0
    LINENUMBER 24 L0
    ICONST_0
    ISTORE 1
   L1
    LINENUMBER 25 L1
    ICONST_1
    ISTORE 2
   L2
    LINENUMBER 27 L2
    ILOAD 1                          
    ILOAD 2                          
    IAND                              //载入两个变量,进行运算
    ISTORE 3
   L3
    LINENUMBER 29 L3
    RETURN
   L4
    LOCALVARIABLE args [Ljava/lang/String; L0 L4 0
    LOCALVARIABLE a Z L1 L4 1
    LOCALVARIABLE b Z L2 L4 2
    LOCALVARIABLE bitAnd Z L3 L4 3
    MAXSTACK = 2
    MAXLOCALS = 4
}*/

 

Logical And

public class TestLogicalAnd {
    
    public static void main(String[] args) {
        boolean a = false;
        boolean b = true;
        
        boolean logicalAnd = a&&b;
        //System.out.println(a +"&&" +b+":" + logicalAnd);
    }
}

//bytecode
/*
 public class corejava_ch3_5_3/TestLogicalAnd {

  // compiled from: TestLogicalAnd.java

  // access flags 0x1
  public <init>()V
   L0
    LINENUMBER 21 L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init>()V
    RETURN
   L1
    LOCALVARIABLE this Lcorejava_ch3_5_3/TestLogicalAnd; L0 L1 0
    MAXSTACK = 1
    MAXLOCALS = 1

  // access flags 0x9
  public static main([Ljava/lang/String;)V
   L0
    LINENUMBER 24 L0
    ICONST_0
    ISTORE 1
   L1
    LINENUMBER 25 L1
    ICONST_1
    ISTORE 2
   L2
    LINENUMBER 27 L2
    ILOAD 1
    IFEQ L3                              //判断是否为0,是则goto L3
    ILOAD 2
    IFEQ L3
    ICONST_1
    GOTO L4
   L3
    ICONST_0
   L4
    ISTORE 3
   L5
    LINENUMBER 29 L5
    RETURN
   L6
    LOCALVARIABLE args [Ljava/lang/String; L0 L6 0
    LOCALVARIABLE a Z L1 L6 1
    LOCALVARIABLE b Z L2 L6 2
    LOCALVARIABLE logicalAnd Z L5 L6 3
    MAXSTACK = 1
    MAXLOCALS = 4
}
 */
 

 

分享到:
评论

相关推荐

    ARM® Compiler v5.06 for µVision® armasm User Guide

    7.28 Difference between operator precedence in assembly language and C 8 VFP Programming 8.1 Architecture support for VFP 8.2 Half-precision extension for VFP 8.3 Fused Multiply-Add extension for VFP ...

    雷达技术知识

    slope, with adjusted R2 values of 0.35, 0.47, and 0.76 for horizontal intervals of 5, 10, and 20m, respectively. Additionally, results show LiDAR provides greater data density where water surfaces are...

    Invent Your Own Computer Games with Python (2008).pdf

    The Difference Between Statements and Expressions x "My Favorite Stuff" x Crazy Answers and Crazy Names for our Favorite Stuff x Capitalizing our Variables x Chapter 2 - Guess the Number x Source ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: With little difference between curve angles at smaller scales the curve was drawn backwards (error in TFlexEllipse.Paint). - ADD: Support of the binary document format. Added the public ...

    JavaScript in 10 Minutes

    Unboxed Values**: Explains the difference between primitive values and their boxed counterparts and the implications for equality checks and other operations. 7. **Silent Failures**: Lists scenarios ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Tabs Function Declarations and Definitions Function Calls Conditionals Loops and Switch Statements Pointer and Reference Expressions Boolean Expressions Return Values Variable and Array ...

    BobBuilder_app

    You can switch to the SortedDictionary in the code at any time if you wish and it makes no difference to the overall code other than you can remove the sorting in the page splits. I also tried an ...

    自动翻滚网页Interdimensional.zip

     * Pixels per difference between tilts  * @type {Number}  */  PPD: 0.8,  /**  * Minimum difference between tilts  * @type {Number}  */  insensitivity: 5,  /**  * ...

    Java邮件开发Fundamentals of the JavaMail API

    framework adds support for typing arbitrary blocks of data and handling it accordingly. This doesn't sound like much, but it is your basic MIME-type support found in many browsers and mail tools ...

    SSD7 选择题。Multiple-Choice

    A difference operation can be applied to tables that (a) are union compatible (b) have the same column names (c) have the same name (d) are the same size Correct answer is (a) Your ...

    东华合创java笔试题

    * What is the difference between "==" and ".equals()" in Java? "=="是比较两个对象的内存地址,而".equals()"是比较两个对象的值。 东华合创Java笔试题涵盖了Java基础知识、语法知识、面向对象编程知识、多线程...

    Guide to Scientific Computing in C++

    5 Blocks, Functions and Reference Variables . . . . . . . 5.1 Blocks . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Functions . . . . . . . . . . . . . . . . . . . . . . . 5.2.1 Simple Functions ...

    用JAVA做两个给定时间的天数差

    long difference = java.time.temporal.ChronoUnit.DAYS.between(date1, date2); System.out.println("天数差: " + difference); } } ``` 在这两种方法中,Java 8的`java.time`包提供的解决方案更为简洁且易于...

    ZendFramework中文文档

    14.5.3. Retrieving Validated Fields and other Reports 14.5.3.1. Querying if the input is valid 14.5.3.2. Getting Invalid, Missing, or Unknown Fields 14.5.3.3. Getting Valid Fields 14.5.4. Using ...

    The way to go

    1.2 Main characteristics, context and reasons for developing a new language....................4 1.2.1 Languages that influenced Go.......................................................................

    [Go语言入门(含源码)] The Way to Go (with source code)

    1.2 Main characteristics, context and reasons for developing a new language....................4 1.2.1 Languages that influenced Go.......................................................................

    StringUtils api 中文 英文 对照

    String between = StringUtils.substringBetween(str, "Hello ", "!"); // "World" ``` ##### 9. Split/Join - **功能**:将字符串分割为子串数组或将子串数组连接成一个字符串。 - **用途**:处理 CSV 文件、...

Global site tag (gtag.js) - Google Analytics