//1. Demonstrate the concept of operators in java.
class BoolLogic{
public static void main(String args[]){
boolean a=true;
boolean b=false;
boolean c= a|b;
boolean d= a&b;
boolean e= a^b;
boolean f= (!a &b)|(a& !b);
boolean g= !a;
System.out.println("a = "+a);
System.out.println("b = "+b);
System.out.println("a|b = "+c);
System.out.println("a&b = "+d);
System.out.println("a^b = "+e);
System.out.println("!a &b|a& !b = "+f);
System.out.println("!a = "+g);
}
//2)
public class While {
public static void main(String[] args) {
int n=10;
while(n>0){
System.out.println("tick"+n);
n--;
}
3)
class Dowhile
public static void main(String[] args)
int i=1;
do
System.out.println(i);
i++;
while(i<=10);
}
//4)
class For
public static void main(String[] args)
for (int i = 0; i < 5; i++)
System.out.println(i);
}
//5)
class If {
public static void main(String[] args)
if (20 > 18)
System.out.println("20 is greater than 18");
}
//6)
class Ifelse
public static void main(String[] args)
int time = 20;
if (time < 18)
System.out.println("Good day.");
else
System.out.println("Good evening.");
}
//7) class Switch
public static void main(String[] args)
int day = 4;
switch (day)
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
case 7:
System.out.println("Sunday");
break;
}
class Multidimensional{
public static void main(String args[]){
int twoD[][]=new int[4][5];
int i,j,k=0;
for(i=0;i<4;i++)
for(j=0;j<5;j++){
twoD[i][j]=k;
k++;
for(i=0;i<4;i++){
for(j=0;j<5;j++)
System.out.println(twoD[i][j]+"");
System.out.println();
}
class Stringordering{
static String name[]={"Madras","Delhi","Ahmedabad","Calcutta","Bombay"};
public static void main(String args[])
int size=name.length;
String temp=null;
for(int i=0;i<size;i++){
for(int j=i+1;j<size;j++){
if(name[j].compareTo(name[i])<0)
temp=name[i];
name[i]=name[j];
name[j]=temp;
for(int i=0;i<size;i++){
System.out.println(name[i]);
}
import java.util.Vector;
class LanguageVector {
public static void main(String[] args) {
Vector<String> mammals= new Vector<>();
// Using the add() method
mammals.add("Dog");
mammals.add("Horse");
// Using index number
mammals.add(2, "Cat");
System.out.println("Vector:" + mammals);
// Using addAll()
Vector<String> animals = new Vector<>();
animals.add("Crocodile");
animals.addAll(mammals);
System.out.println("New Vector: " + animals);
}
class Enumdemo{
enum Days{
Sun,Mon,Tue,Wen,Thu,Fri,Sat}
public static void main(String args[])
for(Days d: Days.values())
System.out.println("Day is ="+d);
}
class City{
public String name;
public long population;
public void display() {
System.out.println("City name: " +name);
System.out.println("Population: " +population);
class Cities{
public static void main(String args[]){
City metro1,metro2;
metro1 = new City();
metro2 = new City();
metro1.name ="Delhi";
metro1.population = 10000000;
System.out.println("Details of metro city 1:");
metro1.display();
metro2.name ="Bangalore";
metro2.population = 5000000;
System.out.println("Details of metro city 2:");
metro2.display();
}
class Enumdemo{
enum Days{
Sun,Mon,Tue,Wen,Thu,Fri,Sat}
public static void main(String args[])
for(Days d: Days.values())
System.out.println("Day is ="+d);
}
class Rectangle{
int length,width;
Rectangle(){
length=0;
width=0;
Rectangle(int x, int y){
length=x;
width=y;
int rectArea()
return(length*width);
class RectangleArea{
public static void main(String args[]){
Rectangle rect1=new Rectangle(15,10);
Rectangle rect2=new Rectangle();
int area1=rect1.rectArea();
int area2=rect2.rectArea();
System.out.println("Area1="+area1);
System.out.println("Area2="+area2);
}
class Room{
int length;
int breadth;
void setDim(int x, int y)
length=x;
breadth=y;
void setDim(int x)
length=breadth=x;
int area()
return(length*breadth);
class Methodoverload{
public static void main(String args[]){
Room r1= new Room();
int ar;
r1.setDim(10,20);
ar=r1.area();
System.out.println("Area of object1="+ar);
r1.setDim(30);
ar=r1.area();
System.out.println("Area of object1="+ar);
}
class Bank{
int getRateOfInterest(){return 0;}
class SBI extends Bank{
int getRateOfInterest(){return 8;}
class ICICI extends Bank{
int getRateOfInterest(){return 7;}
class AXIS extends Bank{
int getRateOfInterest(){return 9;}
class Test2{
public static void main(String args[]){
SBI s=new SBI();
ICICI i=new ICICI();
AXIS a=new AXIS();
System.out.println("SBI Rate of Interest: "+s.getRateOfInterest());
System.out.println("ICICI Rate of Interest: "+i.getRateOfInterest());
System.out.println("AXIS Rate of Interest: "+a.getRateOfInterest());
}
class Mathoperation
static int d;
static float mul(float x,float y)
return (x*y);
static float divide(float x, float y)
return (x/y);
class MathApplication
public static void main(String args[])
Mathoperation mo= new Mathoperation();
Mathoperation mo1= new Mathoperation();
Mathoperation mo2= new Mathoperation();
float c= mo.mul(4.0f,6.0f);
System.out.println("c="+c);
mo.d=10;
float a= Mathoperation.mul(4.0f,5.0f);
float b= Mathoperation.divide(3.0f,2.0f);
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("d=" +mo.d);
System.out.println("d=" +Mathoperation.d);
Mathoperation.d=20;
System.out.println("First object d="+mo.d);
System.out.println("Second object d="+mo1.d);
System.out.println("Third object d="+mo2.d);
System.out.println("accessed using class name d="+Mathoperation.d);
}
class Room
int length;
int breadth;
Room(int x, int y)
length=x;
breadth=y;
int area()
return (length*breadth);
class BedRoom extends Room
int height;
BedRoom(int x, int y, int z)
super(x,y);
height = z;
int volume()
return(length*breadth*height);
class InherTest1
public static void main(String args[])
{
BedRoom room1=new BedRoom(14,12,10);
Room r2= new Room(20,30);
int area1=room1.area();
int volume1=room1.volume();
int a=r2.area();
System.out.println("Area1="+area1);
System.out.println("Area="+a);
System.out.println("Volume1="+volume1);
System.out.println("Length of room1="+room1.length);
}
interface AnimalEat {
void eat();
interface AnimalTravel {
void travel();
class Animal implements AnimalEat, AnimalTravel {
public void eat() {
System.out.println("Animal is eating");
public void travel() {
System.out.println("Animal is travelling");
class Interface {
public static void main(String args[]) {
Animal a = new Animal();
a.eat();
a.travel();