SlideShare a Scribd company logo
1
Java practical N Scheme Experiments
Java programming path setting
➢ Open Notepad type the java program.
➢ Save the program using Filename .java
➢ Open command Prompt
➢ Set the path.
➢ Compile java program using the command javac filename.java
➢ Run the Program using the command java file name
➢ Give the inputs and verify the outputs
2
Ex:No-1 CONVERT CELSIUS TO FAHRENHEIT
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
class nex1
{
public static void main(String str[])
{
float f,fahren,celsius;
celsius=24;
fahren=((celsius*9)/5)+32;
System.out.println("Temperature in fahrenheit :"+fahren);
}
}
Output:
Result:
3
EX:N0-2 FIND LARGEST NUMBER
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
class nex2
{
public static void main(String str[])throws IOException
{
int a,b;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s1=br.readLine();
a=Integer.parseInt(s1);
String s2=br.readLine();
b=Integer.parseInt(s2);
if(a>b)
{
System.out.println("a is greater");
}
else
{
System.out.println("b is greater");
}
}
}
4
Output:
Result:
5
EX:No-3 FACTORIAL NUMBERS
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
class nex3
{
public static void main(String str[])throws IOException
{
int n,i,fact;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s1=br.readLine();
n=Integer.parseInt(s1);
fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
System.out.println("Factorial:t"+fact);
}
}
}
6
Output:
Result:
7
EX:No-4 VECTOR CLASS AND METHODS
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
import java.util.*;
public class vec4
{
public static void main(String args[])throws IOException
{
int len,cap;
Vector<String> vec = new Vector<String>();
System.out.println("Enter Add Elementsn");
vec.add("Tiger");
vec.add("Lion");
vec.add("Dog");
vec.add("Elephant");
len=vec.size();
System.out.println("SIZE:t"+len);
cap=vec.capacity();
System.out.println("CAPACITY:t"+cap);
vec.addElement("Rat");
vec.addElement("Cat");
vec.addElement("Deer");
System.out.println("Elements are: "+vec);
len=vec.size();
System.out.println("SIZE:t"+len);
cap=vec.capacity();
System.out.println("CAPACITY:t"+cap);
}
}
8
Output:
Result:
9
EX:No-5 PALINDROME OR NOT
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
class nex5
{
public static void main(String str[])throws IOException
{
int strln;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s1=br.readLine();
s1="amma";
String s2="";
strln=s1.length();
for(int i=(strln-1);i>=0;--i)
{
s2=s2+s1.charAt(i);
}
if(s1.toLowerCase().equals(s2.toLowerCase()))
{
System.out.println("tis a palindrome");
}
else
{
System.out.println("tis not palindrome");
}
}
}
10
Output:
Result:
11
EX:No-6 STUDENT MARKSHEET USING CONSTRUCTOR
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
import java.util.Scanner;
public class Student
{
private String name;
private int eng;
private int hn;
private int mts;
private double total;
private double avg;
public void accept()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter student name: ");
name = in.nextLine();
System.out.print("Enter marks in English: ");
eng = in.nextInt();
System.out.print("Enter marks in Hindi: ");
hn = in.nextInt();
System.out.print("Enter marks in Maths: ");
mts = in.nextInt();
}
public void compute()
{
total = eng + hn + mts;
avg = total / 3.0;
}
12
public void display()
{
System.out.println("Name: " + name);
System.out.println("Marks in English: " + eng);
System.out.println("Marks in Hindi: " + hn);
System.out.println("Marks in Maths: " + mts);
System.out.println("Total Marks: " + total);
System.out.println("Average Marks: " + avg);
}
public static void main(String args[])
{
Student ss = new Student();
ss.accept();
ss.compute();
ss.display();
}
}
Output:
Result:
13
EX:No-7 DISPLAY RADIUS OF A CIRCLE USING COMMAND LINE
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
class nex7
{
public static void main(String args[])
{
double radius=Double.parseDouble(args[0]);
System.out.println("Area: "+(22/7 * radius * radius));
System.out.println("Perimeter: "+(2 * 22/7 * radius));
}
}
Output:
Result:
14
EX:No-8 MULTI LEVEL INHERITANCE
Aim :
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
class add
{
void addition()
{
int a=10;
int b=6;
int x=a+b;
System.out.println("Addition:t"+x);
}
}
class sub extends add
{
void subtraction()
{
int m=15;
int n=7;
int k=m-n;
System.out.println("Subtraction:t"+k);
}
}
class nex8
{
public static void main(String args[])throws IOException
{
15
sub s1=new sub();
s1.addition();
s1.subtraction();
}
}
Output:
Result:
16
EX:No-9 EXCEPTION CLASS
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
class nex9
{
public static void main(String args[])throws IOException
{
int a,b,c;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s1=br.readLine();
a=Integer.parseInt(s1);
String s2=br.readLine();
b=Integer.parseInt(s2);
String s3=br.readLine();
c=Integer.parseInt(s3);
try
{
if(b==0)
{
ArithmeticException a1=new ArithmeticException();
throw a1;
}
else
{
int d=a+b/c;
System.out.println(d);
}
}
17
catch(ArithmeticException e)
{
System.out.println(e);
}
System.out.println("Welcome to Java");
}
}
Output:
Result:
18
EX:No-10 THREAD
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.*;
class thr1 extends Thread
{
public void run()
{
for(int i=0;i<=5;i++)
{
System.out.println("Good Morning");
}
}
}
class thr2 extends Thread
{
public void run()
{
for(int i=0;i<=5;i++)
{
System.out.println("Hello");
}
}
}
class thr3 extends Thread
{
public void run()
{
for(int i=0;i<=5;i++)
{
System.out.println("Welcome");
}
}
}
19
class nex10
{
public static void main(String args[])throws IOException
{
thr1 t1=new thr1();
thr2 t2=new thr2();
thr3 t3=new thr3();
t1.start();
t2.start();
t3.start();
}
}
Output:
Result:
20
EX:No-11 BYTE STREAM CLASS
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using Interpreter.
* Stop the Program.
Program:
import java.io.FileOutputStream;
import java.io.IOException;
class nex11
{
public static void main(String args[])
{
try
{
FileOutputStream fout=new FileOutputStream("ja.txt");
String s= "Welcome to JAVA!";
byte b[] = s.getBytes();
fout.write(b);
fout.close();
}
catch (IOException e)
{
System.out.println(e);
}
}
}
21
Output:
Result:
22
EX:No-12 MOUSE EVENT
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using appletviewer browser (“appletviewer filename.java”).
* Applet window will be opened.
* The output also displayed on the applet window.
* Stop the Program.
Program:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class nex12 extends Applet implements MouseListener,
MouseMotionListener
{
String message = "";
public void init()
{
setBackground(Color.YELLOW);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
g.drawString(message, 50, 50);
}
public void mouseEntered(MouseEvent me)
{
setBackground(Color.PINK);
message = "Mouse Entered: (" + me.getX() + ", " + me.getY() + ")";
repaint();
}
public void mouseExited(MouseEvent me)
{
23
setBackground(Color.RED);
message = "Mouse Exited: (" + me.getX() + ", " + me.getY() + ")";
repaint();
}
public void mouseClicked(MouseEvent me)
{
setBackground(Color.CYAN);
message = "Mouse Clicked: (" + me.getX() + ", " + me.getY() + ")";
repaint();
}
public void mousePressed(MouseEvent me)
{
setBackground(Color.MAGENTA);
message = "Mouse Pressed: (" + me.getX() + ", " + me.getY() + ")";
repaint();
}
public void mouseReleased(MouseEvent me)
{
setBackground(Color.GREEN);
message = "Mouse Released: (" + me.getX() + ", " + me.getY() + ")";
repaint();
}
public void mouseMoved(MouseEvent me)
{
setBackground(Color.ORANGE);
message = "Mouse Moved: (" + me.getX() + ", " + me.getY() + ")";
repaint();
}
public void mouseDragged(MouseEvent me)
{
setBackground(Color.GRAY);
message = "Mouse Dragged: (" + me.getX() + ", " + me.getY() + ")";
repaint();
}
}
/*<APPLET CODE="nex12.class" WIDTH="300" HEIGHT="300">
</APPLET>*/
24
Output:
Result:-
25
EX:No-13 DISPLAY BASIC SHAPES
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using appletviewer browser (“appletviewer filename.java”).
* Applet window will be opened.
* The output also displayed on the applet window.
* Stop the Program.
Program:
import java.awt.*;
import java.applet.*;
public class nex13 extends Applet
{
public void paint(Graphics g)
{
g.drawOval(50,50,75,75);
g.drawRect(130,130,100,100);
g.drawRoundRect(200,250,150,150,50,50);
g.drawArc(280,280,300,290,0,90);
g.drawOval(400,150,80,120);
Color c1=new Color(0,255,0);
g.setColor(c1);
g.fillOval(50,50,75,75);
g.fillRect(130,130,100,100);
g.fillRoundRect(200,250,150,150,50,50);
g.fillArc(280,280,300,290,0,90);
g.fillOval(400,150,80,120);
}
}
/*<applet code="nex13.class" width=800 height=800>
</applet>*/
26
Output:
Result:-
27
EX:No-14 CALCULATOR
Aim:
Procedure:
* Open the notepad.
* Type the Program and save “ filename.java ”
* Open the Command Prompt and set path.
* Compile the Program using javac.
* Run the Program using appletviewer browser (“appletviewer filename.java”).
* Applet window will be opened.
* The output also displayed on the applet window.
* Stop the Program.
Program:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class nex14 extends Applet implements ActionListener
{
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16;
String s1="",s2;
Frame f;Panel p2;
TextField t;int n1,n2;
public void init()
{
setLayout(new BorderLayout());
t=new TextField();
p2=new Panel();
p2.setLayout(new GridLayout(4,4));
b1=new Button("1"); b1.addActionListener(this);
b2=new Button("2"); b2.addActionListener(this);
b3=new Button("3"); b3.addActionListener(this);
b4=new Button("+"); b4.addActionListener(this);
b5=new Button("4"); b5.addActionListener(this);
b6=new Button("5"); b6.addActionListener(this);
b7=new Button("6"); b7.addActionListener(this);
28
b8=new Button("-"); b8.addActionListener(this);
b9=new Button("7"); b9.addActionListener(this);
b10=new Button("8"); b10.addActionListener(this);
b11=new Button("9"); b11.addActionListener(this);
b12=new Button("*"); b12.addActionListener(this);
b13=new Button("c"); b13.addActionListener(this);
b14=new Button("0"); b14.addActionListener(this);
b15=new Button("/"); b15.addActionListener(this);
b16=new Button("="); b16.addActionListener(this);
add(t,"North");
p2.add(b1);p2.add(b2);p2.add(b3);p2.add(b4);
p2.add(b5);p2.add(b6);p2.add(b7);p2.add(b8);
p2.add(b9);p2.add(b10);p2.add(b11);p2.add(b12);
p2.add(b13);p2.add(b14);p2.add(b15);p2.add(b16);
add(p2);
}
public void actionPerformed(ActionEvent e1)
{
String str=e1.getActionCommand();
if(str.equals("+")||str.equals("-")||str.equals("*")||str.equals("/"))
{
String str1=t.getText();
s2=str;
n1=Integer.parseInt(str1);
s1="";
}
else if(str.equals("="))
{
String str2=t.getText();
n2=Integer.parseInt(str2);
int sum=0;
if(s2=="+")
sum=n1+n2;
else if(s2=="-")
sum=n1-n2;
else if(s2=="*")
sum=n1*n2;
else if(s2=="/")
sum=n1/n2;
String str1=String.valueOf(sum);
t.setText(""+str1);
s1="";
}
29
else if(str.equals("c"))
{
t.setText("");
}
else
{
s1+=str;
t.setText(""+s1);
}
}
}
/*<applet code="nex14.class" height=300 width=300>
</applet>*/
Output:
Result:-

