Java Lab Ex
Java Lab Ex
String name;
int rollno;
int age;
void info()
System.out.println("Name: "+name);
System.out.println("Age: "+age);
student.rollno = 253;
student.age = 25;
// Calling method
student.info();
}
OUTPUT
Name: Ramesh
Age: 25
Ex .no:2 /* INTERITANCE AND POLYMORPHISM*/
---------------------------------------------------------------
class Animal
}}
}}
}}
class Main {
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();
}}
OUTPUT:
interface Results
{
final static float pi = 3.14f;
float areaOf(float l, float b);
}
class Rectangle implements Results
{
public float areaOf(float l, float b)
{
return (l * b);
}
}
class Square implements Results
{
public float areaOf(float l, float b)
{
return (l * l);
}
}
class Circle implements Results
{
public float areaOf(float r, float b)
{
return (pi * r * r);
}
}
public class InterfaceDemo
{
public static void main(String args[])
{
Rectangle rect = new Rectangle();
Square square = new Square();
Circle circle = new Circle();
System.out.println("Area of Rectangle: "+rect.areaOf(20.3f, 28.7f));
System.out.println("Are of square: "+square.areaOf(10.0f, 10.0f));
System.out.println("Area of Circle: "+circle.areaOf(5.2f, 0));
}
}
Output:
Area of Rectangle: 582.61
Are of square: 100.0
Area of Circle: 84.905594
Ex.no:07 : SWING CONCEPT
------------------------------
import javax.swing.*;
}
OUTPUT:
---------------
Ex.no : 8 /*Implementing Exception Handling*/
Output:
System.out.println("thread"+Thread.currentThread().getId()+"isrunning");
}
catch(Exception e)
{
System.out.println("Exception is caught");
}
}
}
public class multithreading
{
public static void main(String[] args)
{
int n=8;
for(int i=0;i<8;i++)
{
MultithreadingDemo obj=new MultithreadingDemo();
obj.start();
}
}
}
Output:
thread10isrunning
thread9isrunning
thread13isrunning
thread14isrunning
thread16isrunning
thread12isrunning
thread15isrunning
thread11isrunning
Ex.no:10 : I/O - STREAM FILE HANDLING
----------------------------------------------
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
class copy05
{
public static void main(String args[])throws IOException
{
FileInputStream in=null;
FileOutputStream out=null;
try
{
in=new FileInputStream("G://sawc//abi.txt");
out=new FileOutputStream("G://sawc//outagain.txt");
int c;
while((c=in.read())!=-1)
{
out.write(c);
}
}
finally
{
if(in!=null)
{
in.close();
}
if(out!=null)
{
out.close();
}
System.out.print("\n The string has been copied into new string...");
System.out.print("\n The IO handling is performed...");
}
}
}
OUTPUT:
---------------
C:\jdk1.2.1\bin>javac copy05.java
C:\jdk1.2.1\bin>java copy05