Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

 

 

 

Chapter II: Operators & Assignments

  • 2.1) Types of operators
  • 2.2) Operator precedence
  • 2.3) Bitwise operations on integers
  • 2.4) "+ " operator on Strings
  • 2.5) Comparision operator (==) applied on objects/ equals() method
  • 2.6)Primitives passed to methods
  • 1.8)java keywords
  • 1.9)identifiers
  • 1.10)initialising
  • 1.11)interface declaration & implementation

 

2.1 Types Of Operators

*Mathematical operators (++ -- +- (type) * / % + -)

*Relational operators (< > <= >= == != (+=) )

*Logical operators (!)

*Bitwise operators

*Shift operators (>>,>>>,<<)

*Terminary operators

*Almost all operators work only with primitives .

* "=",'= =' &'!=' work with all objects .

* String class supports '+'&'+=' .

 

 

2.2) Operator precedence

 

2.3) Bitwise operations on integers

2.4) "+ " operator on Strings

2.5) Comparision operator (==) applied on objects/ equals() method

  • '==' determines whether the variables reference the same object in memory rather than comparing them.
  • If you construct two strings with same literal without using new keyword then

a="Hello"

b="Hello"

(a= =b) // this is true

  • '==' operator returns true only if references are to same object . These operators disregard the contents of objects .
  • equals() method tests for equality of content .

Ex : Long a1= new Long (100);

Long a2= new Long (100);

Long a3=a1 // a3,a1 refer to same object now.

boolean flag=(a1==a2)// false.

flag=(a1==a3) // true.

flag= a1.equals(a2)//true

  • equals() method signature is

public boolean equals(Object obj)

  • equals returns true only if obj is of the same type and a comparision of the contents are identical
  • however Boolean and String classes overide this with more meaning.equals() return true in Boolean if the two objects contain the same Boolean value and in String if the Strings contain the same sequence of characters.

 

2.7)Primitives passedethods to m