More Related Content

DOCX
Akutansi manajemen abc &amp; abm
PPTX
Using MongoDB with the .Net Framework
PPT
Akuntansi mjm bab xiv
PDF
Modul bahan-ajar-kecerdasan-buatan-ptiik-final
PPTX
Taking your side effects aside
PDF
Algoritma dan Struktur Data - Queue
PDF
Core java pract_sem iii
PDF
Akutansi manajemen abc &amp; abm
Using MongoDB with the .Net Framework
Akuntansi mjm bab xiv
Modul bahan-ajar-kecerdasan-buatan-ptiik-final
Taking your side effects aside
Algoritma dan Struktur Data - Queue
Core java pract_sem iii

Similar to Java practical N Scheme Diploma in Computer Engineering (20)

DOC
CS2309 JAVA LAB MANUAL
DOCX
PDF
Java Practical File Diploma
DOC
Practical java
DOCX
Java file
DOCX
Java file
ODT
Java practical
DOCX
Description 1) Create a Lab2 folder for this project2.docx
PDF
Sam wd programs
PPTX
Lab101.pptx
PDF
Java for android developers
DOC
Java final lab
DOCX
Java practical
PPTX
Lab01.pptx
PDF
Lab exam question_paper
PPT
M251_Meeting 7 (Exception Handling and Text IO).ppt
PDF
PSI 3 Integration
PPTX
Understanding java streams
PDF
Microsoft word java
DOCX
Wap to implement bitwise operators
CS2309 JAVA LAB MANUAL
Java Practical File Diploma
Practical java
Java file
Java file
Java practical
Description 1) Create a Lab2 folder for this project2.docx
Sam wd programs
Lab101.pptx
Java for android developers
Java final lab
Java practical
Lab01.pptx
Lab exam question_paper
M251_Meeting 7 (Exception Handling and Text IO).ppt
PSI 3 Integration
Understanding java streams
Microsoft word java
Wap to implement bitwise operators
Ad

