Q1 What is the difference between single threaded application and multithreaded application? What are the benefits of multi-threading. Explain with examples
Q2 Write a java applet that takes your name through a parameter from the HTML file and displays it
Q3 Write a short note on thread synchronization with examples
Q4 WAP that asks the user to input a no. If a no is even then print it else throw a user defined exception
Q5 Draw the state transition diagram of a thread
Q6 Write a java applet that displays 9 squares, one below the other. Every third square must be filled in black?
Q7 What is a package? how is it useful? Demonstrate with example?
Q8 WAP that creates 2 threads. One thread prints your name 1000 times. The other thread calculates the sum of 1st 1000 integers and prints it?
Q9 Draw a diagram of the applet life-cycle?
Q10 WAP that asks the user to input 2 string. If the strings are same it prints "The Strings Are Same" else if throws a user defined exception.
Q11 Explain exception handling features of java with suitable examples?
Q12 What is a java applet? Write a java applet to display "Hello JAVA". Also write the relation between applet and HTML?
Q13 How do you add a class or an interface to a package. Explain with examples?
Q14 Write a short note on Parameter Passing to applets with examples?
1)
Single-threaded Apartments-Single-threaded apartments consist of exactly one thread, so all COM objects that live in a single-threaded apartment can receive method calls only from the one thread that belongs to that apartment. All method calls to a COM object in a single-threaded apartment are synchronized with the windows message queue for the single-threaded apartment's thread. A process with a single thread of execution is simply a special case of this model.
Multithreaded Apartments-Multithreaded apartments consist of one or more threads, so all COM objects that live in an multithreaded apartment can receive method calls directly from any of the threads that belong to the multithreaded apartment. Threads in a multithreaded apartment use a model called free-threading. Calls to COM objects in a multithreaded apartment are synchronized by the objects themselves."
2)
3)
4)Check Number
import java.util.*;
class Check
{
public static void main(String[] args) throws Exception
{
Scanner input=new Scanner(System.in);
System.out.print("Enter a number: ");
int num=input.nextInt();
if(num%2==0){
System.out.println(num+" is even");
}
else{
throw new Exception("Number is odd");
}
}
}
10)
import java.util.*;
class AcceptString
{
public static void main(String[] args) throws Exception
{
Scanner input=new Scanner(System.in);
System.out.print("Enter String1: ");
String st1=input.nextLine();
System.out.print("Enter String2: ");
String st2=input.nextLine();
if(st1.equalsIgnoreCase(st2)){
System.out.println("Strings are same!");
}
else{
throw new Exception("String are not equal!");
}
}
}