Java Programms

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 55

BASIC JAVA PROGRAMS

TO USE PRINTING STATEMENT IN MAIN METHOD

package details;

public class SelfIntroduction {

public static void main (String[] args) {

System.out.println("Name:Pooja Bibave");

System.out.println("Address:Sangamner,Ahamadnagar");

System.out.println("Education:B.E.Civil Engineering");

System.out.println("Mobile No:8208103662");

System.out.println("Hobbies:Watching TV,Playing Mobile Games,Listening


Songs");
}
}

OUTPUT:

Name:Pooja Bibave
Address:Sangamner,Ahamadnagar
Education:B.E.Civil Engineering
Mobile No:8208103662
Hobbies:Watching TV,Playing Mobile Games,Listening Songs

ONE LINE PROGRAMME (Addition Statements In One Line


Using + )

package additionStatements;

public class Introduction_One_Line {

public static void main(String[]args) {

System.out.println("Name:Pooja Bibave" + " Address:Sangamner,Ahamadnagar" + "


Education:B.E.Civil Engineering" + " Mobile No:8208103662" + "
Hobbies:Watching TV,Playing Mobile Games,Listening Songs");

}
OUTPUT:
Name:Pooja Bibave Address:Sangamner,Ahamadnagar Education:B.E.Civil
Engineering Mobile No:8208103662 Hobbies:Watching TV,Playing Mobile
Games,Listening Songs
ONE LINE PROGRAMME (Addition In Different Lines Using “\n”)
package additionStatements;

public class Different_Lines_Statement_Output {

public static void main(String[]args) {

System.out.println(" Name:Bibave Pooja" + "\n" + "


Address:Sangamner,Ahamadnagar" + "\n" + " Education:B.E.Civil Engineering" +
"\n" + " Mobile No:8208103662");

OUTPUT:

Name:Bibave Pooja
Address:Sangamner,Ahamadnagar
Education:B.E.Civil Engineering
Mobile No:8208103662

PRINTING TRICKS:(Using “println”)

package additionStatements;

public class Printing_Tricks {

public static void main(String[] args) {

System.out.print("AD");
System.out.println("PC");
System.out.print("BD");
System.out.print("PI");
System.out.print("MI");
System.out.println("NAHI");
System.out.println("TUCH");
System.out.print("PI");

OUTPUT:

ADPC
BDPIMINAHI
TUCH
PI
STATIC METHOD

package program;

public class Regular_Method {

public static void cat() { //Static Method

System.out.println("Hellow Word"); //Printing statement


}
public static void main(String[] args) { //Main Method

cat(); //Method Call


}

OUTPUT

Hellow Word

NON-STATIC MOTHOD

package program;

public class Object_Creation {

public void demo() { //Non-Static Method

System.out.println("Velocity Is Best Class"); //Printing Statement


}

public static void main(String[] args) { //Main Method

Object_Creation A = new Object_Creation(); //Object Create


A.demo(); //Method Call
}

OUTPUT

Velocity Is Best Class


TWO NON STATIC METHOD TOGETHER :

package program;

public class Boss {

public void demo() { //Non-Static Method

System.out.println("Hey Pooja"); } //Printing Statement

public void demo1() { //Non-Static

System.out.println("Velocity class"); }

public static void main(String[] args) { //Main Method

Boss B = new Boss(); //Object Creation

B.demo(); //Method Call


B.demo1(); //Method Call

OUTPUT

Hey Pooja
Velocity class

VARIABLES :

LOCAL VARIABLE :

package types;

public class Local_Instance {


int y = 2;
int z = 4;

public static void customer1() { //local variable


int a = 10;
int b = 20;

System.out.println(a);
System.out.println(b);
System.out.println(a+b);
System.out.println(a*b);

}
public static void main(String[] args) {

customer1(); //method call


Local_Instance mau = new Local_Instance();
mau.customer2(); //method call
}

public void customer2() { //instance\global


variable
System.out.println("customer2");

System.out.println(y);
System.out.println(z);
}

OUTPUT :

10
20
30
200
customer2
2
4

INSTANCE VARIABLE :

package types;

public class Population2022 {

String a = "Uttar Pradesh"; //States //Instance


Variable
String b = "Maharashtra";
String c = "Bihar";
String d = "West Bengal";

int e = 233200000; //2022 Estimates,Population


int f = 125400000;
int g = 124900000;
int h = 98600000;

byte i = 1; //Rank
byte j = 2;
byte k = 3;
byte l = 4;

public void ranking() { //Non-Static Method

System.out.println(" Statewise Popupation


2022");
System.out.println("
");
System.out.println(" RANK" + " STATES" + "
2022 ESTIMATES");
System.out.println("--------------------------------------
-----------------------");
System.out.println(" " + i +" " + a +"
"+ e);
System.out.println(" " + j +" " + b +"
"+ f);
System.out.println(" " + k +" " + c +"
"+ g);
System.out.println(" " + l +" " + d +"
"+ h);
}
public static void main(String[] args) {

Population2022 P = new Population2022();


P.ranking();

}
}

OUTPUT :

Statewise Popupation 2022

RANK STATES 2022 ESTIMATES


-------------------------------------------------------------
1 Uttar Pradesh 233200000
2 Maharashtra 125400000
3 Bihar 124900000
4 West Bengal 98600000
STATIC VARIABLE :

package types;

public class Static {

static String a = "My name is pooja";


static int d = 67;

public static void demo() {

System.out.println(a);
System.out.println(d);
System.out.println(a + "\n" + d);
}

public static void main(String[] args) {

demo(); //method call

OUTPUT :

My name is pooja
67
My name is pooja
67

DATATYPES:

PRIMITIVE DATATYPE :

package primitive_nonPrimitiveExample;

public class Datatype {

public static void main(String[] args) {


boolean c = 20>19;
System.out.println(c);

byte d =127;
System.out.println(d);

short e = 32767;
System.out.println(e);

int f = 2147483647;
System.out.println(f);

long g = 21474836488996L;
System.out.println(g);

float h = 34.99f;
System.out.println(h);

double i = 39.499999d;
System.out.println(i);

char k = '9';
System.out.println(k);
}

OUTPUT:

true
127
32767
2147483647
21474836488996
34.99
39.499999
9

NON-PRIMITIVE DATATYPE:

package primitive_nonPrimitiveExample;

public class ColdDrinks {

String a = "Sprite";
String b = "Pepsi";
String c = "Coca-Cola";
String d = "Fanta";
String e = "Maaza";
String f = "Mirinda";

public void product() {


System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(e);
System.out.println(f);
}
public void productprice() {
System.out.println(" ");
System.out.println(a + " # rs 62/-");
System.out.println(b + " # rs 58/-");
System.out.println(c + " # rs 63/-");
System.out.println(d + " # rs 30/-");
System.out.println(e + " # rs 20/-");
System.out.println(f + " # rs 62/-");
}
public static void main(String[] args) {
ColdDrinks c = new ColdDrinks();
c.product();
c.productprice();
}
}

OUTPUT:

Sprite
Pepsi
Coca-Cola
Maaza
Mirinda

Sprite # rs 62/-
Pepsi # rs 58/-
Coca-Cola # rs 63/-
Fanta # rs 30/-
Maaza # rs 20/-
Mirinda # rs 62/-

CONSTRUCTOR:
DEFAULT CONSRUCTOR:

USER-DEFINED CONSTRUCTOR:

package types;

public class Example_2 {

//1.Declaration

String name; //Instance Variable


int age;
long mob ;

//2.Initialization

public Example_2(String name1 , int age1 , long mob1) {

name = name1;
age = age1;
mob = mob1;
}
//Usage
public void details() {

System.out.println("your name is = " + name + "\n"


+ "age is = " + age + "mobile no = " + mob );
}
public static void main(String[] args) {
Example_2 B = new Example_2("pooja bibave", 23,
7040157805l);
B.details();
}

OUTPUT:

your name is = pooja bibave


age is = 23mobile no = 7040157805

METHOD CALLING:
package mCWSC_With_Argument;

public class MCWSCWithArgument {

public void dell() { //Non


Static Method
System.out.println("Dell is best compony of laptop");
}

public void dell(String animal) {


System.out.println("Cat is lovely pet animal");
}

public void dell(String hobby, String like) {


System.out.println("Watching TV is my fev hobby");
}

public static void dell(long salary) {


//Static Method
System.out.println("I wamt to the salary is
55000/month");
}

public static void apple(int pkg, String mekup) {


//static method with different method name
System.out.println("Pooja want to do mekup for
wedding");
}

public static void main(String[] args) {


MCWSCWithArgument v = new MCWSCWithArgument();
v.dell();
v.dell("manu"); //non static method with arguments
v.dell("TV Serials", "coocking");
dell(55000l); //Static method call
apple(40000,"fecial");

OUTPUT:

Dell is best compony of laptop


Cat is lovely pet animal
Watching TV is my fev hobby
I wamt to the salary is 55000/month
Pooja want to do mekup for wedding

THIS KEYWORD:

package detail;

public class This_details {

int a = 20;
int b = 30;

public void que() { //Non Static Method


int a = 4;
int b = 6;

System.out.println(a);
System.out.println(b);
System.out.println(this.a);
System.out.println(this.b);

}
public static void main(String[] args) {
This_details c = new This_details();
c.que();
}
}

OUTPUT:

4
6
20
30

OPERATORS:

ARITHMATIC OPERATORS:

package operators1;

public class Arithmetic_Operator {

public static void main(String[] args) {


int a = 30;
int b = 20;

System.out.println(a+b); //50
System.out.println(a-b); //10
System.out.println(a*b); //600
System.out.println(a/b); //1 Division(/)- gives us the
value of quotient
System.out.println(a%b); //10 Modulus(%) - gives us the
value of reminder

OUTPUT:

50
10
600
1
10

BITWISE AND LOGICAL AND OPERATORS:

package operators1;

public class Bitwise_And_LogicalAndOperator {

public static void main(String[] args) {

//Logical = &&

int p = 150;
int q = 350;
int r = 450;
int s = 950;

System.out.println(r>q && s>p); //True


System.out.println(q<s && p>q); //false
System.out.println(r<q && p>r); //false
System.out.println(q==s && p>s); //false

//Bitwise = &
System.out.println(r>q & s>p); //true
System.out.println(q<s & p>q); //false
System.out.println(r<q & p>r); //false
System.out.println(q==s & p>s); //false
}

}
OUTPUT:

true
false
false
false
true
false
false
false

BITWISE AND LOGICAL OR:

package operators1;

public class BitwiseOr_LogicalOr_Operator {

public static void main(String[] args) {

//bitwise OR = |
//Logical OR = ||
int p = 150;
int q = 350;
int r = 450;
int s = 950;

System.out.println(r>q || s>p); //true


System.out.println(r<s || p>q); //true
System.out.println(r<q || p>s); //false
System.out.println(q==s || p<s); //true

//betwise = &
System.out.println(r>q | s>p); //true
System.out.println(q<s | p>q); //true
System.out.println(r<q | p>r); //false
System.out.println(q==s | p<s); //true

}
}

OUTPUT:

true
true
false
true
true
true
false
true

RATIONAL OPERATOR:

package operators1;

public class Bitwise_And_LogicalAndOperator {

public static void main(String[] args) {

//Logical = &&

int p = 150;
int q = 350;
int r = 450;
int s = 950;

System.out.println(r>q && s>p); //True


System.out.println(q<s && p>q); //false
System.out.println(r<q && p>r); //false
System.out.println(q==s && p>s); //false

//Bitwise = &

System.out.println(r>q & s>p); //true


System.out.println(q<s & p>q); //false
System.out.println(r<q & p>r); //false
System.out.println(q==s & p>s); //false
}

}
OUTPUT:

true
false
false
false
true
false
false
false

SHIFT OPERATOR:

package operators1;

public class Arithmetic_Operator {

public static void main(String[] args) {

int a = 30;
int b = 20;

System.out.println(a+b); //50
System.out.println(a-b); //10
System.out.println(a*b); //600
System.out.println(a/b); //1 Division(/)- gives us the
value of quotient
System.out.println(a%b); //10 Modulus(%) - gives us the
value of reminder

OUTPUT:

50
10
600
1
10

UNARY OPERATORS:
package operators1;

public class Unary_Operators {

//Expression = Variable
//++ = + 1
//-- = -1

public static void main(String[] args) {

int a = 20;
System.out.println(a); //20
//postfix(++)
System.out.println(a++); //20 (20+1+21)
System.out.println(a++); //21 (21+1=22)
System.out.println(a); //22
System.out.println(a++); //22 (22+1=23)

int b =5;
System.out.println(b); //5
//Postfix(--)
System.out.println(b--); // 5(5-1=4)
System.out.println(b--); //4 (4-1=3)
System.out.println(b); //3
System.out.println(b--); //3 (3-1=2)

int c =80;
System.out.println(c); //80
//prefix(++)
System.out.println(++c); //81 (80+1=81)
System.out.println(++c); //82 (81+1=82)
System.out.println(++c); //83 (82+1=83)
System.out.println(c); //83
System.out.println(++c); //84 (83+1=84)
System.out.println(c); //84

int d = 40;
System.out.println(d); //40
//prefix(--)
System.out.println(--d); //39 (40-1=39)
System.out.println(--d); //38 (39-1=38)
System.out.println(d); //38
System.out.println(d); //38

int e = 222;
System.out.println(e); //222
//(+)expression
System.out.println(+e); //222
System.out.println(+e); //222
System.out.println(e); //222

int f = 44;
System.out.println(f); //44
//(-)expression
System.out.println(-f); //-44
System.out.println(-f); //-44

int g = -20;
//~
int h = 30;
//! expression
boolean i = h>g;
System.out.println(~g); //19 -(-20+1)
System.out.println(~h); //-31 -(30+1)
System.out.println(!i); //false opposite sign

}
}

OUTPUT:

20
20
21
22
22
5
5
4
3
3
80
81
82
83
83
84
84
40
39
38
38
38
222
222
222
222
44
-44
-44
19
-31
false

CONTROL SATEMENTS:

IF-STATEMENT:

package control_statement;

public class If_Statements {

public static void main(String[] args) {

int y = -1203;

//Conditional Statements
//Std Syntax of If Statements
//if(Condition){//Statements)

if(y<0) {
System.out.println("you have entered
negative number");
}

int age = 18;


if(age <= 18) {
System.out.println("Teenager Age");
}
if(age>18) {
System.out.println("Adult Age");
}
}
}

OUTPUT:

you have entered negative number


Teenager Age

NESTED-IF STATEMENT:
package control_statement;

public class Nested_if_Statement {

public static void main(String[] args) {

int age = 45;


if(age>18) {
System.out.println("Eligible for Vaccine");
k1();
}
}
public static void k1() {
int s = 43;
int t = 46;

if(s>18 && t<44) {


System.out.println("Both are eligible for vaccine t
and s");
}
}
}

OUTPUT:

Eligible for Vaccine

IF-ELSE /IF ELSE STATEMENT STATEMENT:

package control_statement;

public class If_Else_Statement {

static int math = 41;


public static void main(String[] args) {

if(math > 40) {


System.out.println("You are Pass");
}

else {
System.out.println("You are Fail");
}
}

}
OUTPUT:

You are Pass

ELSE IF STATEMENT:

package control_statement;

public class Else_If_Statement {

public static void main(String[] args) {


int marks = 60;
if(marks>=65) {
System.out.println(" Class With Distinction");
}
else if(marks >=60 && marks <65) {
System.out.println("First Class");
}
else if(marks>=55 && marks <60) {
System.out.println("Higher Second Class");
}

}
OUTPUT:

First Class

NESTED IF ELSE STATEMENT:

package control_statement;

public class Nested_If_Else_Statement {

static String un = "pooja";


static String pwd = "123@lu";

public static void main(String[] args) {

if(un=="pooji") {
if(pwd=="123@lu") {
System.out.println("Welcome Pooja");
}

else {
System.out.println("You are entered wrong password");
}
}
else {
System.out.println("You have entered wrong username");

}
}
}

OUTPUT:

You have entered wrong username

SWITCH STATEMENT:

package control_statement;

public class Nested_If_Else_Statement {

static String un = "pooja";


static String pwd = "123@lu";

public static void main(String[] args) {

if(un=="pooji") {
if(pwd=="123@lu") {
System.out.println("Welcome Pooja");
}

else {
System.out.println("You are entered wrong password");
}
}
else {
System.out.println("You have entered wrong username");

}
}
}
OUTPUT:

------------Hundai Showroom---------------------
Welcome
schooter/bike available according to your budget
pulser black 60000 -/Rs
mestro white 75000 -/Rs
Shine black 80000 /-Rs
Pulsar red 65000 -/Rs

SCANNER CLASS:

package uses;

import java.util.Scanner;
public class Swich_scanner {
static String b;

public static void main(String[] args) {

int day=5;
switch(day) {

case 1 : System.out.println("Today is Monday");break;


case 2 : System.out.println("Today is Tuesday");break;
case 3 : System.out.println("Today is
Wednesday");break;
case 4 : System.out.println("Today is
Thursday");break;
case 5 : System.out.println("Today is Friday");break;
case 6 : System.out.println("Today is
Saturday");break;
case 7 : System.out.println("Today is Sunday");break;
default : System.out.println("Invalid Value/Input");
}
System.out.println("----------------------------------");
System.out.println("Enter today`s day");
Scanner v = new Scanner(System.in);
b = v.nextLine();
System.out.println("Today is = " + b);
System.out.println("Enter which day in one week");
byte m = v.nextByte();
System.out.println("Which days in one week is = " + m);
}

OUTPUT:

Today is Friday
----------------------------------
Enter today`s day
2
Today is = 2
Enter which day in one week

LOOPS IN JAVA:

FOR – LOOP :

package looping;

public class ForLoopEX1 {


int R;
public void cgl() {

System.out.println("Even Numbers"); //1300


for(R = 130; R <= 140; R++ ) {

if(R%2 == 0) {
System.out.println(R);
}
}
System.out.println("Odd Numbers");
for (R = 130; R <= 140; R++) {

if(R%2 == 1) {
System.out.println(R);
}
}
}

public static void main(String[] args) {


ForLoopEX1 K = new ForLoopEX1();
K.cgl();
}
}

OUTPUT:

Even Numbers
130
132
134
136
138
140
Odd Numbers
131
133
135
137
139

WHILE LOOP :

package for_loop_eg;

public class While_loop {

public static void main(String[] args) {


int i = 10;

while(i>1) {
System.out.println(i);
i--;
}
}
}
OUTPUT :

10
9
8
7
6
5
4
3
2
DO-WHILE LOOP:

package for_loop_eg;

public class Do_while_loop {

public static void main(String[] args) {

int y = 1;
do {
System.out.println(y);
y++;
}
while(y<=10);

}
}
OUTPUT:

1
2
3
4
5
6
7
8
9
10

STAR PATTERN:

RIGHT TRINGLE STAR PATTERN:

package for_loop_eg;

public class Star_pattern {

public void zx() {

for(int i = 1; i<5; i++) {


//declared loop for j
for(int j=1; j<=i; j++) {
System.out.print("* "); //ij = *
}
System.out.println(); //new next line
}

}
public static void main(String[] args) {
Star_pattern m = new Star_pattern();
m.zx();
}
}

OUTPUT:

*
* *
* * *
* * * *

MIRRORED RIGHT ANGLE TRIANGLE STAR PATTERN:

package for_loop_eg;

public class StarPattern2 {

public static void main(String[] args) {

for(int i=1; i<=5; i++) {

for(int j=4; j>=i; j--) {


System.out.print(" ");
}
for(int j=1; j<=i; j++) {
System.out.print(" *");
}
System.out.println();
}
}

OUTPUT:

*
* *
* * *
* * * *
* * * * *
INVERTED RIGHT TRINGLE STAR PATTERN:

package for_loop_eg;

public class StarPattern2 {

public static void main(String[] args) {

for(int i=1; i<=5; i++) {

for(int j=4; j>=i; j--) {


System.out.print(" ");
}
for(int j=1; j<=i; j++) {
System.out.print(" *");
}
System.out.println();
}
}

}
OUTPUT:

* * * * *
* * * *
* * *
* *
*

INVERTED MIRRORED RIGHT TRINGLE STAR PATTERN:

package for_loop_eg;

public class StarPattern4 {


public static void main(String[] args) {
for(int i=1; i<=5; i++) {
for(int j=1; j<i; j++){
System.out.print(" ");
}
for(int j= 5; j>=i; j--){
System.out.print(" *");;
}
System.out.println();
}
}

}
OUTPUT:

* * * * *
* * * *
* * *
* *
*

HOLLOW PYRAMID STAR PATTERN:

package for_loop_eg;

public class Hollow_tringle {


public static void main(String[] args) {

for(int i=1; i<=10; i++) {


for(int j=10; j>=i; j--) {
if(i==j) {
System.out.print(" @");}
else {
System.out.print(" ");
}
}
for(int j=1; j<i; j++) {
System.out.print(" ");
}

for(int j=2; j<=i; j++) {


if(i==j) {
System.out.print(" @");
}else{
System.out.print(" ");
}}
System.out.println();
}System.out.println("@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@");}}

OUTPUT:
@
@ @
@ @
@ @
@ @
@ @
@ @
@ @
@ @
@ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @

BUTTERFLY STAR PATTERN:

package for_loop_eg;

public class Butterfly {


public static void main(String[] args) {
for(int i=1; i<=5; i++) {
for(int j=1; j<=i; j++) {
System.out.print(" *");}
for(int j=4; j>=i; j--){
System.out.print(" ");}
for(int j=4; j>=i; j--) {
System.out.print(" ");}
for(int j=1; j<=i; j++) {
System.out.print(" *"); }
System.out.println(); }

for(int i=1; i<=5; i++) {


for(int j=4; j>=i; j--) {
System.out.print(" *");}
for(int j=1; j<=i; j++){
System.out.print(" ");}
for(int j=1; j<=i; j++) {
System.out.print(" ");}
for(int j=4; j>=i; j--) {
System.out.print(" *");}
System.out.println();}

}
}

OUTPUT:

* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *

OOPS CONCEPT:

INHERITANCE:

1.SINGLE LEVEL INHERITANCE:

package sinble_level_inheritance;

public class Father {


public void land() {
System.out.println("Fathers Land");
}
public void house() {
System.out.println("Fathers House");
}
public void car() {
System.out.println("Fathers car");
}
public void job() {
System.out.println("Fathers job");
}
public void balance() {
System.out.println("Fathers Bank Balance");
}
}
----
package sinble_level_inheritance;

public class son extends Father{


public void job1(){
System.out.println("Son`s job");
}
public void bike() {
System.out.println("Son`s Bike");
}
}
----
package sinble_level_inheritance;

public class FatherSonBaithak {

public static void main(String[] args) {

son s = new son();


s.bike();
s.job();
s.balance();
s.land();
s.car();
s.house();
s.job1();
}
}

OUTPUT:
Son`s Bike
Fathers job
Fathers Bank Balance
Fathers Land
Fathers car
Fathers House
Son`s job

MULTI LEVEL INHERITANCE:

package sinble_level_inheritance;

public class FatherSonBaithak {

public static void main(String[] args) {

son s = new son();


s.bike();
s.job();
s.balance();
s.land();
s.car();
s.house();
s.job1();
}
}

package multi_level_inheritance;

public class WhatsAppVersion2 extends WhatsAppVersion1{

public void image() {


System.out.println("WhatsApp`s Image Feature");
}
public void group() {
System.out.println("WhatsApp`s Grouping Features");
}
public void document() {
System.out.println("WhatsApp`s Document Features");
}
public void about() {
System.out.println("WhatsApp`s About Feature");
}
}

package multi_level_inheritance;

public class WhatsAppVersion3 extends WhatsAppVersion2{

public void audioCall() {


System.out.println("WhatsApp`s AudioCall Feature");
}
public void status() {
System.out.println("WhatsApp`s Status Feature)");
}
public void recordings() {
System.out.println("WhatsApp`s Recording Features");
}
public void location() {
System.out.println("Whatspp`s Location Feature");
}

package multi_level_inheritance;
public class WhatsAppVersion4 extends WhatsAppVersion3{

public void videoCall() {


System.out.println("WhatsApp`s VideoCall Feature");
}
public void payment() {
System.out.println("WhatsApp`s Payment Feature");
}
public void videoStatus() {
System.out.println("WhatApp`s Video Status Feature");
}
public void linkdevice() {
System.out.println("WhatsApp`s LinkDevice Feature");
}

package multi_level_inheritance;

public class WhatsAppVersion4 extends WhatsAppVersion3{

public void videoCall() {


System.out.println("WhatsApp`s VideoCall Feature");
}
public void payment() {
System.out.println("WhatsApp`s Payment Feature");
}
public void videoStatus() {
System.out.println("WhatApp`s Video Status Feature");
}
public void linkdevice() {
System.out.println("WhatsApp`s LinkDevice Feature");
}

}
package multi_level_inheritance;

public class WhatsAppMain {

public static void main(String[] args) {


WhatsAppVersion4 k = new WhatsAppVersion4();
k.textmsg();
k.dp();
k.image();
k.group();
k.document();
k.about();
k.audioCall();
k.status();
k.recordings();
k.location();
k.videoCall();
k.payment();
k.videoStatus();
k.linkdevice();
}

OUTPUT:

WhatsApp`s Text Message Feature


WhatsApp`s DP Feature
WhatsApp`s Image Feature
WhatsApp`s Grouping Features
WhatsApp`s Document Features
WhatsApp`s About Feature
WhatsApp`s AudioCall Feature
WhatsApp`s Status Feature)
WhatsApp`s Recording Features
Whatspp`s Location Feature
WhatsApp`s VideoCall Feature
WhatsApp`s Payment Feature
WhatApp`s Video Status Feature
WhatsApp`s LinkDevice Feature

HIRARCHICAL INHERITANCE:

package hirarchical_inheritance;

public class PoojaEat {

public void eating() {


System.out.println("Pooja want to Eat Non Veg
eSpecially Chikan");
}
}
package hirarchical_inheritance;

public class Mess extends PoojaEat{

public void dinner4() {


System.out.println("pooja want to Eat Anything in
Mess");
}
public static void main(String[] args) {
Mess d = new Mess();
d.eating();
d.dinner4 ();
}}

package hirarchical_inheritance;

public class Mess extends PoojaEat{

public void dinner4() {


System.out.println("pooja want to Eat Anything in
Mess");
}
public static void main(String[] args) {
Mess d = new Mess();
d.eating();
d.dinner4 ();
}}

package hirarchical_inheritance;

public class PrasadHotel extends PoojaEat{


public void dinner2() {
System.out.println("Pooja want to Eat Chikan
Thali at PanhalGad Hotel");
}
public static void main(String[] args) {
PrasadHotel b = new PrasadHotel();
b.eating();
b.dinner2();
}
}

package hirarchical_inheritance;

public class PrasadHotel extends PoojaEat{

public void dinner2() {


System.out.println("Pooja want to Eat Chikan
Thali at PanhalGad Hotel");
}
public static void main(String[] args) {
PrasadHotel b = new PrasadHotel();
b.eating();
b.dinner2();
}
}

OUTPUT;

Pooja want to Eat Non Veg eSpecially Chikan


Pooja want to Eat Chikan Thali at PanhalGad Hotel

COMPILE TIME POLYMORPHISM:

package polymorphism;

public class Compiletime {

/*1)Compile-Time Polymorphism*
*Eg=Method overloading*/
public void area(int side) {
System.out.println("Area of 1 Square = "+ side*side);
}
public void area(int side1, int side2) {
int side = side2 - side1;
System.out.println("Area of 2 Square = "+ side*side);
}

public static void main(String[] args) {


Compiletime f = new Compiletime();
f.area(20);
f.area(60, 70);
}
}

OUTPUT:

Area of 1 Square = 400


Area of 2 Square = 100

RUNTIME TIME POLYMORPHISM:

package polymorphism;

public class Runtime {

//Eg=method overriding

public void wish() {


System.out.println("Good Morning !!");
}

package polymorphism;

public class Runtime_extends extends Runtime{


public void wish() {
System.out.println("Good Evening !!");
}

public static void main(String[] args) {


Runtime_extends w = new Runtime_extends();
w.wish();
Runtime w1 = new Runtime();
w1.wish();
}

OUTPUT:

Good Evening !!
Good Morning !!

CASTING:

1.PRIMITIVE CASTING:

IMPLICITE CASTING:

package casting;

public class Implicite_Casting {

public static void main(String[] args) {


int a = 10;
double b = a;
System.out.println(b);
}

OUTPUT:

10.0

EXPLICITE CASTING:
package casting;

public class Explicite_Casting {


public static void main(String[] args) {
int a= 10;
short b = (short)a;
System.out.println(b);

OUTPUT:

10

2.NON-PRIMITIVE CASTING:

UPCASTING:

package casting;

public class Upcasting {

public void home() {


System.out.println("Fathers home");
}
public void land() {
System.out.println("Fathers land");
}
}

package casting;

public class son extends Upcasting{


public void bike() {
System.out.println("Sons bike");

}
public void job() {
System.out.println("Sons job");
}
public static void main(String[] args) {
Upcasting k = new son();
k.home();
k.land();
}
}

OUTPUT:

Fathers home
Fathers land

DOWNCASTING: DOES NOT SUPPORT IN JVM.

4.ABSTRACTION:

package abstraction;

public abstract class BankingApplication {

public void welcome() {


System.out.println("I wanted to open Bank Account");
}
abstract public void name();
abstract public void mobno();
abstract public void aadhar();
abstract public void accountno();
abstract public void un();
abstract public void pwd();
public void ty() {
System.out.println("I have opened Bank Account. Thank
You");
}

package abstraction;

public class BankingHDFC extends BankingApplication{

public void name() {


System.out.println("Vikas Aanan");
}
public void mobno() {
System.out.println("9923186643");
}
public void aadhar() {
System.out.println("96325874112");
}
public void accountno() {
System.out.println("10398745611");
}
final public void un() {
System.out.println("hdfc445");
}
public void pwd() {
System.out.println("14uGanga");
}
public void accountcreated() {
System.out.println("Account is Created Thank for
choosing HDFC Bank");
}
public static void main(String[] args) {
BankingApplication g = new BankingHDFC() ;
g.welcome();
g.welcome();
g.name();
g.mobno();
g.accountno();
g.aadhar();
g.un();
g.pwd();
g.ty();

}}

OUTPUT:

I wanted to open Bank Account


I wanted to open Bank Account
Vikas Aanan
9923186643
10398745611
96325874112
hdfc445
14uGanga
I have opened Bank Account. Thank You

6.INTERFACE:
package interface2;

public interface Transaction1 {

void name();
void adhar();

int a = 120;
static String b = "Velocity";

public void withdrawAmount();


public void withdrawAmount1();

default void fromBank() {


System.out.println(b);
System.out.println("from Bank is Tranaction1");
tyFromBank();
}
private void tyFromBank() {
System.out.println("Thank You form Bank is Transaction1 is
Successful");
}

public static void sc() {


System.out.println("SC is Static Method from Transacion1
Interface");
}
}

package interface2;

public interface Transaction2 {

public void withdrawAmount2();


public void withdrawAmount3();
}

package interface2;

public interface Transaction3 {

public void withdrawAmount4();


public void withdrawAmount5();
}

package interface2;

public class TransactionClass1 implements Transaction3,


Transaction2, Transaction1{

public void withdrawAmount() {


System.out.println("30000");
}

public void withdrawAmount1() {


System.out.println("40000");
}

public void withdrawAmount2() {


System.out.println(a);
System.out.println("10000");

public void withdrawAmount3() {


System.out.println("20000");

public void withdrawAmount4() {


System.out.println("50000");
}

public void withdrawAmount5() {


System.out.println("60000");

public void name() {}

public void aadhar() {}

public static void main(String[] args) {


TransactionClass1 t = new TransactionClass1();
t.withdrawAmount();
t.withdrawAmount1();
t.withdrawAmount2();
t.withdrawAmount3();
t.withdrawAmount4();
t.withdrawAmount5();
t.fromBank();
Transaction1.sc();
}

@Override
public void adhar() {
// TODO Auto-generated method stub

OUTPUT:

30000
40000
120
10000
20000
50000
60000
Velocity
from Bank is Tranaction1
Thank You form Bank is Transaction1 is Successful
SC is Static Method from Transacion1 Interface

7.ENCAPSULATION:

package encapsulation;

public class EncapTest {

private double balance;// Private 2500

public double getBalance() {


return balance;
}

public void setBalance(double balance) {// 2500


if(balance<= 20000) {
this.balance = balance;// 2500
}
}

package encapsulation;

public class EncapTest {

private double balance;// Private 2500

public double getBalance() {


return balance;
}

public void setBalance(double balance) {// 2500


if(balance<= 20000) {
this.balance = balance;// 2500
}
}

package encapsulation;

public class PersonalDetails {

private String name;


private int age;
private long mobno;

public String getName() {


return name;
}
public int getAge() {
return age;
}
public long getMobNo() {
return mobno;
}

public void setName(String name1) {


name = name1;
}

public void setAge(int age) {


this.age = age;
}

public void setMobNo(long mobno1) {


mobno = mobno1;
}

public static void main(String[] args) {


PersonalDetails p = new PersonalDetails();
p.setName("Pratik");
p.setAge(25);
p.setMobNo(963258740l);
System.out.println(p.getName() + " "+ p.getAge()
+ " "+ p.getMobNo());

}
}

OUTPUT:

Pratik 25 963258740

SUPER AND THIS KEYWORS:

THIS:

package oops;

public class ThisKeyword1 {

int a = 1999;
int b = 1499;
int c = 100;
public void q1() {
int a = 10;
int b = 20;
System.out.println(a);
System.out.println(b);
System.out.println(this.a);
System.out.println(this.b);
}

public static void main(String[] aegs) {


ThisKeyword1 e = new ThisKeyword1();
e.q1();
}
}

OUTPUT:

10
20
1999
1499

SUPER:

package oops;

public class ThisKeyword1 {

int a = 1999;
int b = 1499;
int c = 100;
public void q1() {
int a = 10;
int b = 20;
System.out.println(a);
System.out.println(b);
System.out.println(this.a);
System.out.println(this.b);
}

public static void main(String[] aegs) {


ThisKeyword1 e = new ThisKeyword1();
e.q1();
}
}

OUTPUT:

10
20
1999
1499
LOGICAL PROGRAMS:

ARMSTRONG NUMBERS:

package programs;

public class Armstrong_Number {


public void pd() {
int num = 153;
int v = num;
int y =0;
int d = 0;

while(num>0) {
y = v%10;
d = d + (y*y*y);
num = num/10;
}
if(d == v) {
System.out.println("Given number is armstrong number");
}
else {
System.out.println("Given number is not armstrong number");
}
}

public static void main(String[] args) {


Armstrong_Number m = new Armstrong_Number();
m. pd ();

}}
OUTPUT:

Given number is not armstrong number

REVERSE NUMBER:

package programs;

public class Reverse_No {


int no;
int rev;
int rem;
public Reverse_No(){
no =12345;
rev = 0;
}
public void cv() {
while(no!=0) {
rem = no%10; //5,4,3
rev = rev*10 + rem; //5,54,543
no = no/10; //1234, 123, 12
}
System.out.println(rev);
}
public static void main(String[] args) {
Reverse_No y = new Reverse_No();
y.cv();
}
}

OUTPUT:

54321

PRIME NUMBER:

package programs;

public class Prime_no {


public void cnm() {
int temp = 0;

for(int no = 100; no<=150; no++) {


//int temp=0;
for(int i = 2; i<= no - 1; i++) {
if(no%i == 0) {
temp = temp+1; //0+1=1
}
}
if(temp==0) {
System.out.println(no);
}else {
temp = 0;
}
}
} public static void main(String[] args) {
Prime_no v = new Prime_no();
v.cnm();
}
}

OUTPUT:

101
103
107
109
113
127
131
137
139
149

PALLINDROME NUMBER:

package programs;

import java.util.Scanner;

public class Pallindrome_No {


public void qwe() {
System.out.println("enter the range");
Scanner s = new Scanner(System.in);
int a = s.nextInt();
int b = s.nextInt();
s.close();

for( int i=a; i<=b; i++) {


int k = i;
int c = 0;
int n;

while(k>0) {
n = k%10;
c = (10*c)+n;
k = k/10;

if(i==c) {
System.out.println(c);
}}}}
public static void main(String[] args) {
Pallindrome_No r =new Pallindrome_No();
r.qwe();

}
}

OUTPUT:

enter the range


0
20
1
2
3
4
5
6
7
8
9
11

NATURAL NUMBER:

package programs;

public class Natural_Number {


public void cv() {
// for(int i = 1; i<=10; i++) {
// System.out.println(i);
// }
int k =1;
do {
System.out.println(k);
k++;
}while( k<=10);

public static void main(String[] args){


Natural_Number m = new Natural_Number();
m.cv();
}
}
OUTPUT:

1
2
3
4
5
6
7
8
9
10

FIBONACCI SERIES:

package programs;

public class Fibonacci_S {


public void manu() {
int a = 0;
int b = 1;
int c;
System.out.println(a);
System.out.println(b);
for(a = 0; a<=10; a++) {
c = a + b;
System.out.println(c);
a = b;
b = c;
}}
public static void main(String[] args) {
Fibonacci_S E = new Fibonacci_S();
E.manu();
}
}

OUTPUT:

0
1
1
3
5
9
15
25

FACTORIAL NUMBER:

package programs;

public class Factorial_No {


static int n = 5;
static int fact = 1;

static void dell() {


for(int i = 1; i<=5; i++) {
fact = fact * i; //1, 2, 6
}
System.out.println("this is factorial " + fact);
}

public static void main(String[] args) {


Factorial_No M = new Factorial_No();
M.dell();
}}

OUTPUT:

this is factorial 120

AVERAGE NUMBER:

package programs;

public class Average_Number {


public void avg() {
int a =10;
float b =0;

for(int i = 1; i<=a; ++i) {


b = b+i;
}
float avg = b/a;
System.out.println(avg);
}
public static void main(String[] args) {
Average_Number k = new Average_Number();
k.avg();
}
}

OUTPUT:

5.5

You might also like