Operators:
it is nothing but a symbol
used to perform some operations on operands
Ex: a+b
"a,b" -is operands," +" is operator (doing addition operation)
List of operators:
Arithmetic Operators (+ - * / % ++ --)
- + Addition (x+y)
- - Subtraction (x-y)
- * Multiplication (x*y)
- / Division (x/y)
- % Modulus (x%y)
- ++ Increment (++x)
- -- Decrement (--x)
Relational Operators (<> <= >= == !=)
- == Equal to (x==y)
- != Not equal (x!=y)
- < Less than (x<y)
- > Greater than (x>y)
- <= Less than or equal to(x<=y)
- >= Greater than or equal to (x>=y)
Logical operators (&& || ! )
- && Logical and (x<5 && x<10)
- || Logical or (x<5 || x<4)
- ! Logical not ( !(x<5 && x<10) )
Assignment Operator (= += -= *= /= %=)
- = (x=5) this is same as (x=5)
- += (x+=5) this is same as (x=x+5)
- -= (x-=5) this is same as (x=x-5)
- *= (x*=5) this is same as (x=x*5)
- /= (x/=5) this is same as (x=x/5)
- %= (x%=5) this is same as (x=x%5)
Bitwise operators (& | ^ ~ << >>)
- & Bitwise AND
- | Bitwise OR
- ^ Bitwise exclusive OR
- ~ Bitwise Compliment
- >> Shift right
- << shift left
Ternary Operator:
ternary operator are run one code when the condition is true and another code when the condition is false.
int time=20;
String result=(time>18) ? "Good day.": "Good Evening."
System.out.println(result);
Output:
Good Evening
Variables:
- Instance variables: which are declared inside the class outside the method. They are used to store unique data for each instance of a class.
- Local variables: which are declared inside the method.
Constructor:
- It's a special method.
- No return types.
- Should be sane name as class name.
- it will call at the time of object creation.
- Used to initialize instance variable.
- if you don't write any constructor compiler will add one default constructor, if you write constructor compiler will not add default constructor.
Constructor Types
- No parameter/ Default Constructor
- Parameterized Constructor
Comments
Post a Comment