BLACKMASK

OOP WITH JAVA CHAPTER 2 (NEW 2018)

OBJECT ORIENTED PROGRAMMING WITH JAVA

CHAPTER 2


Primitive data type
\U0000  \UFFFF
Char
Char C=”A”
Escape sequence
“My School”
“\”
Char table =”\t”;
Nul=”1000”;
Slash=”\\”;
Boolean
Boolean data type has two possible values either
True or false
Ø By default it is false.
                 Boolean flag =true;
                 System.out.println(flag);

Short
Short data type can have value from [32768,32767];
By default it is zero
Short temp = 100;
System.out.println(tem);

Integer
Int data type can have value from -2^31 to [2^31-1]
Long
Long data type can have value from
 [-2^63,2^63-1]
Double
Double data type has double precision 64-bit floating point.
default value =0.0
Example
Double number =-15.09;
System.out.println(number);
Float
Flot data type is single precision
32 bit data type.
Float num =-15.9
Output =-15.9.
Type casting(conversion)
Int i=13
X byte=I;//not allowed in java
Byte b=(byte);
Primitive data type
Java support eight basic type known as primitive data types. the primitive types includes a Boolean type,a character type ,four integer types ,and two floating point types differ in the number of bits that represent them and therefore in the range of numbers they can represent.
Variable and type of variable
Named memory location that can change it self value during the execution of program.
 int a=65;
Types
1.local variable
2.Instant variable
3.Static variable
4.Constant variable
Local variable‘‘A local variable which is declared inside the method is called local variable’’ .local variable are only visible within the relevant method, constructor, or block.
There is no default value for local variables.
Constant variable
Constant variable declares with const keyword and can be used with primitive data types. Constant are set at compile time it self and assigned for value type only.
Static variable
Static variable is a property of a class rather then the instance of class. If can be assigned for refrence types and set of run time.
1.    It is a variable which belongs to the class not to the instance (Object).
2.    Static variable are initialized only once at the start of execution.
3.    Single copy to be shared by all instances.
4.    Static variable can be accesed by the name.
Syntax
<Class Name><Variable Name>
Instance variable:.
A variable which is declared insight the class but outside the method.
 public static void main(string[]args){
}
Public static void student(){method
Int rollno=0;
String name=0;
Public void main add new () {
}

 Operators
   1)  Assignment operator.
   2)  Arithmetic operator.
   3) Logical operator.
   4) Relational operator.
   5) Bitwise operator.
        Unary:.
Int i-5;
 i ++;
           
    operand
   i --;
-i;

Binary:.
 a=3;
b=4;
c=a + b;
      
Ternary:.
Ternary operator is short hand of
if-then-else.
var=Expression?Expression1:Expression2;
 Program:.
     int dayofFeb=28;
     String result;
     result=(dayofFeb==29)?"leap year":"Not      leap year";
     System.out.println(result);
Relational operator
A relational operators compairs two values and determines the relation ship between them.
a=5,b=3          (a==b)//0
==checks the value of two operands are equal or not.if yes the condition become true.
|=checks if value of two operands are equal or not.and return true if values are unequal.
a=5,b=3  
a>b if value of left operand is greater then right operand it return 1.
a<b check if the value of left operand is greater is less then value of right operand it returns true.
Program
package javapractice2;
public class Javapractice2 {
 public static void main(String[] args) {
   int a=10;
   int b=5;
   System.out.println("a+b="+a+b);
   System.out.println("a*b"+a*b);
   System.out.println("a%b"+a%b);
   System.out.println("a/b"+a/b);
    }
    }
Output
run:
a+b=105
a*b50
a%b0
a/b2
BUILD SUCCESSFUL (total time: 0 seconds)

Assignment operator
Assignment operator assigns value from right side to left side
operand.
 a=5*2+2;
   a=s;
   b=3;
+=     a+=b;//a=a+b
Arithmetic operator
Arithmetic operators are used in the same way that they are used in algebra.
+;a+b (addition)
-;a-b(subtraction)
*;a*b(multiply)
/;a/b(divide left side operand to right side)
%;a%b(return remainder after division)
Logical operator.
Logical operators are known as Boolean operators.logical operator on Boolean values and produces a Boolean as a result.


Bitwise operator
1.      AND( &)
2.      OR (|)
3.      NOT
Bitwise and&:.
Bitwise and is a binary operator that compares corresponding bits of two operands.
Bitwise or|
Bitwise operator perform bit by bit operations or gives 1 if either bit is 1
Bitwise not
It converts the bit pattern .it is a unary operator.
Bitwise
Rightshift>>
Left shift<<
Rightshift
Righty shift operator shift a pattern of bits toward right by certain number of specified bits.
A=000111100//00
R=a>>1;
R=30
Left shift(<<)
Left shifs a pattern of bits towards left by specific number of times.
Int x=0000100 //4
R= x<<3;00100000 //
Unary
Increment operator
Increment operator increases the value of operand by 1.
Int f=1;
     f++;
post increment                       pre increment
x++                                                      ++x
Decrement operator
It decreases the value of operand by 1.
Int y=3;                                                                                                                                                                                                                                                                         
y--;//y=3
post decrement                                pre decrement
y--                                                                   --y



Auto boxing
Auto boxing is the automatic conversion that a java compiler makes between primitive data types and their corresponding wrapper classes.
Primitive                                       Wrapper
  Int                                                   integer             
Un boxing
The automatic conversion of wrapper class object into relevant primitive data type is called un boxing.
Integer i=new integer (30);
Int j=I;
Note(you can take notes of OOP WITH JAVA from "swedish89.wordpress.com")