JAVA practical Answers 1523-1591
JAVA practical Answers 1523-1591
S,
Rajarshi Shahu Institute of Management,
Aurangabad
Department
Of
Master of Computer Applications
Certificate
This is to certify that Mr. /Miss --------------------------------is
our student of MCA –I semester having a Roll No. -------and has
submitted his /her Practical File on the subject of “JAVA “in the
academic year 2024-2025, as per the requirement of Dr.
Babasaheb Ambedkar Marathwada University, Aurangabad.
External Examiner
INDEX
3 WAP a program to demonstrate the use of Static member and static method
Program:
public class Demo {
System.out.println("Default values.....");
Output:
Default values.....
Val1 = false
Val2 = 0.0
Val3 = 0.0
Val4 = 0
Val5 = 0
Val6 = null
2. WAP a to demonstrate the Function of predefined class scanner
Program:
import java.util.*;
scan.close();
int i = in.nextInt();
double d = in.nextDouble();
in.close();
}
Output:
Name: Abhishek
Age: 23
Salary: 25000.0
3. WAP a program to demonstrate the use of Static member and static method
Program:
class Student{
int rollno;
String name;
college = "BBDIT";
rollno = r;
name = n;
//creating objects
s1.display();
s2.display();
s3.display();
Output:
class Animal{
a.eat();
Program :
class Animal{
String color="white";
String color="black";
void printColor(){
class TestSuper1{
d.printColor();
}}
Output :
black
white
6. WAP to demonstrate the Application of package in Java
Program :
//save by A.java
package pack;
public class A{
//save by B.java
package mypack;
import pack.*;
class B{
obj.msg();
Output:
Hello
7. WAP to demonstrate the implementation of multi-threading using runnable interface
Program :
@Override
t1.start();
System.out.println("Hi");
Output:
Hi
Program:
import javax.swing.*;
class ScrollBarExample
ScrollBarExample(){
s.setBounds(100,100, 50,100);
f.add(s);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
new ScrollBarExample();
}}
Output:
10. WAP to demonstrate the use of dialogue box
import java.awt.*;
import java.awt.event.*;
DialogExample() {
DialogExample.d.setVisible(false);
});
d.add(b);
d.setSize(300,300);
d.setVisible(true);
new DialogExample();
}
Output:
11. WAP to implement Windowcloseevents
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
// class constructor
WindowExample() {
dispose();
});
setLayout (null);
setVisible (true);
// main method
new WindowExample();
}
Output :
12. Write a program to read and write character in file
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
// Main class
throws IOException
String text
"/Users/mayanksolanki/Desktop/demo.docx");
Files.writeString(fileName, text);
System.out.println(file_content);
}
Output:
Welcome to geekforgeeks
Happy Learning!
13. Write a program to use of write and reader classes
class Student{
//defining fields
String name;
System.out.println(s1.name);
Output:
Null
14. write a program to demonstrate the keylistener in java
import java.awt.*;
import java.awt.event.*;
Label l;
TextArea area;
// class constructor
KeyListenerExample() {
l = new Label();
area.addKeyListener(this);
add(l);
add(area);
setLayout (null);
setVisible (true);
}
// overriding the keyPressed() method of KeyListener interface where we set the text of the label when
key is pressed
// overriding the keyReleased() method of KeyListener interface where we set the text of the label when
key is released
// overriding the keyTyped() method of KeyListener interface where we set the text of the label when a
key is typed
// main method
new KeyListenerExample();
Output:
15. write a program to manage arithmetic exception in java
int res = a / b;
// main method
obj.divide(1, 0);
Output:
at ArithmeticException.divide(ArithmeticException.java:6)
at ArithmeticException.main(ArithmeticException.java:16)