soljava
soljava
1.
class Slip1 implements Runnable
{
public void run()
{
try
{
for(char c='A';c<='Z';c++)
{
System.out.println(c);
Thread.sleep(3000);
}
}
catch(Exception e)
{
System.out.println("error");
}
}
}
}
_____________________________________________________________________________
Slip 2
1.
import java.util.*;
public class Friend {
}
_____________________________________________________________________________
___________________________________________________________________________________
_____________________________________________________________
Slip 4
1.
import javax.swing.*;
import java.awt.*;
frame.setSize(300, 100);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
2.
___________________________________________________________________________________
____
Slip 5
1.
import java.util.Enumeration;
import java.util.Hashtable;
System.out.println("Student Directory:");
System.out.println("------------------");
while (mobileNumbers.hasMoreElements() &&
studentNames.hasMoreElements()) {
String mobileNumber = mobileNumbers.nextElement();
String studentName = studentNames.nextElement();
System.out.println("Mobile Number: " + mobileNumber + ", Student
Name: " + studentName);
}
}
}
2.
___________________________________________________________________________________
___
Slip 6
1.
import java.util.*;
import java.io.*;
class Slip1_2
no=Integer.parseInt(br.readLine());
for(i=0;i<no;i++)
element=Integer.parseInt(br.readLine());
ts.add(element);
}
element = Integer.parseInt(br.readLine());
if(ts.contains(element))
System.out.println("Element is found");
else
System.out.println("Element is NOT found");
}
}
2.File1
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public TrafficSignal() {
setBackground(Color.BLACK);
setPreferredSize(new Dimension(200, 600));
if (state == 0) {
g.setColor(Color.RED);
g.fillOval(50, 50, 100, 100);
g.setColor(Color.BLACK);
g.fillOval(50, 250, 100, 100);
g.fillOval(50, 450, 100, 100);
} else if (state == 1) {
g.setColor(Color.BLACK);
g.fillOval(50, 50, 100, 100);
g.setColor(Color.YELLOW);
g.fillOval(50, 250, 100, 100);
g.setColor(Color.BLACK);
g.fillOval(50, 450, 100, 100);
} else {
g.setColor(Color.BLACK);
g.fillOval(50, 50, 100, 100);
g.fillOval(50, 250, 100, 100);
g.setColor(Color.GREEN);
g.fillOval(50, 450, 100, 100);
}
}
}
File2
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
________________________________________________________________________________
Slip 8
1.
class A extends Thread
{
public void run()
{
for(int i=1;i<=10;i++)
{
System.out.println("Covid 19...."+i);
}
}
}
class B extends Thread
{
public void run()
{
for (int i=1;i<=20;i++)
{
System.out.println("LOCKDOWN2020...."+i);
}
}
}
class C extends Thread
{
public void run()
{
for (int i=1;i<=30;i++)
{
System.out.println("VACINATED2021...."+i);
}
}
}
class SetA1
{
public static void main(String args[])
{
A obj=new A();
obj.start();
B obj1=new B();
obj1.start();
C obj2=new C();
obj2.start();
}
}
________________________________________________________________
Slip 9
1.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public ballMover() {
setTitle("Ball Mover");
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ballPanel.startMoving();
}
});
add(ballPanel, BorderLayout.CENTER);
add(startButton, BorderLayout.SOUTH);
}
public BallPanel() {
setBackground(Color.WHITE);
}
2.
___________________________________________________________________________________
__
Slip 13
2.
File 1:
import java.util.Random;
File 2:
public class Main1 {
public static void main(String[] args) {
LifecycleThread thread1 = new LifecycleThread("Thread-1");
LifecycleThread thread2 = new LifecycleThread("Thread-2");
LifecycleThread thread3 = new LifecycleThread("Thread-3");
thread1.start();
thread2.start();
thread3.start();
}
}
___________________________________________________________________________________
Slip 15
1.
File 1:
class ThreadPriority extends Thread {
public ThreadPriority(String name) {
super(name);
}
@Override
public void run() {
System.out.println("Thread Name: " + Thread.currentThread().getName());
System.out.println("Thread Priority: " +
Thread.currentThread().getPriority());
}
}
File 2:
public class Main2 {
public static void main(String[] args) {
ThreadPriority thread1 = new ThreadPriority("Thread-1");
ThreadPriority thread2 = new ThreadPriority("Thread-2");
thread1.setPriority(Thread.MAX_PRIORITY);
thread2.setPriority(Thread.NORM_PRIORITY);
thread1.start();
thread2.start();
}
}
___________________________________________________________________________________
__
Slip 17
1.
import java.util.Scanner;
import java.util.TreeSet;
2.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public NumberDisplay() {
setLayout(new FlowLayout());
setSize(300, 100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
System.out.println("Negative integers:");
for (Integer integer : integers) {
if (integer < 0) {
System.out.print(integer + " ");
}
}
scanner.close();
}
}
2.
___________________________________________________________________________
Slip 20
2.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public TempleDrawer() {
setBackground(Color.WHITE);
setPreferredSize(new Dimension(800, 600));
g2d.setColor(Color.BLUE);
g2d.fillRect(200, 400, 400, 100);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
g2d.setColor(Color.GRAY);
g2d.fillRect(220, 300, 50, 100);
g2d.fillRect(530, 300, 50, 100);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
g2d.setColor(Color.DARK_GRAY);
g2d.fillOval(300, 200, 200, 200);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
g2d.setColor(Color.BLACK);
g2d.fillRect(350, 450, 100, 50);
drawing = false;
}
System.out.println("\nSubjects:");
Iterator<String> iterator = subjects.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
scanner.close();
}
}
2.
class SharedBuffer {
private int value;
private boolean empty = true;
producer.start();
consumer.start();
}
}
_________________________________________________________________________
Slip 23
1.
1.File 1
import java.util.Scanner;
2.
import java.util.LinkedList;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Scanner;
thread1.start();
thread2.start();
thread3.start();
}
}
___________________________________________________________________________________
____________________
Slip 29
2.
import java.util.LinkedList;
linkedList.add(10);
linkedList.add(20);
linkedList.add(30);
linkedList.add(40);
linkedList.add(50);
linkedList.removeLast();
System.out.println("LinkedList after deleting last element: " +
linkedList);
System.out.println("Size of LinkedList: " + linkedList.size());
}
}
___________________________________________________________________________________
_________________
Slip 30