Oopj - Lab Manual
Oopj - Lab Manual
Oopj - Lab Manual
PTACTICAL-1
1
Your Name Enroll No:number
2
Your Name Enroll No:number
3
Your Name Enroll No:number
4
Your Name Enroll No:number
PRCTICAL-2
INPUT:
class oop
{
public static void main(String arg[])
{
System.out.print("oop with java");
}
}
OUTPUT:
oop with java
5
Your Name Enroll No:number
PRACTICAL-3
INPUT:
class data2
{
public static void main (String arg[])
{
char c ='K';
short s=1234;
byte b=12;
int i=125349;
float f=13.68437282f;long l=3632645;
double d =34.847739382293382;
{
System.out.println("char:"+ c);
System.out.println("short:"+ s);
System.out.println("byte:"+ b);
System.out.println("int:"+ i);
System.out.println("float:"+ f);
System.out.println("double:"+d);
System.out.println("long:"+ l);
}
}
}
OUTPUT:
char:K
short:1234
byte:12
int:125349
float:13.684373
double:34.84773938229338
long:3632645
6
Your Name Enroll No:number
PRCTICAL-4
INPUT:
//without using temporary varible
class Swap
{public static void main (String arg[])
{
int a=20;
int b=30;
a=a+b;
b=a-b;
a=a-b;
{
System.out.println(“a:”+a);
System.out.println(“b:”+b);
}
}
}
OUTPUT:
a:30
b:20
//Using temporary variable(use cmd)
class Argument
{
public static void main(String arg[])
{
if(arg.length !=2)
{
System.out.println("please provide two number from command
line
argument");
7
Your Name Enroll No:number
return;
}
int x=Integer.parseInt(arg [0]);
int y=Integer.parseInt(arg [1]);
{int temp=x;
x=y;
y=temp;
System.out.println(“x”+x);
System.out.println(“y”+y);
}
}
}
OUTPUT:
x:6
y:12
8
Your Name Enroll No:number
PRACTICAL-5
INPUT:
// if-else statement
class If
{
public static void main(String arg[])
{
int x=70;
if(x<45)
{
System.out.println("pass in exam");
}
else
{System.out.println("failed in exam");
}
}
}
OUTPUT:
failed in exam
//else-if
class Else
{
public static void main(String arg[])
{
int number=3;
if(number>3)
{
System.out.println("POSITIVE");
}
else if(number<0)
9
Your Name Enroll No:number
{
System.out.println("NEGATIVE");
}
else
{
System.out.println("ZERO");
}
}
}
OUTPUT:
ZERO
//nested if-else
class Switch
{
public static void main(String arg[])
{
int age=25;
int weight=50;
if(age>=25)
{
if(weight>48)
{
System.out.println("you are eligiable for donated blood");
}
else
{
System.out.println("you are eligiable for donated blood");
}
}
else
{
System.out.println("Age must be greated than 18 ");
}
}
}
OUTPUT:
10
Your Name Enroll No:number
class Switch
{
public static void main(String arg[])
{
String Branch=("It");
switch(Branch)
{
case "Civil":
System.out.println("Mittal");
break;
case "Mechanical":
System.out.println("Kriya");
break;
case "Computer":
System.out.println("Krupa");
break;
case "It":
System.out.println("Khushi");
break;
default:
System.out.println("invalid Branch");
}
System.out.println("khushi is " + Branch + " Student");
}
}
OUTPUT:
Khushi
khushi is It Student
11
Your Name Enroll No:number
PRACTICAL-6
INPUT:
//for loop
class For
{
public static void main (String arg[])
{
int s ,r ,k=6;
{
for(s=1; s<=k; s++)
{
for(r=1; r<=s; r++)
{
System.out.print("*");
}
System.out.println( );
}
}
}
}
2]while and do while
class sum
{
public static void main(String arg[])
{
int x=12 ,sum=0;
{
while(x<=13)
{
sum=sum+x;
{
12
Your Name Enroll No:number
x++;
{
System.out.println("Addition:"+sum);
}
}
}
}
}
OUTPUT:
Addition:12
Addition:25
//Do while
class While
{
public static void main(String arg[])
{
int x=2;
do
{
System.out.println(x);
x++;
}
while(x<=20);
}
}
OUTPUT:
2
3
4
5
6
7
8
9
10
11
13
Your Name Enroll No:number
12
13
14
15
16
17
18
19
20
14
Your Name Enroll No:number
PRACTICAL-7
INPUT:
import java.util.Arrays;
class Array
{
public static void main(String args[])
{
int a[]={1,423,6,46,34,23,13,53,4};
Arrays.sort(a);
System.out.println("min-"+a[0]+" max-"+a[a.length-1]);
}
}
OUTPUT:
min-1 max-423
15
Your Name Enroll No:number
PRACTICAL-8
INPUT:
class Student
{
int id;
String name;
}
class TestStudent2
{
public static void main(String args[])
{
Student s1=new Student();
s1.id=101;
s1.name="sujal";
System.out.println(s1.id+" "+s1.name);
}
}
OUTPUT:
101 sujal
16
Your Name Enroll No:number
PRACTICAL-9
INPUT:
class Factorial
{
static int factorial(int n)
{
if(n!=0)
return n*factorial(n-1);
else
return 1;
}
public static void main (String args[])
{
int number=6,result;
result=factorial(number);
System.out.println(number+ "factorial" +result);
}
}
OUTPUT:
6factorial:720
17
Your Name Enroll No:number
PRACTICAL-10
INPUT:
class Adder
{
static int add(int a,int b)
{
return a+b;
}
static double add(double a,double b)
{
return a+b;
}
class TestOverloading
{
public static void main(String arg[])
{
System.out.println(Adder.add(11,11));
System.out.println(Adder.add(12.3,12.6));
}
}
}
OUTPUT:
22
24.9
18
Your Name Enroll No:number
PRACTICAL-11
INPUT:
class operation
{
public static void main(String arg[])
{
String s="String operation";
System.out.println(s);
System.out.println(s.startsWith("st"));
System.out.println(s.endsWith("n"));
System.out.println(s.charAt(0));
System.out.println(s.charAt(3));
System.out.println(s.length());
System.out.println(s.substring(2));
System.out.println(s.substring(0,2));
}
}
OUTPUT:
String operation
false
true
S
i
16
ring operation
St
19
Your Name Enroll No:number
PRACTICAL-12
INPUT:
class Wrapper
{
public static void main(String args[])
{
byte b=10;
short s=20;
int i=30;
long l=40;
float f=50.0F;
double d=60.0D;
char c='a';
boolean b2=true;
System.out.println("object values:");
System.out.println("Byte object: "+byteobj);
System.out.println("Short object: "+shortobj);
System.out.println("Integer object: "+intobj);
System.out.println("Long object: "+longobj);
System.out.println("Float object: "+floatobj);
20
Your Name Enroll No:number
OUTPUT:
object values:
Byte object: 10
Short object: 20
Integer object: 30
Long object: 40
Float object: 50.0
Double object: 60.0
Character object: a
21
Your Name Enroll No:number
primitive values:
byte value: 10
short value: 20
int value: 30
long value: 40
float value: 50.0
double value: 60.0
char value: a
boolean value: true
22
Your Name Enroll No:number
PRACTICAL-13
INPUT:
class Static
{
static
{
System.out.println("Inside Static Block.");
}
OUTPUT:
Inside Static Block.
Inside main method.
23
Your Name Enroll No:number
PRACTICAL-14
INPUT:
class Demo
{
void display()
{
System.out.println("A non-static function is called.");
}
obj.display();
Demo.show();
}
}
OUTPUT:
A non-static function is called.
The static function is called.
24
Your Name Enroll No:number
PRACTICAL-15
INPUT:
class Student
{
int rollno;
String name;
float fee;
Student(int rollno,String name,float fee)
{
this.rollno=rollno;
this.name=name;
this.fee=fee;
}
void display(){System.out.println(rollno+" "+name+" "+fee);
}
}
class This
{
public static void main(String args[])
{
Student s1=new Student(111,"Khushi",5000f);
Student s2=new Student(112,"Mittal",6000f);
s1.display();
s2.display();
}
}
OUTPUT:
111 Khushi 5000.0
112 Mittal 6000.0
25
Your Name Enroll No:number
26