`
KellyLin1115
  • 浏览: 4674 次
  • 性别: Icon_minigender_2
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

Operators

 
阅读更多
Mathematical operators
Integer division truncates, rather than rounds, the result.

If you create a Random object with no arguments, Java uses the current time as a seed for the random number generator, and will thus produce different output for each execution of the program.

Logical operators
Each of the logical operators AND (&&), OR (||) and NOT (!) produces a boolean value of true or false based on the logical relationship of its arguments.
When dealing with logical operators, you run into a phenomenon called “short-circuiting.” This means that the expression will be evaluated only until the truth or falsehood of the entire expression can be unambiguously determined. As a result, the latter parts of a logical expression might not be evaluated.

Literals
Ordinarily, when you insert a literal value into a program, the compiler knows exactly what type to make it. Sometimes, however, the type is ambiguous. When this happens, you must guide the compiler by adding some extra information in the form of characters associated with the literal value.

Hexadecimal (base 16), which works with all the integral data types, is denoted by a leading 0x or 0X followed by 0-9 or a-f either in uppercase or lowercase.
Octal (base is denoted by a leading zero in the number and digits from 0-7.

        int i1 = 0x2f; // Hexadecimal (lowercase)
        int i2 = 0X2F; // Hexadecimal (uppercase)   
        int i3 = 0177; // Octal (leading zero)
        char c = 0xffff; // max char hex value
        byte b = 0x7f; // max byte hex value
        short s = 0x7fff; // max short hex value

print("i1: " + Integer.toBinaryString(i1));
i1: 101111
i2: 101111
i3: 1111111
c: 1111111111111111
b: 1111111
s: 111111111111111

Notice in the preceding code the maximum possible hexadecimal values for char, byte, and short. If you exceed these, the compiler will automatically make the value an int and tell you that you need a narrowing cast for the assignment

Exponential notation
"e" means "10 to the power."
Uppercase and lowercase ‘e’ are the same:
   float expFloat = 1.39e-43f;
   System.out.println(expFloat);
    double expDouble = 47e47d; // ‘d’ is optional
    double expDouble2 = 47e47; // Automatically double
    System.out.println(expDouble);
/* Output:
    1.39E-43
    4.7E48

long n3 = 200;
there’s no ambiguity, so an L after the 200 would be superfluous. However, with float f4 = 1e-43f; // 10 to the power
the compiler normally takes exponential numbers as doubles, so without the trailing f, it will give you an error telling you that you must use a cast to convert double to float.

Bitwise operators
The bitwise operators allow you to manipulate individual bits in an integral primitive data type.
The bitwise AND operator (&) produces a one in the output bit if both input bits are one; otherwise, it produces a zero.
The bitwise OR operator (|) produces a one in the output bit if either input bit is a one and produces a zero only if both input bits are zero.
The bitwise EXCLUSIVE OR, or XOR (^), produces a one in the output bit if one or the other input bit is a one, but not both.
The bitwise NOT (~, also called the ones complement operator) is a unary operator; it takes only one argument. (All other bitwise operators are binary operators.) Bitwise NOT produces the opposite of the input bit—a one if the input bit is zero, a zero if the input bit is one.

Bitwise operators can be combined with the = sign to unite the operation and assignment: &=, |= and ^= are all legitimate. (Since ~ is a unary operator, it cannot be combined with the = sign.)

The boolean type is treated as a one-bit value, so it is somewhat different. You can perform a bitwise AND, OR, and XOR, but you can’t perform a bitwise NOT (presumably to prevent confusion with the logical NOT). For booleans, the bitwise operators have the same effect as the logical operators except that they do not short circuit.

Shift operators
The shift operators also manipulate bits. They can be used solely with primitive, integral types.
The left-shift operator (<<) produces the operand to the left of the operator after it has been shifted to the left by the number of bits specified to the right of the operator (inserting zeroes at the lower-order bits).
The signed right-shift operator (>>) produces the operand to the left of the operator after it has been shifted to the right by the number of bits specified to the right of the operator. The signed right shift >> uses sign extension: If the value is positive, zeroes are inserted at the higher-order bits; if the value is negative, ones are inserted at the higher-order bits.
Unsigned right shift >>>, which uses zero extension: Regardless of the sign, zeroes are inserted at the higher-order bits.

f you shift a char, byte, or short, it will be promoted to int before the shift takes place, and the result will be an int. Only the five low-order bits of the right-hand side will be used. This prevents you from shifting more than the number of bits in an int.
If you’re operating on a long, you’ll get a long result. Only the six low-order bits of the right-hand side will be used, so you can’t shift more than the number of bits in a long.

原码:
   在用二进制原码表示的数中,符号位为0表示正数,符号位为1表示负数,其余各位表示数值部分。如:10000010表示-2,00000010表示2。
反码:    
⑴对于正数,它的反码表示与原码相同
⑵对于负数,则除符号位仍为“1”外,其余各位“1”换成“0”,“0”换成“1”,即得到反码[X]反。例如[11101001]反=10010110。
⑶对于0,它的反码有两种表示:[+0]反=00…0  [-0]反=11…1
补码:
  正数的补码就是该正数本身。
  对于负数:符号位不变,反码加1。

Casting operators
Truncation and rounding
casting from a float or double to an integral value always truncates the number. If instead you want the result to be rounded, use the round( ) methods in java.lang.Math:

Java has no “sizeof”
In C and C++, the sizeof( ) operator tells you the number of bytes allocated for data items. The most compelling reason for sizeof( ) in C and C++ is for portability. Different data types might be different sizes on different machines.
Java does not need a sizeof( ) operator for this purpose, because all the data types are the same size on all machines.

分享到:
评论

相关推荐

    Teradata SQL Functions, Operators, Expressions, and Predicates

    由于提供的文件内容包含了大量版权和商标声明,并没有提供实际的Teradata SQL Functions, Operators, Expressions和Predicates的相关知识内容,因此无法直接从文件内容中生成具体的知识点。不过,我可以根据文件的...

    Wavelets and Operators (1993, Cambridge University Press).pdf

    《小波与算子》(Wavelets and Operators)是一本由Yves Meyer教授撰写的权威著作,该书深入探讨了小波理论及其在数学分析中的应用。本书不仅涵盖了小波的基本理论,还详细介绍了如何利用算子理论来分析小波变换的性质...

    cdo (Climate Data Operators ) 常用命令介绍:(查看文件信息、多文件合并、数据裁剪、数据插.pdf

    **CDO(Climate Data Operators)** 是一个强大的命令行工具,专门用于气候数据的处理和分析。它提供了超过600个操作符,能够执行各种复杂的气候数据分析任务,包括文件信息查看、数据合并、裁剪、插值以及更多。CDO...

    Ordinary Differential Operators

    在数学领域,尤其是泛函分析和偏微分方程中,"Ordinary Differential Operators"(常微分算子)是极其重要的研究对象。它们是定义在函数空间上,通过对函数进行微分操作来生成新函数的线性算子。常微分算子在物理、...

    CDO相关文档(climate data operators)

    内容涉及:cdo(climate data operators)的说明书、指令卡片、图形使用文档、py和rb对cdo的使用以及一个大佬的相关ppt。之前发过一个链接,只有py和rb对cdo的使用,这边这个涵盖了我最近找到的所有参考文档。

    Schrodinger Operators With Application to Quantum Mechanics and Global Geometry (Theoretical and Mathematical Physics) by Hans L. Cycon, Richard G. Froese, Werner Kirsch, Barry Simon (z-lib.org).djvu

    Schrodinger Operators With Application to Quantum Mechanics and Global Geometry (Theoretical and Mathematical Physics) by Hans L. Cycon, Richard G. Froese, Werner Kirsch, Barry Simon (z-lib.org).djvu

    linq_standard_query_operators

    ### Linq Standard Query Operators #### 限制操作符 (Restriction Operators) **Where** - **功能**: Where 操作符遍历源序列,并返回那些使谓词函数返回 true 的元素。 - **示例**: 假设有一个客户集合 `...

    Copy Constructors and Assignment Operators终极解释

    在C++编程语言中,复制构造函数(Copy Constructor)和赋值运算符(Assignment Operator)是两个非常关键的概念,特别是在处理对象的拷贝和赋值时。它们默认由编译器提供,但通常需要根据具体需求进行自定义,以确保正确...

    The .NET Standard Query Operators

    《.NET Standard Query Operators》 本文将深入探讨.NET Standard Query Operators,这是一种强大的API,用于查询任何.NET数组或集合。该API包含在名为System.Query.dll的程序集中的System.Query.Sequence静态类中...

    PyPI 官网下载 | rappiflow_dag_operators-0.3.1.tar.gz

    《PyPI与rappiflow_dag_operators-0.3.1:探索分布式云原生环境中的Python库》 PyPI(Python Package Index)是Python开发者的重要资源库,它为全球的Python开发者提供了一个集中发布和下载Python软件包的平台。在...

    Python库 | discrete_fuzzy_operators-1.9.1.tar.gz

    《Python库discrete_fuzzy_operators详解》 在信息技术领域,Python作为一种强大的开发语言,以其简洁易读的语法和丰富的库资源深受开发者喜爱。本文将深入探讨Python库`discrete_fuzzy_operators-1.9.1`,这是一个...

    题一:Data Types, Operators and Expressions1

    在编程语言中,数据类型(Data Types)、运算符(Operators)和表达式(Expressions)是构建程序的基础元素。本文将详细探讨这些概念,特别是在C语言中的应用。 首先,变量名(Variable Names)是编程中用来存储值...

    linear operators part 1

    Dunford,Schwartz写的线性算子。

    Python库 | rappiflow_dag_operators-0.2.4-py3-none-any.whl

    《Python库rappiflow_dag_operators-0.2.4-py3-none-any.whl详解》 在Python的世界中,库是开发者的重要工具,它们提供了丰富的功能,简化了编程工作。今天我们要讨论的是一个名为`rappiflow_dag_operators`的...

    History of Banach Spaces and Linear Operators

    ### 关于《Banach空间与线性算子的历史》的知识点概述 #### 一、Banach空间的概念与发展 - **1.1 完备赋范线性空间**:Banach空间是数学分析中的一个重要概念,它是一种完备的赋范线性空间。这意味着在Banach空间...

    standard_query_operators

    .NET Standard Query Operators是LINQ(Language Integrated Query,语言集成查询)的一部分,它是.NET框架中引入的一个强大特性,允许开发者以一种声明式的方式处理各种数据源,包括集合、数据库、XML等。...

    C程序设计英文课件:CHAPTE 2 Types,Operators and Expressions.ppt

    在C语言中,第二章“Types, Operators, and Expressions”涵盖了编程的基础概念,包括变量命名、数据类型、常量、声明与表达式、运算符等多个方面。让我们逐一深入探讨这些知识点。 首先,变量(Variable)是程序中...

    PyPI 官网下载 | custom-operators-1.0.tar.gz

    《PyPI官网下载:custom-operators-1.0.tar.gz——深入解析Python自定义操作符库》 在Python编程世界中,PyPI(Python Package Index)是开发者们获取和分享Python软件包的主要平台。它提供了丰富的第三方库,极大...

    用Operators管理多集群Kubernetes.docx

    标题中的"用Operators管理多集群Kubernetes"指的是在Kubernetes环境中,使用Operator技术来有效地管理和自动化多集群的运维过程。Operator是一种高级的自动化方法,它扩展了Kubernetes的原生能力,使得复杂应用和...

    mongo中模糊查询使用和QueryOperators宣贯.pdf

    在MongoDB中,模糊查询和QueryOperators是两个关键概念,用于实现更复杂的查询操作。MongoDB是一个基于分布式文件存储的NoSQL数据库系统,它提供了丰富的查询语言,支持多种数据模型,包括文档、图形和键值对。本文...

Global site tag (gtag.js) - Google Analytics