Java File
Java File
*/
class abc
{
public static void main(String args[])
{
System.out.println("Hello, this is my First Java
Program");
}
}
OUTPUT:
OUTPUT:
class room
{
float length;
float breadth;
void getdata(float a,float b)
{
length=a;
breadth=b;
}
}
class roomarea
{
public static void main(String args[])
{
float area;
room obj= new room();
3
obj.getdata(10,20); // function call
area= obj.length*obj.breadth;
System.out.println("Area="+area);
}
}
OUTPUT:
class Rectangle
{
int length, breadth;
void getdata(int x, int y)
{
length = x;
breadth = y;
}
int rectArea()
{
int area = length * breadth;
return (area);
}
}
class RoomArea
5
{
public static void main(String args[])
{
OUTPUT:
{
int a=10;
int b=20;
int c;
display()
{
c=30;
}
void show()
{
System.out.println("A="+a);
System.out.println("B="+b);
System.out.println("C="+c);
}
7
}
class demo
{
public static void main(String args[])
{
OUTPUT:
6 /*Program to Parameterized
constructor*/
class room
{
int length,breadth,res;
room(int x,int y)
{
length=x;
breadth=y;
}
void roomarea()
{
res=length*breadth;
System.out.println("area="+res);
}
}
class roomarea
9
{
public static void main(String args[])
{
room obj=new room(10,20);
obj.roomarea();
}
}
OUTPUT:
10
room(int l, int b)
{
length=l;
breadth=b;
}
room(room obj)
{
System.out.println("copy constructor");
length=obj.length;
breadth=obj.breadth;
}
int area()
11
{
return(length*breadth);
}
}
class roomarea
{
public static void main(String args[])
{
room firstroom=new room(10,20);
room secondroom=new room(firstroom);
System.out.println("The area
is="+firstroom.area());
System.out.println("The area
is="+secondroom.area());
}
}
OUTPUT:
12
{
x = a;
y = b;
}
int largest()
{
if (x >= y)
return(x);
else
return(y);
}
void display()
13
{
int large = largest();
System.out.println("largest value="+large);
}
}
class nestingdemo
{
OUTPUT:
14
}
}
class derived extends base
{
int num2;
void product()
{
System.out.println("Product of 2no's="+
(num1*num2));
}
void derivedshow()
15
{
System.out.println("num2="+num2);
}
}
class inheritancedemo
{
public static void main(String args[])
{
OUTPUT:
16
room(int l, int b)
{
length=l;
breadth=b;
}
void area()
{
System.out.println("Area of room="+
(length*breadth));
}
}
class bedroom extends room
17
{
int height;
bedroom(int l,int b,int h)
{
super(l,b);
height=h;
}
void volume()
{
System.out.println("Value of room="+
(length*breadth*height));
}
}
class inheritdemo
{
public static void main(String args[])
{
bedroom obj=new bedroom(10,20,30);
18
obj.area();
obj.volume();
}
}
OUTPUT:
19
{
this.x=x;
}
void display()
{
System.out.println("Value of x="+x);
}
}
class derived extends base
{
int y;
20
derived(int x,int y)
{
super(x);
this.y=y;
}
void display()
{
System.out.println("value of x="+x);
System.out.println("Value of y="+y);
}
}
class overridedemo
{
public static void main(String args[])
{
derived obj = new derived(100,200);
obj.display();
}
21
}
OUTPUT:
22
{
share s;
rectangle r=new rectangle(10,20);
s=r;
s.area();
s.circumference();
circle c = new circle (30);
s=c;
s.area();
25
s.circumference();
}
}
OUTPUT:
26
a1 = rect;
System.out.println("Area of
rectangle="+a1.compute(10,20));
a1=cir;
System.out.println("Area of
circle="+a1.compute(10,0));
}
}
28
OUTPUT:
29
x=a/(b-c);
}
catch(ArithmeticException e)
{
System.out.println("Division by zero");
}
y = a/(b+c);
System.out.println("y="+y);
}
30
}
OUTPUT:
31
p[3] = 33;
try
{
z=x/((b*b)-(4*a*c));
System.out.println("The value of z is ="+ z);
}
catch(ArithmeticException e)
32
{
System.out.println("Division by zero in
Arithmatic expression");
}
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array index is out-ofbounds");
}
}
}
OUTPUT:
33
}
catch(ArithmeticException e)
{
System.out.println("Division by zero");
}
catch(ArrayIndexOutOfBoundsException e)
{
34
System.out.println("Array Index error");
}
catch(ArrayStoreException e)
{
System.out.println("Wrong data type");
}
int y = a[1]/a[0];
System.out.println("y = " +y);
}
}
OUTPUT:
35
int x = a[2]/b-a[1];
}
catch(ArithmeticException e)
{
System.out.println("Division by zero");
}
catch(ArrayIndexOutOfBoundsException e)
36
{
System.out.println("Array index error");
}
catch(ArrayStoreException e)
{
System.out.println("wrong data type");
}
finally
{
int y=a[1]/a[0];
System.out.println("y ="+y);
}
}
}
OUTPUT:
37
39
OUTPUT:
40
divide_m();
}
catch(ArithmeticException e)
{
System.out.println("caught the exception"+e);
41
}
}
}
OUTPUT:
42
int e=-d;
System.out.println("a =" +a);
System.out.println("b =" +b);
System.out.println("c =" +c);
System.out.println("d =" +d);
43
System.out.println("e =" +e);
System.out.println("Floating Point Arithmetic");
double da=1+1;
double db=da*3;
double dc=db/4;
double dd=dc-a;
double de=dd;
System.out.println("da="+da);
System.out.println("db="+db);
System.out.println("dc="+dc);
System.out.println("dd="+dd);
System.out.println("de="+de);
}
}
44
OUTPUT:
45
OUTPUT:
47
{
even += 1;
}
else
{
48
odd += 1;
}
}
System.out.println("Even Numbers: " +even +
"Odd Numbers : " + odd);
}
}
OUTPUT:
49
}
else
{
System.out.println(c);
}
50
}
if(c > b)
{
System.out.println(c);
}
else
{
System.out.println(b);
}
}
}
OUTPUT:
51
else if(marks[i]>59)
System.out.println(rollnumber[i] + " I
Division");
else if(marks[i]>49)
System.out.println(rollnumber[i] + " II
Division");
else
52
System.out.println(rollnumber[i] + " fail");
}
}
}
OUTPUT:
53
{
string.append(c);
}
}
catch(Exception e)
{
54
System.out.println("Error in input");
}
System.out.println("You have entered...");
System.out.println(string);
}
}
OUTPUT:
55
{
column = 1;
do
{
y = row * column;
System.out.println("area="+y);
56
column = column + 1;
}
while (column <= 3);
System.out.println("\n");
row = row + 1;
}
while(row <= 3);
}
}
OUTPUT:
57
58
OUTPUT:
59
str = "Java";
str = "Hello" + str;
}
public void paint (Graphics g)
{
g.drawString(str,10,100);
}
60
}
WIDTH = 400
HEIGHT = 200>
<PARAM NAME = "string"
VALUE ="Applet!">
</APPLET>
</BODY>
</HTML>
61
OUTPUT:
62
29 /*Program to Drawing lines and
rectangles.*/
import java.awt.*;
import java.applet.*;
public class LineRect
extends Applet
{
public void paint (Graphics g)
{
g.drawLine(10, 10, 50, 50);
g.drawRect(10, 60, 40, 30);
OUTPUT:
64
OUTPUT:
66
OUTPUT:
68