Java Sessions :
What is Java
Java is a object oriented programming language.
Oops Concept:
1>Class
2>Object
3>Polymorphism
4>Inheritance
5>Abstraction
6>Encapsulation
Features of Java
1> Platform independent: Java is a plalform independent it does not depend on any
operating system.
2> Case Sensitive:
test
TEST
Variable :
Variable is a storing unit or a container which is used to hold value.
Ways to write a variable :
1>Data-type Variable_Name = Value ; // Declaration + Assignment
2>Data_type Variable_Name ; // Declaration
Variable_Name = Value ; // Assignment
3> Data_type Variable_Name1 , Variable_Name2 , Variable_Name3; // Declaration
Variable_Name1 = Value; // Assignment
Variable_Name2 = Value;
Variable_Name3= Value;
4> Data_Type Variable_Name1 = Value;
Data_Type Variable_Name2 = Value;
Data_Type Variable_Name3 = Value;
5> Data_Type Variable_Name1 = 500 , Variable_Name2 = 700 , Variable_Name3 =
900;
// Declaration + Assignment
Data - Type :
Data - Type basically tell the type the value a variable going to hold in a program.
1>Premitive Data - Type
1>byte , short , int , long ( to store integer value )
2> float , double ( to store decimal value )
3>b
4>char ( to store character value )
2>Non Premitive Data - Type
1>String
2>ArrayList
3>Hasgmap
To Store integer value there are 4 different data-type
byte —- > -128 to 127
short ——> -32,768 to 32,767
int ———-> -2,147,483,648 to 2,147,483,647
long ——-> -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
To Store decimal value there are 2 different data-type
float : Store decimal value upto 7 decimal digit
double : Store decimal value upto 15 decimal digit
Operators :
Operator are the symbol in java which are used to perform specific operation.
Int a = 20;
Int b = 30;
[Link](a+b);
Categories in Operator:
1>Arithematic operator : + , - , * , / , %
2>Relational Operator : > , < , >= , <= , !=
3>Logical Operator : && (And Operator ) , || ( OR Operator )
And Operator
Condition1 Condition2 Output
0 1 0
0 0 0
1 0 0
1 1 1
OR Operator
Condition1 Condition2 Output
1 0 1
0 1 1
0 0 0
1 1 1
4>Increment/Decrement Operator : ++(increment) , - - (decrement)
5>Assignment Operator : = ( Assignment operator) , += ( Add and Assign) , -= ( Sub-
tract and assign) , *= ( Multiply and assign ) , /= ( Divide and assign ), %= ( Modulus
and assign )
1>IF - Else Statement
2>else If ladder
3> Nested if else
Syntax for If-Else :
IF(Condition)
{
// Statement 1 :
// Statement 2;
// Statement 3;
Else // Optional
// Statement 1;
Q1> Write a program to check any number is even or odd.
number%2==0; Even
Q2 > Write a program to check a number is positive , negative or zero
Num >0 ; // Positive
Num <0 // Negative
Num == 0 // Zero
Syntax for else if ladder
if( Condition1 )
{
}
Else if ( Condition 2)
Else if (Condition3)
Else if ( Condition 4)
Else // Optional
Q3> Write a program to check the greatest of three number.
Int a , b , c;
A = 100;
B = 200;
C = 140;
Logic :
A > B && A > C ; A is greatest
B > A && B > C ; B is greatest
C > A && C > B ; C is greatest