Java Training
Java Training
Java Training
Program-1
Source code:
import java.io.*;
class student
{
String name;
int rno,m1,m2,m3;
void getstu()throws IOException
{
BufferedReader obj=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the name of student,roll number and
marks of three students");
name=obj.readLine();
rno=Integer.parseInt(obj.readLine());
m1=Integer.parseInt(obj.readLine());
m2=Integer.parseInt(obj.readLine());
m3=Integer.parseInt(obj.readLine());
}
void marksheet()
Output:
Program-2
Program-3
Output:
Program-4
Program-5
Program-6
Program-7
Program-8
Program-9
Output:
Source code:
class Circle
{
public int r;
void getvalue(int x)
{
r=x;
}
void putradius()
{
System.out.println("The radius of circle= ");
r=Integer.parseInt(br.readLine());
}
}
class Area extends Circle
{
double a;
void printArea()
{
a=Math.PI*r*r;
System.out.println("Area= "+a);
}
Program-11
Program-12
Program-13
Objective: WAP to show in the base and derived class the
name of the variable can be same and also accessed by super
keyword.
Source code:
class Base
{
Akansha Dwivedi BCA 5th Sem Page 30
SUMMER TRAINING
int a=10;
float b=50.0f;
}
Program-14
Source Code:
class Company
{
String cname;
Company(String an)
{
cname=an;
System.out.println("Class Company");
}
void ShowCompany()
{
System.out.println("Company Name\t"+cname);
}}
class Department extends Company
{
String dname;
Department(String an,String dn)
{
super(an);
dname=dn;
System.out.println("Class Department");
}
void showDept()
{
this.ShowCompany();
Output:
Program-15
Program-16
Program-17
Program-18
Output:
Program-20
Program-21
Program-22
Program-23
Output:
System.out.println("Natural\t"+N);
N.setName("Natural");
E.setName("Even");
O.setName("Odd");
N.setPriority(Thread.MAX_PRIORITY);
O.setPriority(2);
System.out.println("Name of 1 thread\t"+N.getName());
System.out.println("Name of 2 thread\t"+E.getName());
System.out.println("Name of 3 thread\t"+O.getName());
System.out.println("Priority of thread1\t"+N.getPriority());
System.out.println("Priority of thread2\t"+E.getPriority());
System.out.println("Priority of thread3\t"+O.getPriority());
System.out.println("Natural\t"+N);
N.start();
E.start();
O.start();
}}
Output:
Program-25
Output:
Program-26
Program-27
Objective: WAP to a matrix of 4X5 and print the sum of all row.
Source code:
import java.io.*;
class RowSum
{
public static void main(String args[])throws IOException
Program-28
Program-29
Akansha Dwivedi BCA 5th Sem Page 66
SUMMER TRAINING
Objective: WAP to demonstrate the static variable and
method.
Source code:
class employee
{
String ename;
int ecode;
float esal;
static int count=0;
void getemp(String name,int code,float sal)
{
ename=name;
ecode=code;
esal=sal;
count++;
}
void putemp()
{
System.out.println("Name\t"+ename);
System.out.println("Code\t"+ecode);
System.out.println("Salary\t"+esal);
}
static void showcount()
{
System.out.println("total employee="+count);
class TestStatic
{
static int a=30;
int b=50;
public static void main(String args[])
{
int c=70;
System.out.println("a="+a);
//System.out.println("b="+b);error
System.out.println("c="+c);
System.out.println("count="+employee.count);
employee.showcount();
employee emp1=new employee();
employee emp2=new employee();
employee emp3=new employee();
emp1.getemp("Aastha",1020,55000.0f);
emp2.getemp("Aakansha",1021,75000.0f);
emp3.getemp("Shipra",1022,95000.0f);
emp1.putemp();
emp2.putemp();
emp3.putemp();
employee.showcount();
emp2.showcount();
}}
Akansha Dwivedi BCA 5th Sem Page 68
SUMMER TRAINING
Output:
Program-30
Program-31
Source Code:
import java.io.*;
interface College
{
String cname="SHERWOOD COLLEGE";
String code="1020";
String city="LUCKNOW";
void printstudentdetail();
void msg();
}
class Department
{
Output:
Source code:
interface University
{
String uname="AKTU";
String city="LUCKNOW";
void putuniversity();
}
interface UGC
{
String ugc="University Grant Commission";
void show();
}
interface College extends University, UGC
{
String cname="SHERWOOD";
String city="LUCKNOW";
void putcollege();
}
class Student implements College
{
String sname,scourse;
static void display()
{
Program-33
Source code:
interface Company
{
String cname="ANALYZE";
String city="LUCKNOW";
void putcompany();
}
interface Department
{
String dname="SD";
String dcode="ai1020";
void putdept();
}
class Employee implements Company, Department
{
Program-34
Program-35
Program-36
Program-37
Akansha Dwivedi BCA 5th Sem Page 87
SUMMER TRAINING
Objective: WAP to demonstrate the setting of background
color, font and foreground color.
Source code:
import java.applet.*;
import java.awt.*;
public class Applet2 extends Applet
{
public void init()
{
Color c=new Color(250,100,10);
Font f=new Font("Viner Hand ITC",Font.PLAIN,30);
setBackground(Color.gray);
setForeground(c);
setFont(f);
}
public void paint(Graphics g)
{
g.drawString("Welcome to Applet Programming",20,100);
}
}
/*<Applet code=Applet2 width=400 height=200>
</Applet>*/
Output:
Program-38
Output:
Program-39
Program-40
Source code:
import java.awt.*;
class BorderLayoutTest extends Frame
{
Button b1,b2,b3,b4,b5,b6;
BorderLayoutTest()
{
setBackground(Color.gray);
b1=new Button("Button1");
b2=new Button("Button2");
b3=new Button("Button3");
b4=new Button("Button4.....................................");
b5=new Button("Button5");
b6=new Button("Button6");
add(b1,BorderLayout.NORTH);
Akansha Dwivedi BCA 5th Sem Page 94
SUMMER TRAINING
add(b2,BorderLayout.SOUTH);
add(b3,BorderLayout.EAST);
add(b4,BorderLayout.CENTER);
add(b5,BorderLayout.WEST);
add(b6);
setSize(500,300);
setVisible(true);
}
public static void main(String args[])
{
new BorderLayoutTest();
}
}
Output:
Program-41
Output:
Output:
Program-43
Program-45
Output:
Program-46
Program-47
Output: