RG Java Finalll
RG Java Finalll
(AFFLIATED TO)
4. Create a class employee which have name, age and address of CO1
employee, include methods getdata() and showdata(), getdata()
takes the input from the user, showdata() display the data in
following format: Name: Age: Address:
11. Write a program to demonstrate the concept of abstract class with CO2
constructor and ``final`` method.
12. Write a program to demonstrate the concept of interface when two CO1
interfaces have unique methods and same data members
17. Write a program creating 2 threads using Runnab le interface. Print CO6
your name in ``run ()`` method of first class and "Hello Java" in
``run ()`` method of second thread.
18. Write a program to use Byte stream class to read from a text file CO5
and display the content on the output screen.
19. Write a program to make use of BufferedStream to read lines from CO5
the keyboard until 'STOP' is typed
21. Write program that uses swings to display combination of RGB CO7
using 3 scrollbars.
22. Write a swing application that uses atleast 5 swing controls CO7
24. Write a java program to insert and update details data in the CO7
database.
25. Write a java program to retrieve data from database and display it CO7
on GUI.
I , Raghav Sharma of BCA 2ND YEAR 1st SHIFT would like to convey my sincere thanks and
gratitude to Ms. Chandni Kohli for her support and assistance in the completing my practical
file on subject named java programming with paper code BCA 272.
I would like to acknowledge that this practical file was completed entirely by me and not by
someone else.
Signature:
This is to certify that JAVA Programming Practical File being submitted is a bonafide work
done by Raghav Sharma Student of BCA 4TH Semester 1st shift in partial fulfilment of the
award of the BCA degree.
She has worked under my guidance and supervision and has fulfilled the requirements of the
file that has been reached the requisite standards.
Ms Chandni Kohli
while(true){
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. Exit");
case 5: System.exit(0);
class Employee {
String name;
int age;
String address;
void getData() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter name: ");
name = scanner.nextLine();
System.out.print("Enter age: ");
age = scanner.nextInt();
scanner.nextLine(); // Consume the remaining newline character
System.out.print("Enter address: ");
address = scanner.nextLine();
}
void showData() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Address: " + address);
}
}
System.out.println("*****Hierarchical Inheritance******");
B b=new B();
b.printA();
b.printB();
System.out.println("");
C c=new C();
c.printA();
c.printC();
System.out.println("");
System.out.println("*****Multilevel Inheritance******");
D d=new D();
d.printA();
d.printC();
d.printD();
}
}
class Polymorphism{
public static void main(String[] args){
System.out.println("");
Vehicle v=new Vehicle();
Vehicle c=new Car();
Vehicle b=new Bus();
v.display();
c.display();
b.display();
}
}
class SavingsAccount {
private String accountNumber;
private double balance;
thread1.start();
thread2.start();
}
}
inputStream.close();
} catch (IOException e) {
System.out.println("an error occurred while reading the file: " + e.getMessage());
}
}
}
frame.getContentPane().add(app.sbar1);
app.sbar2 = new JScrollBar(java.awt.Adjustable.VERTICAL, 127, 1,0,255);
app.sbar2.setBounds(30,20, 10, 200);
app.sbar2.setBackground(Color.green);
app.sbar2.addAdjustmentListener(app);
frame.getContentPane().add(app.sbar2);
app.sbar3 = new JScrollBar(java.awt.Adjustable.VERTICAL, 127, 1,0,255);
app.sbar3.setBounds(50,20, 10, 200);
app.sbar3.setBackground(Color.blue);
app.sbar3.addAdjustmentListener(app);
frame.getContentPane().add(app.sbar3);
// Create a JButton
JButton submitButton = new JButton("Submit");
panel.add(submitButton);
public class Ok {
public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/javapracticalfi le",
"root", "root");
Statement statement = connection.createStatement();
int age;
String name;
Scanner s = new Scanner(System.in);
System.out.println("Enter the name and age: ");
name = s.next();
age = s.nextInt();
String query = "insert into student values('" + name + "', '" + age +"');";
statement.executeUpdate(query);
System.out.println("Succesfully updated the table");
connection.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
public Main() {
setTitle("Database GUI Example");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setLayout(new BorderLayout());
textArea = new JTextArea();
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
add(scrollPane, BorderLayout.CENTER);
}
public void fetchDataFromDatabase() {
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
connection = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
statement = connection.createStatement();
String query = "SELECT * FROM student";
resultSet = statement.executeQuery(query);
StringBuilder result = new StringBuilder();
while (resultSet.next()) {
String name = resultSet.getString("sname");
String age = resultSet.getString("age");
result.append("Name: ").append(name)
.append(", Age: ").append(age)
.append("\n");
}
textArea.setText(result.toString());
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null)