Download 2014

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
060010503-Advanced Java 2014
Unit-1
String and Collections
Short Answer Questions
1. Name the packageused for making use of StringTokenizer class.
2. State any two ways to create object of String class.
3. String s=new String(); What will be the result of given code?
4. Write a step to create a string from a given character array.
5. If a user wants to perform string comparison ignoring case, Name the method that will provide solution to user.
6. How we can copy one String object in another one?
7. A user is interested in comparing a specific region from a string with another specific region of string, which
method will provide solution for the specified problem?
8. Assume that a user wants to determine whether the given sting begin or end with a specified string, which
method should a user use inorder to get the solution?
9. Write any one difference between Array and Collection.
10. What are the two ways to iterate the elements of a collection?
11. How ArrayList differs from HashMap?
12. List any two interfaces of Java collections framework.
13. Distinguish two points between Enumeration and Iterator interface.
14. What is map interface in Java?
15. State two differences between Map and HashMap.
16. For the below given program:
//Program written in Java
import java.util.*;
class demo{
public static void main(String[] args){
List<String> lst=new ArrayList<String>();
String s="Two";
lst.add("One");
lst.add(s);
lst.add(s+s);
System.out.println(lst.size());
System.out.println(lst.contains(“one”));System.out.println(lst.contains("TwoTwo"))
;
lst.remove("Two");
System.out.println(lst);
System.out.println(lst.size());}
}
1. State the purpose of line:
List<String> lst=new ArrayList<String>();
and
lst.remove("Two");
2. What will be the result if we executes following line of code?
Lst.add(4,”Hiii”);
Long Answer Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
“String is an immutable object”: Justify the statement.
How does String class differ from the StringBuffer class? Discuss it with suitable examples.
Analyse the impact of String class in the usage of memory when a value of same variable is modified three times.
Create a scenario where string concatenation is done with float datatype.
Explain append() and insert() method of String class with suitable example.
How to do string concatenation with other data type? Discuss it with suitable example.
Explain equal() and == with suitable example.
How one can check whether two string object is referring to same reference or not?
Explain any four String constructors with proper prototype and example.
Compare and contrast delete() and deleteCharAt() method.
Explain replace() and trim() method of String class with suitable example.
Ms. Anuja Vaidya
Page 1
060010503-Advanced Java 2014
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
How to set character value within StringBuffer? Explain it with suitable example.
Validate the significance of ‘Collections’ in creating dynamic data structurs.
What are collections? How do they help in creating dynamic data structures?
Explain any four basic interfaces of Java collections framework.
Validate the significance of StringBuffer class.
What makes Enumeration different from Iterator interface?
Explain at least five StringBuffer class methods using syntax and proper example.
Explain any five methods of List interface with proper syntax and example.
How one can store any detail in key value type of data? Explain with example.
Explain StringTokenizer class with its all methods with proper syntax.
1.
Given: String test = "a1b2c3"; String[] tokens = test.split("\\d"); for(String s: tokens) System.out.print(s + " ");
What is the result?
A. b c
B. 1 2 3
C. a1b2c3
D. a1 b2 c3
Select an appropriate option from given choices
2. Consider the following code
public String mystery(String s)
{
String s1 = s.substring(0,1);
String s2 = s.substring(1, s.length() - 1);
String s3 = s.substring(s.length() - 1);
if (s.length() <= 3)
return s3 + s2 + s1;
else
return s1 + mystery(s2) + s3;
}
What is the output of
System.out.println(mystery("DELIVER"));
A. DELIVER
B. DEVILER
C. REVILED
D. RELIVED
E. DLEIEVR
3. Consider the following code and give output of it.
if("String".toString() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
4.
A.
B.
C.
D.
Print “Equal”.
Print “Not Equal”.
Compiler error.
Runtime error.
Consider the following code
public void twist(String[] w)
{
String temp = w[0].substring(0, 1);
w[0] = w[1].substring(0, 1) + w[0].substring(1);
w[1] = temp + w[1].substring(1);
}
What is the output of the following code segment?
Public static void main(String args[])
Ms. Anuja Vaidya
Page 2
060010503-Advanced Java 2014
{
String[] words = {"HOW", "NEAT"};
twist(words):
System.out.println(words[0] + " " + words[1]);
}
5.
6.
7.
8.
A.
B.
C.
D.
NOW HEAT
Syntax Error
HOW NEAT
Runtime Error
A.
B.
C.
D.
Print “Equal”.
Print “Not Equal”.
Compiler error
Runtime error
A.
B.
C.
D.
Syntax Error
BARBARA
ARBABAR
BARABAR
A.
B.
C.
D.
Print “Equal”.
Print “Not Equal
Compilation error
Runtime error
Consider the following code and give output of it.
if("String".trim() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
What is the output of the following code?
String barb = "BARBARA";
scramble(barb);
System.out.println(barb);
The method scramble is defined as follows:
public String scramble(String str)
{
if (str.length() >= 2)
{
int n = str.length() / 2;
str = scramble(str.substring(n)) + str.substring(0, n);
}
return str;
}
Consider the following code and give output of it.
public class M {
public static void main(String[] args) {
if("String ".trim() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
}
}
A String Class
A. is final
B. is public
Ms. Anuja Vaidya
Page 3
9.
060010503-Advanced Java 2014
C.
D.
is Serializable
has a constructor which takes a StringBuffer Object as an argument
A.
B.
C.
D.
the code will compile an print “Equal”.
the code will compile an print “Not Equal”.
the code will cause a compiler error
the code will cause a runtime error
B.
C.
String string name
String string class;
Read this piece of code carefully and give output of it.
if( "STRING".toUpperCase() == "STRING")
System.out.println("Equal");
else
System.out.println("Not Equal");
10. The syntax to declare a string is as follow:
A. String string_name;
D.
String String_class;
11. It refers to an object in Java, which has a sequence of characters.
A. Array
B.
C.
D.
String
Vector
None of these
12. String are always specified in
A. braces
B.
C.
D.
double quotes
single quotes
square brackets ([])
13. String class is more commonly used to
A. display errors
B.
C.
D.
display messages
display programs
none of these
14. Consider the following code snippet
String river = new String(“Columbia”);
System.out.println(river.length());
What is printed?
A.
B.
C.
D.
6
8
7
9
15. String class is more commonly used to display
A. character
B. text
C. messages
Ms. Anuja Vaidya
Page 4
D.
object
060010503-Advanced Java 2014
State whether below given statements are ‘True’ or ‘False’
1.
2.
3.
4.
5.
Every string user create is actually an object of type String.
Objects of type String are unchallengeable.
Java supports “+” operator to concatenate strings.
To create an empty string we can write “String s=new String()”.
Following code will create string with the initialization of “abc”.
char c[ ] = {‘a’,’b’,’c’};
String s=new String(c);
6. Following code will display “cd”.
char c[ ] = {‘a’,’b’,’c’,’d’,’e’,’f’};
String s=new String(c,2,3);
System.out.println(s);
7. In equals() method the comparison is case sensitive.
8. Suppose executing the following code, assigning “B” value to string will result in stringA being changed to “B”
as well.
String stringA=”A”;
String string=”stringA”;
StringB=”B”;
9. The startsWith() method determines whether a given string begins with a specified string.
10. Suppose we have the following code, so stringA.equals(stringB) returns the same result as stringA==string.
String stringA=”A”;
String string=stringA;
11. StringBuffer class is not thread-safe because when multiple threads access the same class instance, it is not
properly synchronized.
12. Whenever user create String object from an array, the String will be unchanged if user modify the contents of
the array after creating the string.
13. When using Iterator class to go through each member inside a collection, it is legal to add extra member into
the collection at the same time.
14. The == operator compares two object references to see where they refer to the same instance.
15. When using Iterator class to go through each member in the collection, there is no way to move backward to
get the previous member.
16. Vector class provides a way to dynamically increase the size if required.
17. Only object value can be used as a key for Hashtable.
18. When adding primitive types into a collection, the Java runtime regardless of the version of Java automatically
converts the primitive type to appropriate object type.
19. Comparable interface must be implemented by any object that need to be stored in a collection.
20. I t is legal to add different types of object into the collection without generic type presents.
Fill in the blanks with an appropriate answer
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
In Java Programming Language, String is an ---------------------.
String can be created using ------------------ class.
String object in Java is a ----------------------- object which means every time a new instance of String will be
created.
The method --------------------- in string class is used to get the length of the String.
Operator ------------------- or method -------------------- can be used to concatenate two string together.
To compare two strings for equality --------------------- method is used.
To extract a single character from a string ------------------ method is used.
To extract more than one character from a string ------------------ method is used.
To determine whether the string ends with a specified string --------------- is used.
To perform comparison that ignores case difference, --------------------- is used.
-------------------- class is used to split the given string into pieces using delimiters enabling the retrieval of part
of the string for further processing.
If you want to convert all the characters in a String object into character array ------------------ is used.
To searches for the first occurrence of a character or substring --------------- method is used.
---------------- class represent growable and writeable character sequences.
The ------------------ package contains the collections framework, legacy collection classes, event model, date and
time facilities, internationalization, and miscellaneous utility classes.
Ms. Anuja Vaidya
Page 5
060010503-Advanced Java 2014
16. An ---------------- is an object that has methods to traverse through the collection classes.
17. The ------------------ class represents a last-in-first-out collection of objects.
18. If developers try to modify the collection when iterating the whole collections, the system will throw --------------------.
19. Adding primitive types to collections will result converting the primitive types to their ------------------ class.
20. If the object in a collection needs to be sorted, it can implement ------------------ interface.
Unit-2
Multithreaded Programming
Short Answer Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Which are the 2 different ways to support multithreading environment in Java?
What are the two ways to create a thread?
How one can create another thread within main function?
List any 4 methods available in runnable interface.
What is the purpose of using isAlive() method?
In which class isAlive() method is available?
Which methods are used for inter thread communication?
What is the mechanism defined by Java for the resources to be used by only one thread at a time?
What is the procedure to own the monitor by many threads?
What is the unit for 1000 in the following statement ob.sleep(1000);?
What is the data type for the parameter of the sleep() method?
What is the values for the following level?
Max Priority, min-priority,normal-priority
Which is the default thread at the time of starting the program?
Which priority thread can prompt the lower priority thread?
How many threads at a time can access a monitor?
What are all the states associated with the thread?
Which method waits for the thread to die?
Garbage collector thread belongs to which priority?
What is mean by time slicing or time sharing?
What is mean by daemon thread in Java runtime, what is its role?
Long Answer Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
Describe synchronization in respect to multithreading in detail.
Can two threads call two different synchronized instance methods of an object? Justify the answer.
Explain two ways of using thread with an appropriate example.
What is the difference between Thread.start() and Thread.run() method?
Why do we need run() and start() method both? Can we achieve with it only run method? Why?
Can we synchronize the constructor of a Java class? Justify the answer.
What is thread local class? How can it be used?
Analyze the preventive measures to be taken for preventing deadlock.
When invalidMonitorStateException is thrown? Why?
Compare and contrast sleep(),suspend() and wait()?
What happens when we make static method as synchronized?
Can a thread call non-synchronized instance method of an object when a synchronized method is being
executed? Justify the answer.
Identify the role of thread pool.
Can we synchronize the run method? If yes then what will be the behaviour? Justify the answer.
Explain different ways of creating a thread with suitable example? Which one would you prefer and why?
Briefly explain high level state of Threads.
Compare and contrastyield () and sleep ().
Explain thread priority.
Select an appropriate option from given choices
1.
What is the name of the method used to start a thread execution?
A. Init();
Ms. Anuja Vaidya
Page 6
060010503-Advanced Java 2014
2.
3.
B. Start();
C. Run();
D. Resume();
Which two are valid constructors for threads?
A. Thread(Runnable r, String name);
B. Thread();
C. Thread(int Priority);
D. Thread(Runnable r,ThreadGroup g);
E. Thread(Runnable r,int Priority);
Which are the three methods of the object class?
1. Notify();
2. notifyAll();
3. isInturrupted();
4. Synchronized();
5. Interrupt();
6. Wait(long millisecond);
7. Sleep(long milisecond);
8. Yield();
A.
B.
C.
D.
4.
5.
6.
1,2,3
2,4,5
1,2,6
2,3,4
Class x implements Runnable
{
Public static void main(String args[])
{
/*missing code*/
}
Public void run() {}
}
Which of the following line code is suitable to start a thread?
A. Thread t = new Thread(x);
B. Thread t = new Thread(x).start();
C. X run= new x();Thread t= new Thread(run); t.strat();
D. Thread t= new Thread(); t.run();
Which cannot directly cause a thread to stop executing?
A. Calling the setPriority() method on a thread object.
B. Calling wait() method on an object.
C. Calling notify() method on an object
D. Calling read() method on an Inputstream object.
Which two of the following methods are defined in class thread?
Strat();
Wait();
Notify();
Run();
Terminate();
A. 1 and 4
B. 2 and 3
C. 3 and 4
D. 2 and 4
7. Which of the following will directly stop execution of tread?
A. Wait()
B. Notify();
C. notifyAll();
D. exit synchronized code
Ms. Anuja Vaidya
Page 7
060010503-Advanced Java 2014
8.
Which method must be defined by a class implementing the Java.lang.Runnable?
A. Void run()
B. Public void run()
C. Public void start()
D. Void run(int priority)
9. Which will contain the body of the thread?
A. Run();
B. Strart();
C. Stop();
D. Main();
10. Which method registers a thread in a thread scheduler?
A. Run();
B. Construct();
C. Start();
D. Register();
11. Which class or interface defines the wait(), notify(), and notifyAll() methods?
A. Object
B. Thread
C. Runnable
D. Class
12. What will be the output of the program?
Class MyThread extends Thread
{
Public static void main(String [] args)
{
MyThread t = new MyThread();
t.start();
System.out.println(“one. ”);
t.start();
System.out.println(“Two. ”);
}
Public void run()
{
System.out.println(“Thread ”);
}
}
State whether below given statements are ‘True’ or ‘False’
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
The suspend()method is used to terminate a thread
The run() method should necessary exists in classes created as subclass of thread
When two threads are waiting on each other and can't proceed the program is said to be in a deadlock
The word synchronized can be used with only a method.
The suspend()method is used to terminate a thread?
The run() method should necessary exists in classes created as subclass of thread?
When two threads are waiting on each other and can't proceed the program is said to be in a deadlock?
Garbage Collector belongs to high priority.
Sleep() method waits for the thread to die.
Run method is the default thread at a time of starting the program.
Threads of equal priority are time-sliced automatically in round robin fashion.
A thread cannot be preempted by a higher priority thread.
When Java program starts up, one thread begins running immediately. This is usually run() method of your
program.
Java’s multithreading system is built upon the Runnable interface.
To create or implement threading concept in your Java program you need to either implement runnable
interface or extend Thread class.
To override run method in program is optional while extending Thread class to create thread.
The isAlive() method returns false if the thread upon which it’s called is still running.
More than one thread can own a monitor at a given time.
Deadlock situation occurs when only thread in a right way.
Ms. Anuja Vaidya
Page 8
Fill in the blanks with an appropriate answer
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
060010503-Advanced Java 2014
Thread priorities are in the range between ___________ and ____________.
By default every thread is given priority ______________.
Thread can create by implementing ______________.
To create thread class we need to implement ___________ method.
__________ method will make your thread in running state.
Thread priorities are ___________ that specifies the relative priority of one thread to another.
Threads of equal priority are _______________ in round robin fashion.
A thread can be preempted by a _______________.
Java’s multi threading system is built upon the ____________ class.
Thread begins running immediately by _____________ of your program.
___________ method determine if thread is still running or not.
___________ method suspend a thread for a period of time.
___________ wait for a thread to terminate.
Sleep method may throw an _____________ exception.
After the new thread is created, it will not start running until you call its ___________ method.
The extending class must override the ________ method.
The ___________ method returns true if the thread upon which it is called is still running.
___________ Method waits until the thread on which it is called terminates.
Unit – 3
Event handling and AWT
Short Answer Questionss:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
What is Delegation event model?
One benefit of Delegation event model.
How one can differentiate event and event source?
Write a signature of Event Source registration method.
What is unicasting the event?
What is multicasting the event?
Which exception is thrown by unicasting event?
Define the signature of Event source unregister method.
State 2 major requirements for Event Listener.
Which package is used for delegation event model in AWT?
List any 4 event classes supported by AWT.
What is root class for all events in Java?
In which package root class for all events resides?
Which are the two different methods of EventObject class?
What is super class for all AWT events?
In which package super class for all AWT events reside?
State different event class from awt.event package.
List the event listener interface of AWT.
State any two methods of ComponentListener interface.
List methods of WindowListener interface
Which class resides at top level of AWT hierarchy?
State two different constructor to create Frame in AWT.
Which are the two different methods to set the window size in AWT?
What is use of repaint()?
What is use of update()?
What is use of init()?
What is use of paint()?
List any 10 different methods of Graphics class.
List 3 different constructor of color class.
List any 5 methods of color class.
List 5 different methods of Font class with brief description.
Ms. Anuja Vaidya
Page 9
060010503-Advanced Java 2014
32. Which method is used to identify the available font family name?
Long Answer Questionss
1. Explain delegation event model with proper example.
2. Which are the three different component of delegation event model? Explain each component in detail.
3. What is adapter class? Explain it using MouseAdapter and WindowAdapter.
4. How can we create new frame window? How can we set the dimension of the frame window as well as how can
we hide and show frame window and set window title?
5. Explain ActionEvent class in detail with its constants,constructors and methods.
6. Explain AdjustmentEvent class in detail with its constants,constructors and methods.
7. Explain ComponentEvent class in detail with its constants,constructors and methods.
8. Explain ContainerEvent class in detail with its constants,constructors and methods.
9. Explain ItemEvent class in detail with its constants,constructors and methods.
10. Explain MouseEvent class in detail with its constants,constructors and methods.
11. Draw the diagram for Java event. And explain Semantic events and low level events.
12. List the different event listener interfaces with methods.
13. Write a program that will cover all methods from MouseListener and MouseMotionListener.
14. What do you mean by adapter classes? Explain it with proper example (code)
15. Explain ActionEvent with Proper example.
16. Explain KeyEvent with proper example that include all methods of KeyListener.
17. What do you mean by Adapter class? List different adapter classes available for different listener in Java.AWT.
18. Draw window fundamentals figure. And explain each class.
19. Explain MouseEvent class in detail with Frame in applet.
20. Explain Graphics class with frame in applet using 10 different methods of Graphics class.
21. Explain color class with its constructor and methods and also with example that draw 2 different shapes on
applet with 2 different color.
22. Explain use of Font class and explain each method of Font class with brief description.
Select an appropriate option from given choices
1. Which event object is generated when a component is activated?
A. Action Event
B. Adjustment Event
C. Text Event
D. Item Event
2. Which event object is generated when a scrollbar is used?
A. Adjustment Event
B. Action Event
C. Container Event
D. Component Event
3. Which event object is generated when a text field is modified?
A. Text Event
B. Low level Events
C. Focus Event
D. Key Event
4. Which event objects is generated when any components are added or removed from container?
A. Container Event
B. Component Event
C. Focus Event
D. Text Event
5. Which event objects is generated when component is resized or moved?
A. Component Event
B. Container Event
C. Window Event
D. Mouse Event
6. Which event objects is generated when component receives focus for input?
A. Focus Event
B. Component Event
C. Key Event
D. Mouse Event
7. Which event objects is generated when key on keyboard is pressed or released?
Ms. Anuja Vaidya
Page 10
060010503-Advanced Java 2014
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
A. Key Event
B. Mouse Event
C. Input event
D. Component Event
Which event objects is generated when a window activity like maximizing or close occur?
A. Window Event
B. Container Event
C. Mouse Event
D. Key Event
Which event objects is generated when a mouse is used?
A. Mouse Event
B. Click Event
C. Key Event
D. Action Event
Which event objects is generated when component painted?
A. Paint Event
B. Repaint Event
C. Update event
D. Action Event
An object delegates the task of handling an event to whom?
A. Event Listener
B. Event Source
C. Event
D. Class
Listener can be register with which method?
A. AddTypeListener();
B. RegisterTypeListener();
C. AddListener();
D. AddTypeListenerInterface();
Which method is used to remove listener?
A. RemoveTypeListener();
B. UnregisterTypeListener();
C. UnregisterListener();
D. RemoveListener();
Which event class is not a part of symmentic event?
A. Action Event
B. Item Event
C. Text Event
D. Key Event
Which event class is not a part of low level event classes?
A. Component Event
B. Focus Event
C. Mouse Event
D. Window Event
Using which class we can create frame window?
A. Window
B. Frame
C. Container
D. Component
Which method is used to set visibility of frame window?
A. setVisbility();
B. setVisible(Boolean setFlag);
C. setVisible(String setFlag);
D. setVisible();
Which interface is used to close frame window?
A. Window Listener
B. Container Listener
C. Component Listener
D. Window Event
Which method of window listener is used to close frame window?
Ms. Anuja Vaidya
Page 11
060010503-Advanced Java 2014
A. WindowClosed()
B. WindowClosing()
C. WindowClose()
D. Close()
20. Which method is used to set title of frame window?
A. setTitle(String Title);
B. setTitle();
C. Title(String Title);
D. setWindowTitle(String title);
State whether below given statements are ‘True’ or ‘False’
1. Applet’s getParameter() method is used to get parameters value.
2. All applets are subclass of Applet class.
3. All Applet must import Java.event and Java.AWT.
4. Applet keyword is used to run applet program from cmd.
5. init(),start(),paint(),stop() and destroy() are the method of applet life cycle.
6. drawstring() method is used to draw string on applet.
7. Graphic is class that is used to deal with graphics for applet.
8. Every color is created from an RGB value.
9. The checkBoxGroup class is a subclass of the component class.
10. TextBox and TextArea are the subclass of Component class.
11. setEdit() method is used to set a text component to read only state.
12. getState() method allows you to tell if a checkbox is checked or not.
13. setLabel() is used to set label on Button component.
14. Component event object is generated when component receives focus for input.
15. If a frame uses its default layout manager and does not contain any panels, then all the components within the
frame are the same height and width.
16. New TextArea(10,20) constructor creates a TextArea with 10 rows and 20 columns.
17. setLabelText() method is used to set the text of Label Object.
18. getChild() method is used to access a component’s immediate container.
19. Graphics context is encapsulated by Graphics class.
20. Color supplies three methods that let you convert between RGB andHSB.
Fill in the blanks with an appropriate answer
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
___________ method is used to centering the text.
___________ method is used to set the title of frame window.
To handle mouse click event ___________ interface we need to implement in our class.
To draw line ___________ method is used.
___________ adapter class is used to handle close event of Frame window.
To handle button click event ___________ interface we need to implement.
__________ and __________ are methods of MouseMotionListener interface.
An object delegates the task of handling an event to ___________.
To create frame window we need to extends ___________ class.
To create Applet we need to extends ____________ class.
To handle key event ________________ interface is used.
__________ and _________ method is used to get the current position of cursor.
__________ method is part of ActionListener interface.
__________ class is used to create color for different object.
__________ method is used to set new font.
__________ method allows you to tell if a checkbox is checked or not.
__________ method is used to set a text component to read only state.
To use the concept of AWTEvent ___________ package we need to import.
To use Graphics class functionality __________ package we need to import.
To create paint brush in applet __________ method is used.
Unit – 4
Controls, Layout, Managers and Menus
Short Answer Questionss
Ms. Anuja Vaidya
Page 12
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
060010503-Advanced Java 2014
State 7 different controls supported by AWT.
Which method is used to add component in to a window?
Which method is used to remove any one component from a window?
Which method is used to remove all components from a window?
List 3 different types of constructors of Label class.
Define three different alignment constant of Label class.
Which method is used to set and get the alignment of the text of any Label?
State different constructors of Button class.
Which listener is used to handle action event generated by button?
Which 2 different method is used get a current source button’s label?
List five different constructor of Check Boxes class with proper signature.
Which method is used to check whether check box is selected or not?
Which method is used to get label of selected check box?
What is difference between check boxes and checkboxgroup?
Which method is used to determine which checkbox in a group is currently selected?
What is difference between checkbox control and choice control?
Define use of Choice class or choice control?
Which method is used to add a selection to the list with proper signature?
Which method is used to determine that which item is currently selected from choice control?
Which method is used to obtain the number of items in the list? Write with proper signature.
Which method is used to set the currently selected item in choice control? Write with proper signature.
What is use of List class or List control?
Define three different constructor of List class with proper signature.
Which method is used to add a selection to the list? Write with proper signature.
Which method is used to get the multiple selections from list? Write with proper signature.
Which method is used to get the name of currently selected item from its index value?
Which event is generated by Lists?
What is use of scrollbar class or scrollbar method?
Define three different constructor of scrollbar class with proper signature.
Which 2 different constant is used to set the style for scroll bar?
Which method is used to retrieve minimum and maximum value of scrollbar?
Which event is generated by scrollbar control?
Which method is used to handle an event generated by control?
Define use of TextField control.
Define four different types of constructor if TextField class with proper signature.
Which method is used to set the text in textfield and to obtain the text from the text field? Write with proper
signature.
Which method is used to obtain currently selected text from the the TextField? Write with proper signature.
State difference between TextField and TextArea class.
State five different constructor of TextArea class with proper signature.
Which object has a layout manager associated with it?
Which method is used to set the layout manager? Write with proper signature.
State different layouts of layout manager.
What is difference between MenuBar, Menu and MenuItem.
State 3 different constructor of Menu class with proper signature.
State 3 different constructor of MenuItem class.
Define use of dialog box in AWT.
State 2 different constructor of Dialog class with proper signature.
State 2 different type of dialog.
What is difference between Modal dialog and Modeless dialog.
Long Answer Questionss
1.
2.
3.
What is use of Label? Which class is used to create Label in AWT? List 3 different types of constructors of Label
class. Explain it with example which set and get the text of Label.
What is use of Push Button? Which class is used to create a push button? Explain concept of push button with
use of 2 different constructors and also get the current source button name from 4 different buttons created by
your program.
What is use of check box control? Which class is used to create check box control? Explain it with proper
example in which display the selection of user.
Ms. Anuja Vaidya
Page 13
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
060010503-Advanced Java 2014
What is use of check box group? Which class is used to create check box group control? Explain in with proper
example.
What is use of Choice control? Which class is used to create choice control? List different types of constructors
and 5 different methods with proper signature. Explain it with example.
What is use of list control? Which class is used to create list control? List different types of constructors and 5
different methods with proper signature. Explain with proper signature.
What is use of Scroll bar control? Which class is used to create Scroll bar control? Which event is generated by
event? List different types of constructors and 5 different methods with proper signature. Explain it with proper
example.
What is use of TextField control? Which class is used to create text field control? List different types of
constructors and 5 different methods with proper signature. Which method is used to define textfield as
password character? Explain it with proper example.
What is use of Text area control? Which class is used to create text area control? List different types of
constructors and 5 different methods with proper signature. Explain with proper example.
What is use of layout manager? Which method is used to set the layout of window in AWT? Which different
layouts are supported in AWT? Explain any one of them in detail with example.
What is use of flowlayout? Which class is used to create flowlayout? List different constant used to set the
flowlayout. Explain it with example in which you have to add 6 different components in a window with use of
Flowlayout.
What is use of border layout? Which class is used to create border layout? List different constructors of the
same. Explain it with example in which you have to add 6 different components in a window with use of border
layout.
What is use of insets layout? Which class is used to create insets layout? List different constructors of the same.
Explain it with example in which you have to add 4 different components in a window with use of insets layout.
What is use of grid layout? Which class is used to create grid layout? List different constructors of the same.
Explain it with example which creates a 4 by 4 grid and fills it in with 15 buttons each labeled with its index
value.
What is use of card layout? Which class is used to create card layout? List different constructors and methods
with proper signature of the same. Explain it with example which creates a two-level card deck that allows the
user to select an operating system. Window based operating systems are displayed in one card. Other os will be
in the other card.
What is use of gridbag layout? List any 6 methods of the same class with proper signature and with brief
description. Explain with example which includes 6 methods you have described above.
What is use of menu and menu bar? Which class is used to create menu and menubar? List different constructor
and any five methods of the same with proper signature and brief signature and also explain with example
which includes five methods that is described above.
What is use of menu item? How one can add menu items in menu? Explain it with proper example.
How one can create checkable menu item? Which class is used to create checkable menu item? Explain with
example.
What is use of dialog box? Which are the two different types of dialog are there and give difference between
them? Explain it with proper example.
Select an appropriate option from given choices
1.
2.
3.
4.
Which of the following control is not supported in AWT?
A. Push button
B. Choice
C. List
D. Drop down list
Which method is used to add component to your container?
A. add();
B. addComponent();
C. addComponent(Component obj);
D. add(Component obj);
Which method is used to remove any specific component to your container?
A. remove()
B. removeComponent()
C. removeComponent(Component obj)
D. remove(Component obj)
The various controls supported by AWT are
Ms. Anuja Vaidya
Page 14
060010503-Advanced Java 2014
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
A. Labels, push buttons
B. Checkboxes, choice, list
C. Scroll bars, text area, text field
D. All of these
The concept of the menu bar can be implemented by using three Java classes—
A. MenuBar
B. Menu
C. MenuItem
D. All of these
The most commonly used layout managers are
A. FlowLayout
B. BorderLayout
C. GridLayout
D. CardLayout
E. All of these
AWT means
A. Abstract Window Toolkit
B. Abstract Window Toollayout
C. Abstract Withdraw Tools
D. Abstract Window Title
A checkbox is a control that consists of a
A. Combination of a small box
B. A label
C. Combination of a large box and a label
D. Both a & b
The AWT container is an instance of the ___________ class which holds various components and other containers
A. Graphics
B. Container
C. Eventobj
D. None of these
The general form to set a specific type of layout manager is
A. void setLayout(LayoutManager lm)
B. Void setLayout(LayoutManager lm)
C. void setLayout(layoutManager lm)
D. Void setLayout(Layoutmanager lm)
Java packages such as ________________ support the Event handling mechanism.
A. Java.util
B. Java.AWT
C. Java.AWT.event
D. All of these
Positions the components into five regions:east, west, north, south, center
A. BorderLayout
B. CardLayout
C. GridLayout
D. FlowLayout
Arranges the components as a deck of cards such that only one component is visible at a time
A. BorderLayout
B. CardLayout
C. GridLayout
D. FlowLayout
Arranges the components horizontally
A. BorderLayout
B. CardLayout
C. GridLayout
D. FlowLayout
Arranges the componemnts into grid
A. BorderLayout
B. CardLayout
C. GridLayout
D. FlowLayout
Ms. Anuja Vaidya
Page 15
060010503-Advanced Java 2014
16. __________ creates a dropdown list of textual entries
A. Choice
B. Checkbox
C. Textbox
D. TextComponent
17. The Component class and MenuComponent class are the ___________ which represent the GUI components.
A. Subclasses
B. Superclasses
C. Both a & b
D. None of these
18. The AWT classes can be roughly categorized into the following groups:
A. GUI Components
B. Layouts
C. Graphics Tools
D. Event Handlers
E. All of these
19. A menu bar represents
A. A list of menus which can be added to the top of a top-level window
B. A list of menus which can be deleted to the top of a top-level window
C. A list of menus which can be added to the bottom of a bottom-level window
D. None of these
20. The two types of menus which are given as follows
A. Pop-up menus
B. Regular menus
C. Both a & b
D. Both a & b
State whether below given statements are ‘True’ or ‘False’
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
setLayout() method is used to set the layout of a container.
getPreferredSize() method is used to returns the preferred size of a component.
Grid layout is used to organize the components of a container in a tabular form.
Grid layout is a default layout for an applet, a frame and a panel.
Add() method is used to add component to a container.
To remove all components from the container remove(component obj) method is used.
Labels are passive control that does not support any user interaction.
getLabel() method is used to get the text of the label.
Void setAlignment(String alignment) method is used to set the alignment of text on label.
Click event will get generate when button is clicked by user.
getActionCommand() method will return the name of respective component.
CheckBox class is used to create drop down list in Java.
CheckBoxGroup class is used to create radio button control in Java
setLabel(string str) method is used to set the label of any checkbox control.
getState() method is used to check whether checkbox is selected or not.
List class is used to create a list in which we can select only one item.
getSelectedItem() method is used to get the item from list or choice control.
ItemListener interface need to be implemented by choice and list control.
setEchoChar(char ch) is used to set text as password.
setEditable(Boolean edit) is used to set textfield as editable.
Unit – 5
Swing
Short Answer Questionss
1.
2.
3.
4.
5.
6.
When swing comes in to the picture?
State key features of swing.
Differentiate Model and View of MVC.
Which package we should import to use swing control?
Define terms of MVC architecture.
Swing class is derived from which class?
Ms. Anuja Vaidya
Page 16
060010503-Advanced Java 2014
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
List five different component of swing.
Which package we should import to handle an event generated by swing control?
State different top level containers.
Swing components are derived from which package?
To close JFrame in swing which function is used?
To implement the event handling mechanism which packages we need to import?
Which class is used to create label with icon?
Define use of toggle button?
Which method is used to check the state of toggle button (i.e whether its in on mode or off) ?
Which class is used to insert image in Lable?
1.
2.
3.
4.
When Swing comes into the picture? How swing is more powerful than applet?
State drawback of AWT over swing. State features of swing.
Explain MVC architecture? Explain it with practical example.
What is difference between components and container? How we can achieve concept of container and
component in swing? Which classes are used for the same?
How we can create swing application? Explain one program using one of these methods.
Explain event handling in swing with appropriate example.
How one can create swing applet? Explain with example.
Exaplain JLabel component in swing using ImageIcon. Explain all methods of JLabel and ImageIcon with brief
description and with proper signature.
Develop one program that will cover all the methods of JLabel and ImageIcon control.
Explain JTextField component in swing with brief description of all methods of the same class. Also develop one
program that will cover all methods and constructors of JTextField class.
Explain JButton component in swing with brief description of all methods of the same class. Also develop one
program that will cover all methods, constructors and event handling of JButton class.
Explain JToggleButton component in swing with brief description of all methods of the same class. Also develop
one program that will cover all methods, constructors and event handling of JToggelButton class.
Explain JCheckBox component in swing with brief description of all methods of the same class. Also develop one
program that will cover all methods, constructors and event handling of JCheckBox class.
Explain JRadioButton component in swing with brief description of all methods of the same class. Also develop
one program that will cover all methods, constructors and event handling of JRadioButton class.
Explain JTabbedPane component in swing with brief description of all methods of the same class. Also develop
one program that will cover all methods and constructors of JTabbedPane class.
Explain JScrollPane component in swing with brief description of all methods of the same class. Also develop one
program that will cover all methods and constructors of JScrollPane class.
Explain JList component in swing with brief description of all methods of the same class. Also develop one
program that will cover all methods, event handling and constructors of JList class.
Explain JComboBox component in swing with brief description of all methods of the same class. Also develop
one program that will cover all methods, event handling and constructors of JComboBox class.
Explain Tree component in swing with brief description of all methods of the same class. Also develop one
program that will cover all methods, event handling and constructors of Tree class.
Explain JTable component in swing with brief description of all methods of the same class. Also develop one
program that will cover all methods and constructors of JTable class.
Long Answer Questionss
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Select an appropriate option from given choices
1.
2.
3.
MVC stands for
A. Model View Controller
B. Mode View Controller
C. Model View Control
D. Model Viewer Controller
Swing introduced in __________
A. 1997
B. 1996
C. 1995
D. 1994
Swing components are derived from the
Ms. Anuja Vaidya
Page 17
060010503-Advanced Java 2014
A. JComponent
B. Component
C. Container
D. None of these
4. Following are the Top Level containers
A. JApplet
B. JFrame
C. JDialog
D. JWindow
5. To set close operation on Frame which function is used
A. setDefaultCloseOperation()
B. setDefaultClose()
C. setFrameCloseOperation()
D. none of these
6. To create swing applet we need to extend which class?
A. JApplet
B. Applet
C. SwingApplet
D. None of these
7. How many constructors are there in JLabel class?
A. 1
B. 2
C. 3
D. 4
8. Which class is used to create icon in Label?
A. Icon
B. ImageIcon
C. Image
D. None of these
9. How many constructors are there in JTextField class?
A. 1
B. 2
C. 3
D. 4
10. Set command for particular button which function is used?
A. ActionCommand(String command)
B. getActionCommand()
C. setActionCommand(String str)
D. none of these
State whether below given statements are ‘True’ or ‘False’
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
MVC stands for Model View Controller.
We can create JLabel in 4 different ways.
We can create JButton in 4 different ways.
To set the current action command when particular button is pressed setActionCommand().
ImageIcon class is used to create icon for Label.
JButton component has a 2 different states: push and release.
Immediate super class for JCheckBox class is JToggleButton.
isSelected() method is used to check wether togglebutton is in pressed state or release state.
JRadioButton generates action events.
JScrollPane manages a set of components by linking them with tabs.
JTabbedPane uses theSingleSelectionModelmodel.
JTabbedPane have 4 different types of constructors.
To create swing applet we need to extend Applet class
Swing introduced in 1998
To set close operation on Frame setDefaultCloseOperation function is used
JComopnent class derived form Container and component.
You can selectively prevent a field from being saved through the use of the Transient keyword.
JList is based on three different models.
Ms. Anuja Vaidya
Page 18
060010503-Advanced Java 2014
19. JList components generate ListSelectionEvent.
20. There are three different types of property in Java bean.
Fill in the blanks with an appropriate answer
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
MVC stands for ____________.
To set the current action command when particular button is pressed _____________ method is used.
_______________ class is used to create icon for Label.
_______________ component has a 2 different states: push and release.
Immediate super class for JCheckBox class is ________________.
________________ method is used to check whether togglebutton is in pressed state or release state.
JRadioButton generates___________________.
_________________ a set of components by linking them with tabs.
_________________ the SingleSelectionModelmodel.
To create swing applet we need to extend __________ class
Swing introduced in __________.
To set close operation on Frame ______________ function is used.
JComopnent class derived form _________ and ____________ class.
JList is based on _________ different models.
You can selectively prevent a field from being saved through the use of the ________________ keyword.
JList components generate ______________ event.
There are __________ different types of property in Java bean.
________________ exception is thrown by Constrained Property.
A Bean that has a ___________________ property generates an event when an attempt is made to change its value.
A Bean that has a __________________ property generates an event when the property is changed.
Unit 6
Network Programming
Short Answer Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
In which layer of OSI model TCP/IP protocol is available?
What is protocol?
Differentiate TCP/IP and Datagrams.
What is the port no for FTP?
What is the port no for Telnet?
What is the port no for HTTP?
What identifies each computer on Internet?
Give any 2 differences between IPV4 and IPV6.
INet6Address belongs to which package?
The InetAddress used for what?
What is the difference between URL instance and URLConnection instance?
What is socket in Java Networking?
What information is needed to create a TCP socket?
What are the two important TCP Socket classes?
When MalformedURLException and UnknownException throws?
What is the difference between the file and RandomAccessFile classes?
What interface must an object implements before it can be written to a stream as an object?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
Explain TCP/IP Client Socket with appropriate example.
Explaint InetAddress with proper example.
List the instance method of InetAddress class with brief description.
What is socket and explain its instance methods with suitable example.
Explain what is URL using example.
Explain four different Components of URL.
Explain different types of constructor of URL class.
What is the difference between URL and URLConnection?
What is the difference between URLConnection and HttpURLConnection?
Explain any Eight different methods of URLConnection class.
Write a program using URL and URLConnection to establish connection to any site and get the information of the
Long Answer Questions
Ms. Anuja Vaidya
Page 19
12.
13.
14.
15.
16.
17.
18.
19.
060010503-Advanced Java 2014
same site.
What is the use of HttpURLConnection class? Explain any five instant methods of the same class.
What is the difference between URL and URI?
Explain TCP/IP Server socket.
What is Datagram? Explain in detail.
Explain DatagramSocket in detail with its constructor and methods.
Explain DatagramPacket . define its different Constructors.
Explain Datagram with appropriate example.
Explain IP,TCP and UDP in detail.
Select an appropriate option from given choices
1.
2.
3.
4.
5.
6.
7.
TCP stands for
A. Transaction control Protocol
B. Transmission Control Protocol
C. Transmission Circuit Protocol
D. Transaction Circuit Protocol
IP stands for
A. InetAddress Protocol
B. Internet Protocol
C. Inet4Address Protocol
D. Inet6Address Protocol
UDP stands for
A. User Datagram Protocol
B. User Direct Protocol
C. User Datasocket Protocol
D. User Default Protocol
Which of the following is required to communicate between two computers?
A. Communication software
B. Protocol
C. Communication Hardware.
D. All of above.
Which of the following services use TCP?
A. DHCP
B. SMTP
C. HTTP
D. TFTP
E. FTP
A.
B.
C.
D.
1 and 2
2,3 and 5
1,2 and 4
1,3 and 4
The name of internet address is
A. IP Address
B. UDP
C. Domain Name
D. Address
The InetAddress class is used to encapsulate
A. IP Address
B. Domain Name
C. Internet Address
D. A and B
Ms. Anuja Vaidya
Page 20
8.
9.
URL stands for
A. Universal Resource Locator
B. Uniform Resource Locator
C. Uniform Redirect Location
D. Universal Resource Library
060010503-Advanced Java 2014
What is protocol in given URL http://www.google.com
A. HTTP
B. WWW
C. .Com
D. Google
10. What is the port no of HTTP
A. 21
B. 23
C. 119
D. 80
11. What is the port no FTP?
A. 23
B. 21
C. 43
D. 79
12. URL throws which exception?
A. MalformedURLException
B. InterruptedException
C. NullPointerException
D. ArrayIndexOutOfBoundException
13. URL’s method OpenConnection() throws which Exception?
A. MalformedURLException
B. InterruptedException
C. NullPointerException
D. IOException
State whether below given statements are ‘True’ or ‘False’
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
UDP is a protocol that sends independent packets of data, called datagrams, from one computer to another with
guarantees about arrival and sequencing.
The TCP and UDP protocols use domains to map incoming data to a particular process running on a computer.
Port is represented by a positive (16-bit) integer value.
Every computer on the Internet is identifi ed by a unique, 6-byte IP address .
Sockets provide an interface for programming networks at the transport layer.
A socket is an endpoint of a three-way communication link between three programs running on the network.
The two key classes from the Java.net package used in creation of server and client programs are: ServerSocket
and ClientSocket
A server program creates a specific type of socket that is used to listen for client requests.
UDP stands for Universal datagram Protocol
Datagram communication through the following classes DatagramPacket and DatagramSocket.
URI stands for Universal Resource Identifier.
IP stands for Internation Protocol.
Port for HTTP is 90.
URLConnection can open secure connection.
OpenConnection() method is from URL class.
Is TCP Connection Less Protocol.
TCP stands for Transaction Control Protocol.
UDP is more reliable than TCP protocol.
The same port number can be reused many times when binding with sockets simultaneously
Ms. Anuja Vaidya
Page 21
060010503-Advanced Java 2014
20. In order to create a client socket connecting to a particular server, the IP address must be given to the client
socket, otherwise, it cannot connect to the server
21. Sockets provide an interface for programming networks at the transport layer.
22. Call Socket.close() method will close the TCP server that socket connects to.
Fill in the blanks with an appropriate answer
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
______ is a connection-oriented and reliable protocol, ______ is a less reliable protocol.
The TCP and UDP protocols use ______ to map incoming data to a particular process running on a computer.
Datagrams are normally sent by ______ protocol.
Java uses ______ class representing a server and ______ class representing the client that uses TCP protocol.
______ is used to wait for accepting client connection requests.
Class ______ is used to create a packet of data for UDP protocol.
If something goes wrong related to the network, ______ will be thrown when dealing with TCP/UDP programming
in Java.
The main purpose of URL encoding is to maintain the ______ between various platforms.
Based on the URL encoding mechanism, “www.test.com/test me&test you” becomes ______.
______ method is used to instantiate a URLConnection instance.
URL stands for ____________.
UDP stands for ____________.
TCP/IP stands for ____________.
Http is on _________ port.
Ms. Anuja Vaidya
Page 22