Mudancas Recentes - Buscar:

Principal

 Objetivos  
 Ementa  
 Livros 

OAC

LOAC

Professores:

  JOSEANA
  ELMAR

CONTATO

CRÉDITOS

editar



Summary of Operators in Java

copied from https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

The following quick reference summarizes the operators supported by the Java programming language.

Arithmetic Operators

+ Additive operator (also used for String concatenation)
- Subtraction operator
* Multiplication operator
/ Division operator
% Remainder operator

Unary Operators

+ Unary plus operator; indicates positive value (numbers are positive without this, however)
- Unary minus operator; negates an expression
! Logical compliment operator; inverts the value of a boolean

Equality and Relational Operators

== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to

Conditional Operators

&& Conditional-AND
|| Conditional-OR
?: Ternary (shorthand for if-then-else statement)

Bitwise and Bit Shift Operators

~ Unary bitwise complement
<< Signed left shift [ não existe diferênça entre "signed left shift" e "unsigned left shift" ]
>> Signed right shift [ em SystemVerilog este símbolo é unsigned right shift ]
>>> Unsigned right shift [ em SystemVerilog este símbolo é signed right shift ]
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise inclusive OR

Bitwise and Bit Shift Operators

The Java programming language provides operators that perform bitwise and bit shift operations on integral types. The unary bitwise complement operator "~" inverts a bit pattern; it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0". For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111". The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension. The bitwise & operator performs a bitwise AND operation. The bitwise ^ operator performs a bitwise exclusive OR operation. The bitwise | operator performs a bitwise inclusive OR operation. The following program, BitDemo, uses the bitwise AND operator to print the number "2" to standard output.

 class BitDemo {      
    public static void main(String[] args) {
           int bitmask = 0x000F;           
           int val = 0x2222;           
           System.out.println(val & bitmask);  // prints "2"      
    } 
 } 
© 2008 Profs. Elmar Melcher e Joseana Fechine. Monitores: Sergio Espinola e Fabricio Lelis - DSC/UFCG
Modificada em April 28, 2020, at 11:02 AM