Professional Documents
Culture Documents
Java Programms
Java Programms
Java Programms
package details;
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");
OUTPUT:
Name:Pooja Bibave
Address:Sangamner,Ahamadnagar
Education:B.E.Civil Engineering
Mobile No:8208103662
Hobbies:Watching TV,Playing Mobile Games,Listening Songs
package additionStatements;
}
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;
OUTPUT:
Name:Bibave Pooja
Address:Sangamner,Ahamadnagar
Education:B.E.Civil Engineering
Mobile No:8208103662
package additionStatements;
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;
OUTPUT
Hellow Word
NON-STATIC MOTHOD
package program;
}
OUTPUT
package program;
System.out.println("Velocity class"); }
OUTPUT
Hey Pooja
Velocity class
VARIABLES :
LOCAL VARIABLE :
package types;
System.out.println(a);
System.out.println(b);
System.out.println(a+b);
System.out.println(a*b);
}
public static void main(String[] args) {
System.out.println(y);
System.out.println(z);
}
OUTPUT :
10
20
30
200
customer2
2
4
INSTANCE VARIABLE :
package types;
byte i = 1; //Rank
byte j = 2;
byte k = 3;
byte l = 4;
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) {
}
}
OUTPUT :
STATIC VARIABLE :
package types;
System.out.println(a);
System.out.println(d);
System.out.println(a + "\n" + d);
}
OUTPUT :
My name is pooja
67
My name is pooja
67
DATATYPES:
PRIMITIVE DATATYPE :
package primitive_nonPrimitiveExample;
public class Datatype {
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;
String a = "Sprite";
String b = "Pepsi";
String c = "Coca-Cola";
String d = "Fanta";
String e = "Maaza";
String f = "Mirinda";
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;
//1.Declaration
//2.Initialization
name = name1;
age = age1;
mob = mob1;
}
//Usage
public void details() {
OUTPUT:
package mCWSC_With_Argument;
}
OUTPUT:
THIS KEYWORD:
package detail;
int a = 20;
int b = 30;
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 {
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
package operators1;
//Logical = &&
int p = 150;
int q = 350;
int r = 450;
int s = 950;
}
OUTPUT:
true
false
false
false
true
false
false
false
package operators1;
//bitwise OR = |
//Logical OR = ||
int p = 150;
int q = 350;
int r = 450;
int s = 950;
//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;
//Logical = &&
int p = 150;
int q = 350;
int r = 450;
int s = 950;
//Bitwise = &
OUTPUT:
true
false
false
false
true
false
false
false
SHIFT OPERATOR:
package operators1;
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;
//Expression = Variable
//++ = + 1
//-- = -1
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;
int y = -1203;
//Conditional Statements
//Std Syntax of If Statements
//if(Condition){//Statements)
if(y<0) {
System.out.println("you have entered negative
number");
}
NESTED-IF STATEMENT:
package control_statement;
OUTPUT:
package control_statement;
}
OUTPUT:
ELSE IF STATEMENT:
package control_statement;
}
OUTPUT:
First Class
package control_statement;
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:
SWITCH STATEMENT:
package control_statement;
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;
int day=5;
switch(day) {
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;
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);
}
}
}
OUTPUT:
Even Numbers
130
132
134
136
138
140
Odd Numbers
131
133
135
137
139
WHILE LOOP :
package for_loop_eg;
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;
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:
package for_loop_eg;
}
public static void main(String[] args) {
Star_pattern m = new Star_pattern();
m.zx();
}
}
OUTPUT:
*
* *
* * *
* * * *
package for_loop_eg;
OUTPUT:
*
* *
* * *
* * * *
* * * * *
INVERTED RIGHT TRINGLE STAR PATTERN:
package for_loop_eg;
}
OUTPUT:
* * * * *
* * * *
* * *
* *
*
package for_loop_eg;
}
OUTPUT:
* * * * *
* * * *
* * *
* *
*
package for_loop_eg;
OUTPUT:
@
@ @
@ @
@ @
@ @
@ @
@ @
@ @
@ @
@ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
package for_loop_eg;
}
}
OUTPUT:
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
OOPS CONCEPT:
INHERITANCE:
package sinble_level_inheritance;
OUTPUT:
Son`s Bike
Fathers job
Fathers Bank Balance
Fathers Land
Fathers car
Fathers House
Son`s job
package sinble_level_inheritance;
package multi_level_inheritance;
package multi_level_inheritance;
package multi_level_inheritance;
public class WhatsAppVersion4 extends WhatsAppVersion3{
package multi_level_inheritance;
}
package multi_level_inheritance;
OUTPUT:
HIRARCHICAL INHERITANCE:
package hirarchical_inheritance;
package hirarchical_inheritance;
package hirarchical_inheritance;
public class PrasadHotel extends PoojaEat{
package hirarchical_inheritance;
OUTPUT;
package polymorphism;
/*1)Compile-Time Polymorphism*
*Eg=Method overloading*/
OUTPUT:
package polymorphism;
//Eg=method overriding
package polymorphism;
OUTPUT:
Good Evening !!
Good Morning !!
CASTING:
1.PRIMITIVE CASTING:
IMPLICITE CASTING:
package casting;
OUTPUT:
10.0
EXPLICITE CASTING:
package casting;
OUTPUT:
10
2.NON-PRIMITIVE CASTING:
UPCASTING:
package casting;
package casting;
}
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