Write a program:
1: To create deadlock between two threads.
2: Find out duplicate number between 1 to N numbers.
3. Write a program to find maximum repeated words from
a file.
4. To remove duplicates from sorted array.
5. Simple generics class example with two type
parameters.
6. Write SQL
Query to find second highest salary of Employee
Program: Write a program to create deadlock between
two threads.
Description:
|
Deadlock describes a situation
where two or more threads are blocked forever, waiting for each other.
Deadlocks can occur in Java when the synchronized keyword causes the
executing thread to block while waiting to get the lock, associated with the
specified object. Since the thread might already hold locks associated with
other objects, two threads could each be waiting for the other to release a
lock. In such case, they will end up waiting forever.
|
Code:
|
||||
|
||||
Program: Find out duplicate number
between 1 to N numbers.
|
numbers.add(i);
}
//add
duplicate number into the list
numbers.add(22);
DuplicateNumber
dn = new DuplicateNumber();
System.out.println("Duplicate
Number: "+dn.findDuplicateNumber(numbers));
}
}
Output:
|
Duplicate Number: 22
|
Program: Write a program to find maximum repeated
words from a file.
|
||||||
|
||||||
Program: Write a program to remove
duplicates from sorted array.
|
||||||
|
||||||
|
||||||
Program: Write a simple generics class example with
two type parameters.
Below example shows how to create
a simple generics class with two type parameters. Look at the class
definition, we defined two types of parameters called U & V, seperated by
",". You can define multiple type parameters seperated by
",". Look at sample code for more comments.
|
||||||
|
SQL Query to find second highest
salary of Employee
Answer : There are many ways to
find second highest salary of Employee in SQL, you can either use SQL Join or
Subquery to solve this problem. Here is SQL query using Subquery :
select MAX(Salary) from Employee WHERE Salary NOT IN (select MAX(Salary) from Employee );
No comments:
Post a Comment