Recently uploaded (20)

PDF
Business Ethics Teaching Materials for college
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Basic Mud Logging Guide for educational purpose
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Institutional Correction lecture only . . .
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
RMMM.pdf make it easy to upload and study
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
Business Ethics Teaching Materials for college
STATICS OF THE RIGID BODIES Hibbelers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Basic Mud Logging Guide for educational purpose
TR - Agricultural Crops Production NC III.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Renaissance Architecture: A Journey from Faith to Humanism
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Classroom Observation Tools for Teachers
Institutional Correction lecture only . . .
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
RMMM.pdf make it easy to upload and study
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
01-Introduction-to-Information-Management.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Ad

Java practical N Scheme Diploma in Computer Engineering

  • 1. 1 Java practical N Scheme Experiments Java programming path setting ➢ Open Notepad type the java program. ➢ Save the program using Filename .java ➢ Open command Prompt ➢ Set the path. ➢ Compile java program using the command javac filename.java ➢ Run the Program using the command java file name ➢ Give the inputs and verify the outputs
  • 2. 2 Ex:No-1 CONVERT CELSIUS TO FAHRENHEIT Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; class nex1 { public static void main(String str[]) { float f,fahren,celsius; celsius=24; fahren=((celsius*9)/5)+32; System.out.println("Temperature in fahrenheit :"+fahren); } } Output: Result:
  • 3. 3 EX:N0-2 FIND LARGEST NUMBER Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; class nex2 { public static void main(String str[])throws IOException { int a,b; InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); String s1=br.readLine(); a=Integer.parseInt(s1); String s2=br.readLine(); b=Integer.parseInt(s2); if(a>b) { System.out.println("a is greater"); } else { System.out.println("b is greater"); } } }
  • 5. 5 EX:No-3 FACTORIAL NUMBERS Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; class nex3 { public static void main(String str[])throws IOException { int n,i,fact; InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); String s1=br.readLine(); n=Integer.parseInt(s1); fact=1; for(i=1;i<=n;i++) { fact=fact*i; System.out.println("Factorial:t"+fact); } } }
  • 7. 7 EX:No-4 VECTOR CLASS AND METHODS Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; import java.util.*; public class vec4 { public static void main(String args[])throws IOException { int len,cap; Vector<String> vec = new Vector<String>(); System.out.println("Enter Add Elementsn"); vec.add("Tiger"); vec.add("Lion"); vec.add("Dog"); vec.add("Elephant"); len=vec.size(); System.out.println("SIZE:t"+len); cap=vec.capacity(); System.out.println("CAPACITY:t"+cap); vec.addElement("Rat"); vec.addElement("Cat"); vec.addElement("Deer"); System.out.println("Elements are: "+vec); len=vec.size(); System.out.println("SIZE:t"+len); cap=vec.capacity(); System.out.println("CAPACITY:t"+cap); } }
  • 9. 9 EX:No-5 PALINDROME OR NOT Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; class nex5 { public static void main(String str[])throws IOException { int strln; InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); String s1=br.readLine(); s1="amma"; String s2=""; strln=s1.length(); for(int i=(strln-1);i>=0;--i) { s2=s2+s1.charAt(i); } if(s1.toLowerCase().equals(s2.toLowerCase())) { System.out.println("tis a palindrome"); } else { System.out.println("tis not palindrome"); } } }
  • 11. 11 EX:No-6 STUDENT MARKSHEET USING CONSTRUCTOR Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; import java.util.Scanner; public class Student { private String name; private int eng; private int hn; private int mts; private double total; private double avg; public void accept() { Scanner in = new Scanner(System.in); System.out.print("Enter student name: "); name = in.nextLine(); System.out.print("Enter marks in English: "); eng = in.nextInt(); System.out.print("Enter marks in Hindi: "); hn = in.nextInt(); System.out.print("Enter marks in Maths: "); mts = in.nextInt(); } public void compute() { total = eng + hn + mts; avg = total / 3.0; }
  • 12. 12 public void display() { System.out.println("Name: " + name); System.out.println("Marks in English: " + eng); System.out.println("Marks in Hindi: " + hn); System.out.println("Marks in Maths: " + mts); System.out.println("Total Marks: " + total); System.out.println("Average Marks: " + avg); } public static void main(String args[]) { Student ss = new Student(); ss.accept(); ss.compute(); ss.display(); } } Output: Result:
  • 13. 13 EX:No-7 DISPLAY RADIUS OF A CIRCLE USING COMMAND LINE Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; class nex7 { public static void main(String args[]) { double radius=Double.parseDouble(args[0]); System.out.println("Area: "+(22/7 * radius * radius)); System.out.println("Perimeter: "+(2 * 22/7 * radius)); } } Output: Result:
  • 14. 14 EX:No-8 MULTI LEVEL INHERITANCE Aim : Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; class add { void addition() { int a=10; int b=6; int x=a+b; System.out.println("Addition:t"+x); } } class sub extends add { void subtraction() { int m=15; int n=7; int k=m-n; System.out.println("Subtraction:t"+k); } } class nex8 { public static void main(String args[])throws IOException {
  • 16. 16 EX:No-9 EXCEPTION CLASS Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; class nex9 { public static void main(String args[])throws IOException { int a,b,c; InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); String s1=br.readLine(); a=Integer.parseInt(s1); String s2=br.readLine(); b=Integer.parseInt(s2); String s3=br.readLine(); c=Integer.parseInt(s3); try { if(b==0) { ArithmeticException a1=new ArithmeticException(); throw a1; } else { int d=a+b/c; System.out.println(d); } }
  • 18. 18 EX:No-10 THREAD Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.*; class thr1 extends Thread { public void run() { for(int i=0;i<=5;i++) { System.out.println("Good Morning"); } } } class thr2 extends Thread { public void run() { for(int i=0;i<=5;i++) { System.out.println("Hello"); } } } class thr3 extends Thread { public void run() { for(int i=0;i<=5;i++) { System.out.println("Welcome"); } } }
  • 19. 19 class nex10 { public static void main(String args[])throws IOException { thr1 t1=new thr1(); thr2 t2=new thr2(); thr3 t3=new thr3(); t1.start(); t2.start(); t3.start(); } } Output: Result:
  • 20. 20 EX:No-11 BYTE STREAM CLASS Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using Interpreter. * Stop the Program. Program: import java.io.FileOutputStream; import java.io.IOException; class nex11 { public static void main(String args[]) { try { FileOutputStream fout=new FileOutputStream("ja.txt"); String s= "Welcome to JAVA!"; byte b[] = s.getBytes(); fout.write(b); fout.close(); } catch (IOException e) { System.out.println(e); } } }
  • 22. 22 EX:No-12 MOUSE EVENT Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using appletviewer browser (“appletviewer filename.java”). * Applet window will be opened. * The output also displayed on the applet window. * Stop the Program. Program: import java.applet.*; import java.awt.*; import java.awt.event.*; public class nex12 extends Applet implements MouseListener, MouseMotionListener { String message = ""; public void init() { setBackground(Color.YELLOW); addMouseListener(this); addMouseMotionListener(this); } public void paint(Graphics g) { g.drawString(message, 50, 50); } public void mouseEntered(MouseEvent me) { setBackground(Color.PINK); message = "Mouse Entered: (" + me.getX() + ", " + me.getY() + ")"; repaint(); } public void mouseExited(MouseEvent me) {
  • 23. 23 setBackground(Color.RED); message = "Mouse Exited: (" + me.getX() + ", " + me.getY() + ")"; repaint(); } public void mouseClicked(MouseEvent me) { setBackground(Color.CYAN); message = "Mouse Clicked: (" + me.getX() + ", " + me.getY() + ")"; repaint(); } public void mousePressed(MouseEvent me) { setBackground(Color.MAGENTA); message = "Mouse Pressed: (" + me.getX() + ", " + me.getY() + ")"; repaint(); } public void mouseReleased(MouseEvent me) { setBackground(Color.GREEN); message = "Mouse Released: (" + me.getX() + ", " + me.getY() + ")"; repaint(); } public void mouseMoved(MouseEvent me) { setBackground(Color.ORANGE); message = "Mouse Moved: (" + me.getX() + ", " + me.getY() + ")"; repaint(); } public void mouseDragged(MouseEvent me) { setBackground(Color.GRAY); message = "Mouse Dragged: (" + me.getX() + ", " + me.getY() + ")"; repaint(); } } /*<APPLET CODE="nex12.class" WIDTH="300" HEIGHT="300"> </APPLET>*/
  • 25. 25 EX:No-13 DISPLAY BASIC SHAPES Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using appletviewer browser (“appletviewer filename.java”). * Applet window will be opened. * The output also displayed on the applet window. * Stop the Program. Program: import java.awt.*; import java.applet.*; public class nex13 extends Applet { public void paint(Graphics g) { g.drawOval(50,50,75,75); g.drawRect(130,130,100,100); g.drawRoundRect(200,250,150,150,50,50); g.drawArc(280,280,300,290,0,90); g.drawOval(400,150,80,120); Color c1=new Color(0,255,0); g.setColor(c1); g.fillOval(50,50,75,75); g.fillRect(130,130,100,100); g.fillRoundRect(200,250,150,150,50,50); g.fillArc(280,280,300,290,0,90); g.fillOval(400,150,80,120); } } /*<applet code="nex13.class" width=800 height=800> </applet>*/
  • 27. 27 EX:No-14 CALCULATOR Aim: Procedure: * Open the notepad. * Type the Program and save “ filename.java ” * Open the Command Prompt and set path. * Compile the Program using javac. * Run the Program using appletviewer browser (“appletviewer filename.java”). * Applet window will be opened. * The output also displayed on the applet window. * Stop the Program. Program: import java.awt.*; import java.applet.*; import java.awt.event.*; public class nex14 extends Applet implements ActionListener { Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16; String s1="",s2; Frame f;Panel p2; TextField t;int n1,n2; public void init() { setLayout(new BorderLayout()); t=new TextField(); p2=new Panel(); p2.setLayout(new GridLayout(4,4)); b1=new Button("1"); b1.addActionListener(this); b2=new Button("2"); b2.addActionListener(this); b3=new Button("3"); b3.addActionListener(this); b4=new Button("+"); b4.addActionListener(this); b5=new Button("4"); b5.addActionListener(this); b6=new Button("5"); b6.addActionListener(this); b7=new Button("6"); b7.addActionListener(this);
  • 28. 28 b8=new Button("-"); b8.addActionListener(this); b9=new Button("7"); b9.addActionListener(this); b10=new Button("8"); b10.addActionListener(this); b11=new Button("9"); b11.addActionListener(this); b12=new Button("*"); b12.addActionListener(this); b13=new Button("c"); b13.addActionListener(this); b14=new Button("0"); b14.addActionListener(this); b15=new Button("/"); b15.addActionListener(this); b16=new Button("="); b16.addActionListener(this); add(t,"North"); p2.add(b1);p2.add(b2);p2.add(b3);p2.add(b4); p2.add(b5);p2.add(b6);p2.add(b7);p2.add(b8); p2.add(b9);p2.add(b10);p2.add(b11);p2.add(b12); p2.add(b13);p2.add(b14);p2.add(b15);p2.add(b16); add(p2); } public void actionPerformed(ActionEvent e1) { String str=e1.getActionCommand(); if(str.equals("+")||str.equals("-")||str.equals("*")||str.equals("/")) { String str1=t.getText(); s2=str; n1=Integer.parseInt(str1); s1=""; } else if(str.equals("=")) { String str2=t.getText(); n2=Integer.parseInt(str2); int sum=0; if(s2=="+") sum=n1+n2; else if(s2=="-") sum=n1-n2; else if(s2=="*") sum=n1*n2; else if(s2=="/") sum=n1/n2; String str1=String.valueOf(sum); t.setText(""+str1); s1=""; }