oops
oops
oops
1 Answer All
a What will be the output of the program?
2
class Test {
static int x = 10;
public static void main(String[] args) {
Test t1 = new Test();
Test t2 = new Test();
t1.x = 20;
System.out.print( t1.x + " " + t2.x);
}
}
b Define a class called Account with the following properties and methods:
5
Properties: String name, int accNumber, double accBalance
Methods: void deposit(int amt) and double withdraw(int amt)
Assume that an account needs to have a minimum balance of 500. If an attempt is made to
withdraw, which results in balance going below 500, throw a user defined exception called
MinimumBalanceException. Use throw and throws wherever necessary.
6 Answer any One
a Define LinkedList and ArrayList with one suitable example. Briefly explain the difference
5
between LinkedList and ArrayList.
b Write a JAVA program to capitalize the first letter of each word in an inputted sentence
5
from the keyboard.
7 Answer any One
a Write a java awt or swing program, which create 3 text field and two button labelled as sub
5
and other is div. The program will take the input from the two text filed. When we click the
add and div button it will display the result in the third text field.
b Write a java program that will deal with mouse event handling
5
Silicon Institute of Technology
Silicon Hills, Bhubaneswar
| An Autonomous Institute |
1 Answer All
a Find the output of the following code
1
class Output
{
public static void main(String args[])
{
int a1[ ] = new int[20];
int a2 [ ] = { 1, 2, 3, 4, 5, 6 };
System.out.println(a1.length + " " + a2.length);
}
}
b Find the output of the following code
1
class Test {
static final int a=10;
public static void main(String[] args) {
int x = 20;
System.out.println(x+a);
}
}
c What will be the output?
1
class Test{
public static void main(String []args){
try{
int arr[]={1,2};
arr[2]=11;
System.out.println("Inside try block ");
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("Exception caught "+e);
}
}
}
d What exception type does the following program throw?
1
class Test
{
public static void main(String args[])
{
int s[]={1, 2, 3};
System.out.println(s[3]);
}
}
e Which method is used to change the name of a thread?
1
f Write the different types of Thread priority constants used in java. 1
g What will be the output of the following segment?
1
public class Test{
public static void main(String args[]){
String s1 = new String("Hello");
String s2 = new String("Hello");
System.out.println(s1 == s2);
}
}
h Which method called the first time while an applet is loaded into the memory of a computer?
1
i Which method used to change the foreground colour of the components in awt?
1
j Which of the following package provides many event classes and Listener interfaces for event
1
handling?
i. java.awt
ii. java.awt.Graphics
iii. java.awt.event
iv. None of the above
2 Answer All
a Write a java program that will check the number is prime or composite using function.
3
b What do you mean by polymorphism? Explain the difference between static and dynamic
3
polymorphism.
c Differentiate between thread and process.
3
d Explain the steps involved in applet development.
3
e Write a java program to create a TextArea.
3
3 Answer any One
a Design a class ComplexNum having data members real and img. The class should have a
7
default and parameterized constructor to initialize its data members. It should also have
methods displayCompNumber() to display the complex number (in the format 5+3i for
example), subCompNumber() to subtract two Complex numbers and divCompNumber() to to
devide two complex number. Test these methods by creating main method in another class.
b Design a class Time having data members hour, minute and second. The class should have a
7
parameterized constructor to initialize its data members. It should also have methods
displayTime() to display the time in HH:MM:SS format and addTime() to add two time
objects. Test these methods by creating a main method in another class.
4 Answer any One
a Define an abstract class named as Shape, having data members dimOne and dimTwo. Extend
7
this class to create two concrete classes named as Rectangle and Triangle. Override the
computeArea() method in the sub classes. Invoke the computeArea() method in the main
method of another Driver class through an abstract class reference variable.
b Write a java program to create your own exception which creates insufficient fund exception
7
whenever an account holder in the bank wants to withdraw money greater than that he has in
his account?
5 Answer any One
a Write a Java program to compute the sum of n numbers. Create p number of threads and each
7
thread will add n/p number of elements and update in the shared memory sum. Note updating
of shared memory must be synchronized.
b Write a java program that will create one child thread. The child thread has to display all even
7
numbers between m and n, and the main thread will display all odd numbers between m and n.
6 Answer any One
a Write a JAVA program to find all substrings of a given string.
7
b Write a JAVA program to sort an array of names (strings) as per alphabetical order.
7
7 Answer any One
a What is JDBC? Write a simple java program to display the contents of a table named
7
Student having fields RollNo, Name and Mark of an appropriate data type.
b Write a java awt or swing program, which create 3 text field and one button labelled as sub and
7
other is div. The program will take the input from the two text filed. When we click the add
and div button it will display the result in the third text field.
Sillcon
{**
Silicon Institute of TechnologY
Silicon Hills, Bhubaneswar
/; t: y t.rt : t l I i, tz'<:: f it ; *y
s I An Autonomous Institute I
I Answer All
a What will be the output of the following code if we provide command-line argument as 2
java Test This is a command line program
class Test{
public static void main(String args[]){
System. out.println(args [0] ) ;
)
)
b Whu, will be the output of the following code? 2
class A
{
protected void msg0
{
System" out.println( "Hello j ava" ) ;
)
)
public class Simple extends A
{
void msg0 { System.out.println("Hello j ava"); }
)
class Test
{
public static void main(String args[])
{
Simple obj:new SimpleQ;
obj.msg0;
)
)
c Which method is used to set the priority of a thread? 2
d class Char 2
{
public static void main(String args[])
{
char ch1:'Y';
tnt ch2:7;
String s:"Hello";
System.out.println(s+ch1 + ch2);
)
)
e Create an awt button, which is labeled as red. 2
[P, T O.]
2 Answer anY Two
2.5
a Differentiate between static and non-static methods in java.
2.5
b Differentiate between implicit and explicit type casting with a suitable example'
2.s
c Write a lavaprogram that will check the number is prime or composite'
3 Answer anY Two
2.5
a Differentiate between method overloading and method overriding'
b whut is the purpose of using the final key,nvord in exception handling? Write a program to 2.5
!
4 Answer anY Two
a write 2.5
a javaapplet that draw an equilateral triangle
b Differentiate between notify( ) and notiffAll( ) methods used for multithreading' 2.s
c Write down the interface used for mouse event handling and also explain the methods 2.5
** i< ** *< ****** X< ** {< * i< ******** i<,F X< * + * r< {< X< r< * {< *,F
Silicon Institute of Technology
Silicon Hills, Bhubaneswar
| An Autonomous Institute |
1 Answer All
a What will be the output of the following code if we provide command line argument as :
1
java Test This is a command Line program
class Test{
public static void main(String args[]){
System.out.println(args[0]);
}
}
b Find the output of the following code
1
class Output
{
public static void main(String args[])
{
int a1[ ] = new int[20];
int a2 [ ] = { 1, 2, 3, 4, 5, 6 };
System.out.println(a1.length + " " + a2.length);
}
}
c What will be the output?
1
class Test{
public static void main(String []args){
try{
int arr[]={1,2};
arr[2]=11;
System.out.println("Inside try block ");
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("Exception caught "+e);
}
}
}
d What exception type does the following program throw?
1
class Test
{
public static void main(String args[])
{
int s[]={1, 2, 3};
System.out.println(s[3]);
}
}
e Write the two standard techniquse used for synchronization
1
f What is the default priority of a thread?
1
g What will be the output?
1
class LogicalCompare{
public static void main(String args[]){
String str1 = new String("OKAY");
String str2 = new String(str1);
System.out.println(str1 == str2);
}
}
h How many objects will be created for the following code segments?
1
String a = new String("Silicon");
String b = new String("Silicon");
String c = "Silicon";
String d = "Silicon";
i Which method used to change the foreground colour of the components in awt?
1
j Which of the following package provides many event classes and Listener interfaces for
1
event handling?
i. java.awt
ii. java.awt.Graphics
iii. java.awt.event
iv. None of the above
2 Answer All
a Write a java program, that read an array of integres. Define a function as, boolean
3
linearSearch( int arr[] , int item) , which will return true if the element present in the array
false otherwise.
b Explain the uses of “super” keyword with some suitable example.
3
c Discuss the different ways of thread synchronization.
3
d Write a program to reverse a string.
3
e Write a java program to create aTexField.
3
3 Answer any One
a Explain the features of object oriented programming.
7
b Design a class Point with data members as xCo and yCo. The class should have a
7
parameterized constructor to initialize its data members. Define a method
distanceBetPoints() which return the distance between two points. Define another method
isTriangle which takes three Point class object as parameter and returns true if the three
points form a triangle otherwise false.
4 Answer any One
a Write a java program to create your own exception which creates insufficient fund
7
exception whenever an account holder in the bank wants to withdraw money greater than
that he has in his account?
b Write a java program that will have a user defend exception called AgeRganeException.
7
Your program should read the age of a person, if the entered age is either less than 0 or
greater than 100 the program should throw AgeRangeException.
5 Answer any One
a Write a Java program to compute the sum of n numbers. Create p number of threads and
7
each thread will add n/p number of elements and update in the shared memory sum. Note
updating of shared memory must be synchronized.
b Write a Java thread program to search the minimum number in a given array. The program
7
should create four number of threads, each thread should search for the minimum element
in a block of N/4 elements concurrently. This introduces the concept of a Synchronized
block. Each thread should find the minimum element in a block of N/4 elements and
compare to the global minimum element. When all the threads are done, the global variable
should contain the minimum element. It uses a Synchronized block to make sure that only
one thread is updating the global minimum variable at any given time.
6 Answer any One
a Write a java applet that will display the smiling face.
7
b Write a JAVA program to find all substrings of a given string.
7
7 Answer any One
a Design an AWT GUI application (called AWT Counter) as shown in the figure. Each time
7
the "Count" button is clicked, the counter value should be increased by 1 and each time the
Reset button is clicked the counter value should be reset to zero.
b Write a java program to create three color buttons (with caption “Black”, “Red” and
7
“Green”) and a text in a frame. Initially the text should be displayed in yellow color. When
the user clicks on a particular color button the text should be changed to that particular
color