Assignmet-3 Aniket
Assignmet-3 Aniket
Program:
import java.io.*;
ANIKET SINGH 1
System.out.println("Thread 2 : "+i);
}
}
}
class thr
{
public static void main(String[] args) {
ANIKET SINGH 2
2. Write a Java Program to Implement Thread by Implement
Runnable Method.
Program:
import java.io.*;
ANIKET SINGH 3
}
class thred
{
public static void main(String[] args) {
ANIKET SINGH 4
Output:
ANIKET SINGH 5
System.out.println("Priority Thread Name
:"+Thread.currentThread().getPriority());
}
Output:
ANIKET SINGH 6
4. Write a Java Program to print “Hello World” in Applet.
Program:
import java.applet.Applet;
import java.awt.*;
ANIKET SINGH 7
5. Write a Java Program to Draw Circle in Applet
Program:
import java.io.*;
import java.applet.Applet;
import java.awt.*;
ANIKET SINGH 8
/*<applet code="cir.class" width="800" height="800">
</applet>*/
Output:
ANIKET SINGH 9
import java.io.*;
import java.applet.Applet;
import java.awt.*;
public class rec extends Applet
{
public void paint(Graphics g)
{
g.drawRect(100,100,400,400);
}
}
/*
<applet code="rec.class" height="1000" width="1000"></applet>
*/
Output:
ANIKET SINGH 10
7. Write a Java Program to Draw Triangle in Applet
Program:
import java.io.*;
import java.awt.*;
import java.applet.Applet;
ANIKET SINGH 11
/*
<applet code="tr.class" height="800" width="800"></applet>
*/
Output:
ANIKET SINGH 12
import java.io.*;
import java.awt.*;
import java.applet.Applet;
/*
<applet code="pant.class" height="800" width="800">
</applet>
*/
Output:
ANIKET SINGH 13
9. Write a Java Program to Draw Smile Face in Applet.
Program:
import java.io.*;
import java.applet.Applet;
import java.awt.*;
ANIKET SINGH 14
{
public void paint(Graphics g)
{
g.drawOval(80,70,150,150);
g.setColor(Color.BLACK);
g.fillOval(120,120,15,15);
g.fillOval(170,120,15,15);
g.drawArc(130,180,50,20,180,180);
}
}
/*
<applet code="smiley.class" height="700" width="800">
</applet>
*/
Output:
ANIKET SINGH 15
10. Write a java Program to implement String buffer all methods.
Program:
import java.io.*;
ANIKET SINGH 16
str.reverse();
System.out.println("After reverse:- " + str);
int length = str.length();
System.out.println("Length of StringBuffer:- " + length);
int capacity = str.capacity();
System.out.println("Capacity of StringBuffer: -" + capacity);
str.setLength(3);
System.out.println("After setLength:- " + str);
str.replace(0, 3, "Dear");
System.out.println("After replace:- " + str);
str.ensureCapacity(30);
System.out.println("Capacity after ensureCapacity:- " + str.capacity());
str.trimToSize();
System.out.println("Capacity after trimToSize:- " + str.capacity());
String s1 = str.toString();
System.out.println("String representation:- " + s1);
}
}
Output:
ANIKET SINGH 17
11. Write a Java Program to implement Singly Link List.
Program:
import java.io.*;
class Node {
int data;
Node next;
class SinglyLinkedList {
private Node head;
ANIKET SINGH 18
public SinglyLinkedList() {
this.head = null;
}
ANIKET SINGH 19
}
Output:
ANIKET SINGH 20