You are on page 1of 28

ADVANCED JAVA PROGRAMMING

One Word Questions and Answers


UNIT - I
1. Which of this method can be used to make the main thread to be executed last simultaneously
among all the threads? d) It’s a method that allow too many threads to access any information require
a) stop()
b) sleep() 7. What will be the output of the following Java code?
c) join() class newthread extends Thread
d) call() {
newthread()
2. Which of this method is used to find out that a thread is still running or not? {
a) run()
super("My Thread");
b) Alive()
start();
c) isAlive()
}
d) checkRun()
public void run()
3. What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY? {
a) 0 & 256 System.out.println(this);
b) 0 & 1 }
c) 1 & 10 }
d) 1 & 256 class multithreaded_programing
{
4. Which of these method waits for the thread to terminate?
public static void main(String args[])
a) sleep() {
b) isAlive() new newthread();
c) join() }
d) stop() }
a) My Thread
5. Which of these method is used to explicitly set the priority of a thread?
b) Thread[My Thread,5,main]
a) set()
c) Compilation Error
b) make()
d) Runtime Error
c) setPriority()
d) makePriority() 8. What will be the output of the following Java code?

6. What is synchronization in reference to a thread? class newthread extends Thread


a) It’s a process of handling situations when two or more threads need access {
to a shared resource
Thread t;
b) It’s a process by which many thread are able to access same shared resource
newthread()
simultaneously
{
c) It’s a process by which a method is able to access many different threads
t = new Thread(this,"My Thread");
t.start(); {
} public static void main(String args[])
public void run() {
{ new newthread();
try }
{ }
t.join() a) 0
System.out.println(t.getName()); b) 1
} c) true
catch(Exception e) d) false
{
10. What will be the output of the following Java code?
System.out.print("Exception");
} class newthread extends Thread
} {
} Thread t1,t2;
class multithreaded_programing newthread()
{ {
public static void main(String args[]) t1 = new Thread(this,"Thread_1");
{ t2 = new Thread(this,"Thread_2");
new newthread(); t1.start();
} t2.start();
} }
a) My Thread
b) Thread[My Thread,5,main]
public void run()
c) Exception
{
d) Runtime Error t2.setPriority(Thread.MAX_PRIORITY);
System.out.print(t1.equals(t2));
9. What will be the output of the following Java code? }
}
class newthread extends Thread class multithreaded_programing
{ {
Thread t; public static void main(String args[])
newthread() {
{ new newthread();
t = new Thread(this,"New Thread"); }
t.start(); }
} a) true
public void run() b) false
{ c) truetrue
System.out.println(t.isAlive()); d) falsefalse
}
11. Which of these method is used to implement Runnable interface?
}
a) stop()
class multithreaded_programing
b) run()
c) runThread() class newthread implements Runnable
d) stopThread() {
Thread t;
12. Which of these method is used to begin the execution of a thread?
newthread()
a) run()
{
b) start()
c) runThread()
t = new Thread(this,"My Thread");
d) startThread() t.start();
}
13. Which of these statement is incorrect? public void run()
a) A thread can be formed by implementing Runnable interface only {
b) A thread can be formed by a class that extends Thread class System.out.println(t);
c) start() method is used to begin execution of the thread }
d) run() method is used to begin execution of a thread before start() method in }
special cases class multithreaded_programing
{
14. What will be the output of the following Java code?
public static void main(String args[])
class newthread implements Runnable {
{ new newthread();
Thread t; }
}
newthread()
a) My Thread
{ b) Thread[My Thread,5,main]
t = new Thread(this,"My Thread"); c) Compilation Error
t.start(); d) Runtime Error
}
public void run() 16. What will be the output of the following Java code?
{
System.out.println(t.getName()); class newthread implements Runnable
} {
} Thread t;
class multithreaded_programing newthread()
{ {
public static void main(String args[]) t = new Thread(this,"My Thread");
{ t.start();
new newthread(); }
} }
} class multithreaded_programing
a) My Thread {
b) Thread[My Thread,5,main] public static void main(String args[])
c) Compilation Error {
d) Runtime Error new newthread();
}
15. What will be the output of the following Java code?
}
a) My Thread }
b) Thread[My Thread,5,main] public void run()
c) Compilation Error {
d) Runtime Error t2.setPriority(Thread.MAX_PRIORITY);
System.out.print(t1.equals(t2));
17. What will be the output of the following Java code?
}
class newthread implements Runnable }
{ class multithreaded_programing
Thread t; {
newthread() public static void main(String args[])
{ {
t = new Thread(this,"New Thread"); new newthread();
t.start(); }
} }
a) true
public void run()
b) false
{ c) truetrue
t.setPriority(Thread.MAX_PRIORITY); d) falsefalse
System.out.println(t);
} 19. Exception and Error are immediate subclasses of a class called
} a. Object b. Throwable c. AWT d. Panel
class multithreaded_programing
{
20. The order of the three top level elements of the java source file are
public static void main(String args[])
{ a. Import, Package, Class b. Class, Import, Package c. Package, Import, Class d.
new newthread(); Random order
}
} 21. The minimum value of char type variable is
a) Thread[New Thread,0,main]
a. ‘\u0020’ b. ‘\u00ff’ c. ‘\u0010’ d. ‘\u0000’
b) Thread[New Thread,1,main]
c) Thread[New Thread,5,main]
d) Thread[New Thread,10,main] 22. Java uses ___ to represent characters
a. ASCII code b. Unicode c. Byte code d. None of the above
18. What will be the output of the following Java code?
23. Which one is not supported by OOP?
class newthread implements Runnable
{ a. Abstraction b. Polymorphism c. Encapsulation d. Global variables
Thread t;
newthread() 24. Java programs are a. Platform-dependent b. Interpreter-dependent c.
{ Platform-independent d. Interpreter-independent
t1 = new Thread(this,"Thread_1");
t2 = new Thread(this,"Thread_2");
t1.start();
t2.start();
25. The new operator a. returns a pointer to a variable b. creates a variable called c) getPriority()
new c. obtains memory for a new variable d. tells how much memory is d) getThreadPriority()
34. Which of these method of Thread class is used to Suspend a thread for a period of
available time?
a) sleep()
26. Which of the following statement is correct? b) terminate()
a. For positive numbers, result of operators >> and >>> are same b. Java c) suspend()
d) stop()
provides two operators to do left shift <<< and << c. >> is the zero fill right shift
35. Which function of pre defined class Thread is used to check weather current
operator d. >>> is the signed right shift operator thread being checked is still running?
a) isAlive()
27. Java language has support for which of the following types of comment? b) Join()
c) isRunning()
a. block, line and javadoc b. javadoc, literal and string c. javadoc, char and string
d) Alive()
d. single, multiple and quote 36. What will be the output of the following Java code?
class multithreaded_programing
28. Command to execute a compiled java program is : {
a. javac b. java c. run d. execute public static void main(String args[])
{
Thread t = Thread.currentThread();
29. ______ is a mechanism for naming and visibility control of a class and its
t.setName("New Thread");
content. System.out.println(t);
a. Object b. Packages c. Interfaces d. None of the Mentioned }
}
30. The java compiler a. creates executable b. translates java source code to a) Thread[5,main]
b) Thread[New Thread,5]
byte code c. creates classes d. produces java Interpreter
c) Thread[main,5,main]
d) Thread[New Thread,5,main]
31. Two threads cannot simultaneously enter into the methods of the same
37. What is the priority of the thread in output in the following Java program?
object if the methods are
a. static b. synchronized c. private d. package class multithreaded_programing
{
public static void main(String args[])
32. While using threads which of the following is incorrect? {
a. You invoke the Run method b. You implement Runnable interface c. You Thread t = Thread.currentThread();
extend from Thread class d. You call the start method t.setName("New Thread");
System.out.println(t.getName());
33. What is the name of the method used to schedule a thread for execution? }
}
a. init() b. start() c. run() d. resume() a) main
1. Which of these method of Thread class is used to find out the priority given to a b) Thread
thread? c) New Thread
a) get() d) Thread[New Thread,5,main]
b) ThreadPriority()
38. What is the name of the thread in output in the following Java program? b) Both of them will be executed simultaneously
class multithreaded_programing c) None of them will be executed
{ d) It is dependent on the operating system
public static void main(String args[]) 5. Which of these statements is incorrect?
{ a) By multithreading CPU idle time is minimized, and we can take maximum use of it
Thread t = Thread.currentThread(); b) By multitasking CPU idle time is minimized, and we can take maximum use of it
c) Two thread in Java can have the same priority
System.out.println(t.getPriority());
d) A thread can exist only in two states, running and blocked
}
} 6. What will be the output of the following Java code?
a) 0
b) 1 class multithreaded_programing
c) 4 {
d) 5 public static void main(String args[])
39. What is the name of the thread in output in the following Java program? {
Thread t = Thread.currentThread();
class multithreaded_programing System.out.println(t);
{ }
public static void main(String args[]) }
{
Thread t = Thread.currentThread(); a)Thread[5,main]
System.out.println(t.isAlive()); b)Thread[main,5]
}
c)Thread[main,0]
}
a) 0 d) Thread[main,5,main]
b) 1
c) true 8. What is the name of the thread in the following Java Program?
d) false
class multithreaded_programing
40. What is multithreaded programming?
a) It’s a process in which two different processes run simultaneously
{
b) It’s a process in which two or more parts of same process run simultaneously
public static void main(String args[])
c) It’s a process in which many different process are able to access same information {
d) It’s a process in which a single process can access information from many sources Thread t = Thread.currentThread();
2. Which of these are types of multitasking? System.out.println(t);
a) Process based }
b) Thread based }
c) Process and Thread based a)main
d) None of the mentioned
3. Thread priority in Java is? b)Thread
a) Integer c)System
b) Float
c) double d) None of the mentioned
d) long 1. What requires less resources?
4. What will happen if two thread of the same priority are called to be processed a) Thread
simultaneously? b) Process
a) Anyone will be executed first lexographically
c) Thread and Process c) wait()
d) Neither Thread nor Process d) Thread.killThread()
2. What does not prevent JVM from terminating? 1. Which of these keywords are used to implement synchronization?
a) Process a) synchronize
b) Daemon Thread b) syn
c) User Thread c) synch
d) JVM Thread d) synchronized
3. What decides thread priority? 2. Which of this method is used to avoid polling in Java?
a) Process a) wait()
b) Process scheduler b) notify()
c) Thread c) notifyAll()
d) Thread scheduler d) all of the mentioned
4. What is true about time slicing? 3. Which of these method is used to tell the calling thread to give up a monitor and go
a) Time slicing is OS service that allocates CPU time to available runnable thread to sleep until some other thread enters the same monitor?
b) Time slicing is the process to divide the available CPU time to available a) wait()
runnable thread b) notify()
c) Time slicing depends on its implementation in OS c) notifyAll()
d) Time slicing allocates more resources to thread d) sleep()
5. Deadlock is a situation when thread is waiting for other thread to release acquired 4. Which of these method wakes up the first thread that called wait()?
object. a) wake()
a) True b) notify()
b) False c) start()
6. What should not be done to avoid deadlock? d) notifyAll()
a) Avoid using multiple threads 5. Which of these method wakes up all the threads?
b) Avoid hold several locks at once a) wakeAll()
c) Execute foreign code while holding a lock b) notify()
d) Use interruptible locks c) start()
7. What is true about threading? d) notifyAll()
a) run() method calls start() method and runs the code 6. What is synchronization in reference to a thread?
b) run() method creates new thread a) It’s a process of handling situations when two or more threads need access
c) run() method can be called directly without start() method being called to a shared resource
d) start() method creates new thread and calls code written in run() method b) It’s a process by which many thread are able to access same shared resource
8. Which of the following is a correct constructor for thread? simultaneously
a) Thread(Runnable a, String str) c) It’s a process by which a method is able to access many different threads
b) Thread(int priority) simultaneously
c) Thread(Runnable a, int priority) d) It’s a method that allow too many threads to access any information the require
d) Thread(Runnable a, ThreadGroup t)
1. What does AWT stands for?
9. Which of the following stops execution of a thread?
a) Calling SetPriority() method on a Thread object a) All Window Tools
b) Calling notify() method on an object
b) All Writing Tools
c) Calling wait() method on an object
d) Calling read() method on an InputStream object c) Abstract Window Toolkit
10. Which of the following will ensure the thread will be in running state? d) Abstract Writing Toolkit
a) yield()
b) notify()
2. Which of these is used to perform all input & output operations in Java? a) abcqfgh
a) streams b) abc
b) Variables c) abcq
c) classes d) abcqfghq
d) Methods
8. What will be the output of the following Java program if input given is “abc’def/’egh”?
3. Which of these is a type of stream in Java?
a) Integer stream class Input_Output
b) Short stream {
c) Byte stream public static void main(String args[]) throws IOException
d) Long stream {
4. Which of these classes are used by Byte streams for input and output operation? char c;
a) InputStream BufferedReader obj = new BufferedReader(new
b) InputOutputStream
InputStreamReader(System.in));
c) Reader
do
d) All of the mentioned
{
5. Which of these classes are used by character streams for input and output
c = (char) obj.read();
operations?
a) InputStream
System.out.print(c);
b) Writer } while(c!='\'');
c) ReadStream }
d) InputOutputStream }
6. Which of these class is used to read from byte array? a) abc’
a) InputStream
b) BufferedInputStream b) abcdef/’
c) ArrayInputStream c) abc’def/’egh
d) ByteArrayInputStream
d) abcqfghq
7. What will be the output of the following Java program if input given is
9. What will be the output of the following Java program?
‘abcqfghqbcd’?
1. class output
class Input_Output
{ 2. {
public static void main(String args[]) throws IOException 3. public static void main(String args[])
{ 4. {
char c; 5. StringBuffer c = new StringBuffer("Hello");
BufferedReader obj = new BufferedReader(new 6. System.out.println(c.length());
InputStreamReader(System.in)); 7. }
do 8. }
{ a) 4
c = (char) obj.read();
b) 5
System.out.print(c);
} while(c != 'q'); c) 6
} d) 7
}
1. Which exception is thrown by read() method? 6. What will be the output of the following Java program?
a) IOException class output
b) InterruptedException {
public static void main(String args[])
c) SystemException {
d) SystemInputException StringBuffer c = new StringBuffer("Hello");
2. Which of these is used to read a string from the input stream? StringBuffer c1 = new StringBuffer(" World");
a) get() c.append(c1);
b) getLine() System.out.println(c);
c) read() }
d) readLine() }
3. Which of these class is used to read characters and strings in Java from console? a) Hello
a) BufferedReader b) World
c) Helloworld
b) StringReader
d) Hello World
c) BufferedStreamReader 7. What will be the output of the following Java program?
d) InputStreamReader class output
4. Which of these class is implemented by FilterInputStream class? {
a) InputStream public static void main(String args[])
b) InputOutputStream
{
c) BufferedInputStream
StringBuffer s1 = new StringBuffer("Hello");
d) SequenceInputStream
s1.setCharAt(1,x);
5. What will be the output of the following Java program if input given is “Hello stop System.out.println(s1);
World”? }
}
class Input_Output
a) xello
{
public static void main(String args[]) throws IOException b) xxxxx
{ c) Hxllo
string str;
BufferedReader obj = new BufferedReader(new d) Hexlo
InputStreamReader(System.in));
8. What will be the output of the following Java program if input given is “abc’def/’egh”?
do
{ class Input_Output
str = (char) obj.readLine(); {
System.out.print(str); public static void main(String args[]) throws IOException
} while(!str.equals("strong")); {
} char c;
} BufferedReader obj = new BufferedReader(new
a) Hello InputStreamReader(System.in));
b) Hello stop do
c) World {
d) Hello stop World c = (char) obj.read();
System.out.print(c); 7. What will be the output of the following Java program?
} while(c != '\'');
} class output
} {
public static void main(String args[])
a) abc’
{
b) abcdef/’ StringBuffer s1 = new StringBuffer("Hello");
c) abc’def/’egh StringBuffer s2 = s1.reverse();
System.out.println(s2);
d) abcqfghq
}
1. Which of these class contains the methods print() & println()? }
a) System
b) System.out a) Hello
c) BUfferedOutputStream b) olleH
d) PrintStream
2. Which of these methods can be used to writing console output? c) HelloolleH
a) print()
b) println() d) olleHHello
c) write()
d) all of the mentioned 1. Which of these class contains the methods used to write in a file?
3. Which of these classes are used by character streams output operations?
a) InputStream a) FileStream
b) Writer b) FileInputStream
c) ReadStream
d) InputOutputStream c) BUfferedOutputStream
4. Which of these class is used to read from a file?
d) FileBufferStream
a) InputStream
b) BufferedInputStream
c) FileInputStream 2. Which of these exception is thrown in cases when the file specified for writing is not
d) BufferedFileInputStream
found?
5. What will be the output of the following Java program?
a) IOException
class output b) FileException
{
public static void main(String args[]) c) FileNotFoundException
{ d) FileInputException
String a="hello i love java";
System.out.println(indexof('i')+" "+indexof('o')+" 3. Which of these methods are used to read in from file?
"+lastIndexof('i')+" "+lastIndexof('o') )); a) get()
}
b) read()
}
c) scan()
a) 6 4 6 9
d) readFileInput()
b) 5 4 5 9
c) 7 8 8 9 4. Which of these values is returned by read() method is end of file (EOF) is
d) 4 3 6 9 encountered?
b) paint()
a) 0 c) drawString()
b) 1 d) transient()
4. Which of these modifiers can be used for a variable so that it can be accessed from
c) -1 any thread or parts of a program?
a) transient
d) Null b) volatile
5. Which of these exception is thrown by close() and read() methods? c) global
a) IOException d) No modifier is needed
b) FileException 5. Which of these operators can be used to get run time information about an object?
c) FileNotFoundException a) getInfo
d) FileInputOutputException b) Info
6. Which of these methods is used to write() into a file? c) instanceof
a) put() d) getinfoof
b) putFile()
6. What is the Message is displayed in the applet made by the following Java
c) write()
d) writeFile() program?
7. What will be the output of the following Java program? import java.awt.*;
import java.io.*; import java.applet.*;
class filesinputoutput public class myapplet extends Applet
{ {
public static void main(String args[]) public void paint(Graphics g)
{ {
InputStream obj = new FileInputStream("inputoutput.java"); g.drawString("A Simple Applet", 20, 20);
System.out.print(obj.available()); }
} }
a) A Simple Applet
} b) A Simple Applet 20 20
Note: inputoutput.java is stored in the disk. c) Compilation Error
d) Runtime Error
a) true
7. What is the length of the application box made by the following Java program?
b) false
import java.awt.*;
c) prints number of bytes in file import java.applet.*;
d) prints number of characters in the file public class myapplet extends Applet
{
1. Which of these functions is called to display the output of an applet?
a) display() public void paint(Graphics g)
b) paint() {
c) displayApplet() g.drawString("A Simple Applet", 20, 20);
d) PrintApplet() }
2. Which of these methods can be used to output a string in an applet?
}
a) display()
a) 20
b) print()
c) drawString() b) 50
c) 100
d) transient()
d) System dependent
3. Which of these methods is a part of Abstract Window Toolkit (AWT) ?
8. What is the length of the application box made the following Java program?
a) display()
1. import java.awt.*; {
import java.applet.*; public static void main(String args[])
public class myapplet extends Applet {
{ InputStream obj = new FileInputStream("inputoutput.java");
Graphic g; System.out.print(obj.available());
g.drawString("A Simple Applet", 20, 20); }
} }
a) 20 a) true
b) Default value b) false
c) Compilation Error c) prints number of bytes in file
d) Runtime Error d) prints number of characters in the file
1. Which of these classes is used for input and output operation when working with 1. Which of these stream contains the classes which can work on character stream?
bytes? a) InputStream
a) InputStream b) OutputStream
b) Reader c) Character Stream
c) Writer d) All of the mentioned
d) All of the mentioned 2. Which of these class is used to read characters in a file?
2. Which of these class is used to read and write bytes in a file? a) FileReader
a) FileReader b) FileWriter
b) FileWriter c) FileInputStream
c) FileInputStream d) InputStreamReader
d) InputStreamReader 3. Which of these method of FileReader class is used to read characters from a file?
3. Which of these method of InputStream is used to read integer representation of next a) read()
available byte input? b) scanf()
a) read() c) get()
b) scanf() d) getInteger()
c) get() 4. Which of these class can be used to implement the input stream that uses a
d) getInteger() character array as the source?
4. Which of these data type is returned by every method of OutputStream? a) BufferedReader
a) int b) FileReader
b) float c) CharArrayReader
c) byte d) FileArrayReader
d) none of the mentioned 5. Which of these classes can return more than one character to be returned to input
5. Which of these is a method to clear all the data present in output buffers? stream?
a) clear() a) BufferedReader
b) flush() b) Bufferedwriter
c) fflush() c) PushbachReader
d) close() d) CharArrayReader
6. Which of these method(s) is/are used for writing bytes to an outputstream? 1. Which of these packages contain classes and interfaces used for input & output
a) put() operations of a program?
b) print() and write() a) java.util
c) printf() b) java.lang
d) write() and read() c) java.io
d) all of the mentioned
7. What will be the output of the following Java program? (Note: inputoutput.java is 2. Which of these class is not a member class of java.io package?
stored in the disk.) a) String
b) StringReader
import java.io.*; c) Writer
class filesinputoutput d) File
3. Which of these interface is not a member of java.io package? }
a) DataInput a) java
b) ObjectInput b) system
c) ObjectFilter c) java/system
d) FileFilter d) \java\system
4. Which of these class is not related to input and output stream in terms of
functioning? 9. What will be the output of the following Java program? (Note: file is made in c drive.)
a) File
b) Writer
import java.io.*;
c) InputStream class files
d) Reader {
5. Which of these is specified by a File object? public static void main(String args[])
a) a file in disk {
b) directory path
c) directory in disk File obj = new File("/java/system");
d) none of the mentioned System.out.print(obj.canWrite());
6. Which of these is method for testing whether the specified element is a file or a System.out.print(" " + obj.canRead());
directory? }
a) IsFile() }
b) isFile()
a) true false
c) Isfile()
b) false true
d) isfile()
c) true true
7. What will be the output of the following Java code? d) false false

import java.io.*; 10. What will be the output of the following Java program? (Note: file is made in c
class files drive.)
{
public static void main(String args[]) import java.io.*;
{ class files
File obj = new File("/java/system"); {
System.out.print(obj.getName()); public static void main(String args[])
{
}
} File obj = new File("/java/system");
a) java System.out.print(obj.getParent());
b) system System.out.print(" " + obj.isFile());
c) java/system }
d) /java/system }
8. What will be the output of the following Java program? (Note: file is made in c drive.) a) java true
b) java false
import java.io.*; c) \java false
class files d) \java true
{
1. Which of these is a process of writing the state of an object to a byte stream?
public static void main(String args[]) a) Serialization
{ b) Externalization
File obj = new File("/java/system"); c) File Filtering
System.out.print(obj.getAbsolutePath()); d) All of the mentioned
2. Which of these process occur automatically by the java runtime system?
}
a) Serialization
b) Garbage collection 6. If member does not implement serialization, which exception would be thrown?
c) File Filtering a) RuntimeException
d) All of the mentioned b) SerializableException
3. Which of these is an interface for control over serialization and deserialization? c) NotSerializableException
a) Serializable d) UnSerializedException
b) Externalization 7. Default Serialization process cannot be overridden.
c) FileFilter a) True
d) ObjectInput b) False
4. Which of these interface extends DataOutput interface? 1. Which of these is a process of extracting/removing the state of an object from a
a) Serializable stream?
b) Externalization a) Serialization
c) ObjectOutput b) Externalization
d) ObjectInput c) File Filtering
5. Which of these is a method of ObjectOutput interface used to finalize the output d) Deserialization
state so that any buffers are cleared? 2. Which of these process occur automatically by java run time system?
a) clear() a) Serialization
b) flush() b) Memory allocation
c) fflush() c) Deserialization
d) close() d) All of the mentioned
6. Which of these is method of ObjectOutput interface used to write the object to input 3. Which of these interface extends DataInput interface?
or output stream as required? a) Serializable
a) write() b) Externalization
b) Write() c) ObjectOutput
c) StreamWrite() d) ObjectInput
d) writeObject() 4. Which of these is a method of ObjectInput interface used to deserialize an object
1. How an object can become serializable? from a stream?
a) If a class implements java.io.Serializable class a) int read()
b) If a class or any superclass implements java.io.Serializable interface b) void close()
c) Any object is serializable c) Object readObject()
d) No object is serializable d) Object WriteObject()
2. What is serialization? 5. Which of these class extend InputStream class?
a) Turning object in memory into stream of bytes a) ObjectStream
b) Turning stream of bytes into an object in memory b) ObjectInputStream
c) Turning object in memory into stream of bits c) ObjectOutput
d) Turning stream of bits into an object in memory d) ObjectInput
3. What is deserialization? 1. Which of these package contains classes and interfaces for networking?
a) Turning object in memory into stream of bytes a) java.io
b) Turning stream of bytes into an object in memory b) java.util
c) Turning object in memory into stream of bits c) java.net
d) Turning stream of bits into an object in memory d) java.network
4. How many methods Serializable has? 2. Which of these is a protocol for breaking and sending packets to an address across
a) 1 a network?
b) 2 a) TCP/IP
c) 3 b) DNS
d) 0 c) Socket
5. What type of members are not serialized? d) Proxy Server
a) Private 3. How many ports of TCP/IP are reserved for specific protocols?
b) Protected a) 10
c) Static b) 1024
d) Throwable c) 2048
d) 512
4. How many bits are in a single IP address? boolean x = obj1.equals(obj2);
a) 8 System.out.print(x);
b) 16
c) 32 }
d) 64 }
5. Which of these is a full form of DNS? a) 0
a) Data Network Service b) 1
b) Data Name Service c) true
c) Domain Network Service d) false
d) Domain Name Service
9. What will be the output of the following Java program?
6. Which of these class is used to encapsulate IP address and DNS?
a) DatagramPacket import java.io.*;
b) URL import java.net.*;
c) InetAddress
d) ContentHandler public class URLDemo
{
7. What will be the output of the following Java program? public static void main(String[] args)
import java.net.*; {
class networking try
{ {
public static void main(String[] args) throws URL url=new URL("https://www.sanfoundry.com/java-mcq");
UnknownHostException System.out.println("Protocol: "+url.getProtocol());
{ System.out.println("Host Name: "+url.getHost());
InetAddress obj1 = System.out.println("Port Number: "+url.getPort());
InetAddress.getByName("sanfoundry.com"); } catch(Exception e){System.out.println(e);}
InetAddress obj2 = }
InetAddress.getByName("sanfoundry.com"); }
boolean x = obj1.equals(obj2); a) Protocol: http
b) Host Name: www.sanfoundry.com
System.out.print(x); c) Port Number: -1
} d) All of the mentioned
}
a) 0 10. What will be the output of the following Java program?
b) 1 import java.net.*;
c) true
d) false
class networking
{
8. What will be the output of the following Java program? public static void main(String[] args) throws
import java.net.*; UnknownHostException
public class networking {
{ InetAddress obj1 = InetAddress.getByName("cisco.com");
public static void main(String[] args) throws System.out.print(obj1.getHostName());
UnknownHostException }
{ }
InetAddress obj1 = InetAddress.getByName("cisco.com"); a) cisco
b) cisco.com
InetAddress obj2 = c) www.cisco.com
InetAddress.getByName("sanfoundry.com"); d) none of the mentioned
1. Which of these interface abstractes the output of messages from httpd? 8. Which of these is an instance variable of class httpd?
a) LogMessage a) port
b) LogResponse b) cache
c) Httpdserver c) log
d) httpdResponse d) All of the mentioned
2. Which of these class is used to create servers that listen for either local or remote 1. Which of these methods of httpd class is used to read data from the stream?
client programs? a) getDta()
a) httpServer b) GetResponse()
b) ServerSockets c) getStream()
c) MimeHeader d) getRawRequest()
d) HttpResponse 2. Which of these method of httpd class is used to get report on each hit to HTTP
3. Which of these is a standard for communicating multimedia content over email? server?
a) http a) log()
b) https b) logEntry()
c) Mime c) logHttpd()
d) httpd d) logResponse()
4. Which of these methods is used to make raw MIME formatted string? 3. Which of these methods are used to find a URL from the cache of httpd?
a) parse() a) findfromCache()
b) toString() b) findFromCache()
c) getString() c) serveFromCache()
d) parseString() d) getFromCache()
5. Which of these class is used for operating on request from the client to the server? 4. Which of these variables stores the number of hits that are successfully served out
a) http of cache?
b) httpDecoder a) hits
c) httpConnection b) hitstocache
d) httpd c) hits_to_cache
6. Which of these method of MimeHeader is used to return the string equivalent of the d) hits.to.cache
values stores on MimeHeader? 5. Which of these method of httpd class is used to write UrlCacheEntry object into
a) string() local disk?
b) toString() a) writeDiskCache()
c) convertString() b) writetoDisk()
d) getString() c) writeCache()
d) writeDiskEntry()
7. What will be the output of the following Java program?
6. What will be the output of the following Java program?
import java.net.*;
class networking import java.net.*;
{ class networking
public static void main(String[] args) throws Exception {
{ public static void main(String[] args) throws Exception
URL obj = new URL("https://www.sanfoundry.com/javamcq"); {
URLConnection obj1 = obj.openConnection(); URL obj = new URL("https://www.sanfoundry.com/javamcq");
System.out.print(obj1.getContentType()); URLConnection obj1 = obj.openConnection();
} int len = obj1.getContentLength();
} System.out.print(len);
Note: Host URL is written in html and simple text. }
a) html }
b) text Note: Host URL is having length of content 127.
c) html/text a) 126
d) text/html b) 127
c) Compilation Error }
d) Runtime Error a) http
7. Which of these method is used to start a server thread? b) https
a) run() c) www
b) start() d) com
c) runThread()
d) startThread() 7. What will be the output of the following Java program?
8. Which of these method is called when http daemon is acting like a normal web
server?
import java.net.*;
a) Handle() class networking
b) HandleGet() {
c) handleGet() public static void main(String[] args) throws
d) Handleget() MalformedURLException
1. What does URL stands for?
a) Uniform Resource Locator
{
b) Uniform Resource Latch URL obj = new URL("https://www.sanfoundry.com/javamcq");
c) Universal Resource Locator System.out.print(obj.getPort());
d) Universal Resource Latch }
2. Which of these exceptions is thrown by URL class’s constructors? }
a) URLNotFound
a) 1
b) URLSourceNotFound
b) 0
c) MalformedURLException
c) -1
d) URLNotFoundException
d) garbage value
3. Which of these methods is used to know host of an URL?
a) host() 8. What will be the output of the following Java program?
b) getHost()
c) GetHost() import java.net.*;
d) gethost() class networking
4. Which of these methods is used to know the full URL of an URL object? {
a) fullHost()
public static void main(String[] args) throws
b) getHost()
c) ExternalForm() MalformedURLException
d) toExternalForm() {
5. Which of these class is used to access actual bits or content information of a URL? URL obj = new URL("https://www.sanfoundry.com/javamcq");
a) URL System.out.print(obj.getHost());
b) URLDecoder
}
c) URLConnection
d) All of the mentioned }
a) sanfoundry
6. What will be the output of the following Java code? b) sanfoundry.com
c) www.sanfoundry.com
import java.net.*; d) https://www.sanfoundry.com/javamcq
class networking
9. What will be the output of the following Java program?
{
public static void main(String[] args) throws import java.net.*;
MalformedURLException class networking
{ {
URL obj = new URL("https://www.sanfoundry.com/javamcq"); public static void main(String[] args) throws
System.out.print(obj.getProtocol()); MalformedURLException
} {
URL obj = new URL("https://www.sanfoundry.com/javamcq"); Note: Host URL is written in html and simple text.
System.out.print(obj.toExternalForm()); a) html
b) text
} c) html/text
} d) text/html
a) sanfoundry
b) sanfoundry.com 7. What will be the output of the following Java program?
c) www.sanfoundry.com
d) https://www.sanfoundry.com/javamcq import java.net.*;
1. Which of these is a wrapper around everything associated with a reply from an http class networking
server? {
a) HTTP public static void main(String[] args) throws Exception
b) HttpResponse {
c) HttpRequest
d) httpserver URL obj = new URL("https://www.sanfoundry.com/javamcq");
2. Which of these transfer protocol must be used so that URL can be accessed by URLConnection obj1 = obj.openConnection();
URLConnection class object? int len = obj1.getContentLength();
a) http System.out.print(len);
b) https
}
c) Any Protocol can be used
d) None of the mentioned }
3. Which of these methods is used to know when was the URL last modified? Note: Host URL is having length of content 127.
a) LastModified() a) 126
b) getLastModified() b) 127
c) GetLastModified() c) Compilation Error
d) getlastModified()() d) Runtime Error
4. Which of these methods is used to know the type of content used in the URL? 8. What will be the output of the following Java program?
a) ContentType()
b) contentType() import java.net.*;
c) getContentType() class networking
d) GetContentType()
5. Which of these data member of HttpResponse class is used to store the response
{
from an http server? public static void main(String[] args) throws Exception
a) status {
b) address URL obj = new URL("https://www.sanfoundry.com/javamcq");
c) statusResponse URLConnection obj1 = obj.openConnection();
d) statusCode
System.out.print(obj1.getLastModified);
6. What will be the output of the following Java program? }
import java.net.*; }
Note: Host URL was last modified on july 18 tuesday 2013 .
class networking a) july
{ b) 18-6-2013
public static void main(String[] args) throws Exception c) Tue 18 Jun 2013
{ d) Tue Jun 18 2013
URL obj = new URL("https://www.sanfoundry.com/javamcq"); 1. Which of these is a bundle of information passed between machines?
a) Mime
URLConnection obj1 = obj.openConnection(); b) Cache
System.out.print(obj1.getContentType()); c) Datagrams
} d) DatagramSocket
} 2. Which of these class is necessary to implement datagrams?
a) DatagramPacket
b) DatagramSocket c) An event is an object that describes any change by the user and system
c) All of the mentioned d) An event is a class used for defining object, to create events
d) None of the mentioned 3. Which of these methods are used to register a keyboard event listener?
3. Which of these method of DatagramPacket is used to find the port number? a) KeyListener()
a) port() b) addKistener()
b) getPort() c) addKeyListener()
c) findPort() d) eventKeyboardListener()
d) recievePort() 4. Which of these methods are used to register a mouse motion listener?
4. Which of these method of DatagramPacket is used to obtain the byte array of data a) addMouse()
contained in a datagram? b) addMouseListener()
a) getData() c) addMouseMotionListner()
b) getBytes() d) eventMouseMotionListener()
c) getArray() 5. What is a listener in context to event handling?
d) recieveBytes() a) A listener is a variable that is notified when an event occurs
5. Which of these methods of DatagramPacket is used to find the length of byte array? b) A listener is a object that is notified when an event occurs
a) getnumber() c) A listener is a method that is notified when an event occurs
b) length() d) None of the mentioned
c) Length() 6. Event class is defined in which of these libraries?
d) getLength() a) java.io
6. Which of these class must be used to send a datagram packets over a connection? b) java.lang
a) InetAdress c) java.net
b) DatagramPacket d) java.util
c) DatagramSocket 7. Which of these methods can be used to determine the type of event?
d) All of the mentioned a) getID()
7. Which of these method of DatagramPacket class is used to find the destination b) getSource()
address? c) getEvent()
a) findAddress() d) getEventObject()
b) getAddress() 8. Which of these class is super class of all the events?
c) Address() a) EventObject
d) whois() b) EventClass
8. Which of these is a return type of getAddress() method of DatagramPacket class? c) ActionEvent
a) DatagramPacket d) ItemEvent
b) DatagramSocket 9. Which of these events will be notified if scroll bar is manipulated?
c) InetAddress a) ActionEvent
d) ServerSocket b) ComponentEvent
9. Which API gets the SocketAddress (usually IP address + port number) of the c) AdjustmentEvent
remote host that this packet is being sent to or is coming from. d) WindowEvent
a) getSocketAddress() 10. Which of these events will be generated if we close an applet’s window?
b) getAddress() a) ActionEvent
c) address() b) ComponentEvent
d) none of the mentioned c) AdjustmentEvent
1. Which of these packages contains all the classes and methods required for even d) WindowEvent
handling in Java? 1. Which of these events is generated when a button is pressed?
a) java.applet a) ActionEvent
b) java.awt b) KeyEvent
c) java.event c) WindowEvent
d) java.awt.event d) AdjustmentEvent
2. What is an event in delegation event model used by Java programming language? 2. Which of these methods can be used to obtain the command name for invoking
a) An event is an object that describes a state change in a source ActionEvent object?
b) An event is an object that describes a state change in processing a) getCommand()
b) getActionCommand()
c) getActionEvent() 4. Which of these methods can be used to get reference to a component that was
d) getActionEventCommand() removed from a container?
3. Which of these are integer constants defined in ActionEvent class? a) getComponent()
a) ALT_MASK b) getchild()
b) CTRL_MASK c) getContainerComponent()
c) SHIFT_MASK d) getComponentChild()
d) All of the mentioned 5. Which of these are integer constants of ComponentEvent class?
4. Which of these methods can be used to know which key is pressed? a) COMPONENT_HIDDEN
a) getKey() b) COMPONENT_MOVED
b) getModifier() c) COMPONENT_RESIZE
c) getActionKey() d) All of the mentioned
d) getActionEvent() 6. Which of these events is generated when computer gains or loses input focus?
5. Which of these events is generated by scroll bar? a) ComponentEvent
a) ActionEvent b) ContainerEvent
b) KeyEvent c) FocusEvent
c) WindowEvent d) InputEvent
d) AdjustmentEvent 7. FocusEvent is subclass of which of these classes?
6. Which of these methods can be used to determine the type of adjustment event? a) ComponentEvent
a) getType() b) ContainerEvent
b) getEventType() c) ItemEvent
c) getAdjustmentType() d) InputEvent
d) getEventObjectType() 8. Which of these methods can be used to know the type of focus change?
7. Which of these methods can be used to know the degree of adjustment made by a) typeFocus()
the user? b) typeEventFocus()
a) getValue() c) isTemporary()
b) getAdjustmentType() d) isPermanent()
c) getAdjustmentValue() 9. Which of these is superclass of ContainerEvent class?
d) getAdjustmentAmount() a) WindowEvent
8. Which of these constant value will change when the button at the end of scroll bar b) ComponentEvent
was clicked to increase its value? c) ItemEvent
a) BLOCK_DECREMENT d) InputEvent
b) BLOCK_INCREMENT 1. Which of these events is generated when the window is closed?
c) UNIT_DECREMENT a) TextEvent
d) UNIT_INCREMENT b) MouseEvent
1. Which of these events is generated when the size of an event is changed? c) FocusEvent
a) ComponentEvent d) WindowEvent
b) ContainerEvent 2. Which of these methods can be used to obtain the coordinates of a mouse?
c) FocusEvent a) getPoint()
d) InputEvent b) getCoordinates()
2. Which of these events is generated when the component is added or removed? c) getMouseXY()
a) ComponentEvent d) getMouseCordinates()
b) ContainerEvent 3. Which of these methods can be used to change location of an event?
c) FocusEvent a) ChangePoint()
d) InputEvent b) TranslatePoint()
3. Which of these methods can be used to obtain the reference to the container that c) ChangeCordinates()
generated a ContainerEvent? d) TranslateCordinates()
a) getContainer() 4. Which of these are integer constants of TextEvent class?
b) getContainerCommand() a) TEXT_CHANGED
c) getActionEvent() b) TEXT_FORMAT_CHANGED
d) getContainerEvent() c) TEXT_VALUE_CHANGED
d) TEXT_sIZE_CHANGED
5. Which of these methods is used to obtain the object that generated a 5. Which of these interfaces define a method itemStateChanged()?
WindowEvent? a) ComponentListener
a) getMethod() b) ContainerListener
b) getWindow() c) ActionListener
c) getWindowEvent() d) ItemListener
d) getWindowObject() 6. Which of these methods will respond when you click any button by mouse?
6. MouseEvent is subclass of which of these classes? a) mouseClicked()
a) ComponentEvent b) mouseEntered()
b) ContainerEvent c) mousePressed()
c) ItemEvent d) all of the mentioned
d) InputEvent 7. Which of these methods will be invoked if a character is entered?
7. Which of these methods is used to get x coordinate of the mouse? a) keyPressed()
a) getX() b) keyReleased()
b) getXCoordinate() c) keyTyped()
c) getCoordinateX() d) keyEntered()
d) getPointX() 8. Which of these methods is defined in MouseMotionAdapter class?
8. Which of these are constants defined in WindowEvent class? a) mouseDragged()
a) WINDOW_ACTIVATED b) mousePressed()
c) mouseReleased()
b) WINDOW_CLOSED d) mouseClicked()
c) WINDOW_DEICONIFIED 9. Which of these is a superclass of all Adapter classes?
d) All of the mentioned a) Applet
9. Which of these is superclass of WindowEvent class? b) ComponentEvent
c) Event
a) WindowEvent d) InputEvent
b) ComponentEvent UNIT – II & III
c) ItemEvent AWT & SWING
d) InputEvent 1) Where are the following four methods commonly used?
1. Which of these packages contains all the event handling interfaces? 1) public void add(Component c)
a) java.lang 2) public void setSize(int width,int height)
3) public void setLayout(LayoutManager m)
b) java.awt 4) public void setVisible(boolean)
c) java.awt.event a. Graphics class
d) java.event b. Component class
2. Which of these interfaces handles the event when a component is added to a c. Both A & B
d. None of the above
container? 2) Implement the Listener interface and overrides its methods is required to perform
a) ComponentListener in event handling.
b) ContainerListener a. True
c) FocusListener b. False
d) InputListener 3) Which is the container that doesn't contain title bar and MenuBars but it can have
other components like button, textfield etc?
3. Which of these interfaces define a method actionPerformed()?
a. Window
a) ComponentListener
b. Frame
b) ContainerListener
c. Panel
c) ActionListener
d. Container
d) InputListener
4) These two ways are used to create a Frame By creating the object of Frame class
4. Which of these interfaces define four methods?
(association) By extending Frame class (inheritance)
a) ComponentListener
a. True b. False
b) ContainerListener
5) Give the abbreviation of AWT?
c) ActionListener
d) InputListener
a. Applet Windowing Toolkit 14) AWT has more powerful components like tables, lists, scroll panes, color
b. Abstract Windowing Toolkit chooser, tabbed pane etc.
c. Absolute Windowing Toolkit a. True
d. None of the above b. False
15) Which are passive controls that do not support any interaction with the
6) Which method is used to set the graphics current color to the specified color in the user?
graphics class? a. Choice
a. public abstract void setFont(Font font) b. List
b. public abstract void setColor(Color c) c. Labels
c. public abstract void drawString(String str, int x, int y) d. Checkbox
d. None of the above 16) How many types of controls does AWT support?
7) The Java Foundation Classes (JFC) is a set of GUI components which simplify the a. 7
development of desktop applications. b. 6
a. True c. 5
b. False d. 8
8) In Graphics class which method is used to draws a rectangle with the 17) The following
specified width and height? a) It is lightweight.
a. public void drawRect(int x, int y, int width, int height) b) It supports pluggable look and feel.
b. public abstract void fillRect(int x, int y, int width, int height) c) It follows MVC (Model View Controller) architecture
c. public abstract void drawLine(int x1, int y1, int x2, int y2) are the advantages of _____ .
d. public abstract void drawOval(int x, int y, int width, int height) a. Swing
9) Which object can be constructed to show any number of choices in the b. AWT
visible window? c. Both A & B
a. Labels d. None of the above
b. Choice 18) The ActionListener interface is not used for handling action events.
c. List a. True
d. Checkbox b. False
10) Which is used to store data and partial results, as well as to perform 19) Which package provides many event classes and Listener interfaces for
dynamic linking, return values for methods, and dispatch exceptions? event handling?
a. Window a. java.awt
b. Panel b. java.awt.Graphics
c. Frame c. java.awt.event
d. Container d. None of the above
11) Which class is used for this Processing Method processActionEvent( )? 20) Swing is not a part of JFC (Java Foundation Classes) that is used to create
a. Button,List,MenuItem GUI application
b. Button,Checkbox,Choice a. True
c. Scrollbar,Component,Button b. False
d. None of the above 21) The Following steps are required to perform
12) Which method can set or change the text in a Label?
1) Implement the Listener interface and overrides its methods
a. setText() 2) Register the component with the Listener
b. getText() a. Exception Handling
c. All the above b. String Handling
d. None of the above c. Event Handling
13) Which is a component in AWT that can contain another components like d. None of the above
buttons, textfields, labels etc.? 22) Where can the event handling code be written?
a. Window a. Same class
b. Container b. Other class
c. Panel c. Anonymous class
d. Frame d. All mentioned above
23) Which class provides many methods for graphics programming?
a. java.awt A) Exception Handling
b. java.Graphics B) String Handling
c. java.awt.Graphics C) Event Handling
d. None of the above D) None of the above
24) AWT is used for GUI programming in java 10) In which places can put the event handling code
a. True A) Same class
b. False B) Other class
25) The ActionListener interface is not used for handling action events C) Annonymous class
a. True D) All mentioned above
b. False 11) Which package provides many event classes and Listener interfaces for event
2) Which is the container that contain title bar and can have MenuBars. It can have handling?
other components like button, textfield etc.? A) java.awt
A) Panel B) java.awt.Graphics
B) Frame C) java.awt.event
C) Window D) None of the above
D) Container 12) To use the ActionListener interface it must be implemented by a class there are
3) Which is a component in AWT that can contain another components like buttons, several ways to do that find in the following?
textfields, labels etc.? A) Creating a new class
A) Window B) using the class the graphical component
B) Container C) an anonymous inner class
C) Panel D) All mentioned above
D) Frame 13) The ActionListener interface is not used for handling action events?
4) AWT is used for GUI programming in java? A) True
A) True B) False
B) False 14) The ActionListener interface is used for handling action events,For example,it's
) The following specifies the advantages of used by a
It is lightweight. A) JButton
It supports pluggable look and feel. B) JCheckbox
It follows MVC (Model View Controller) architecture. c) JMenuItem
A) Swing d) All of these
B) AWT 1) Give the abbreviation of AWT?
C) Both A & B A) Applet Windowing Toolkit
D) None of the above B) Abstract Windowing Toolkit
6) Swing is not a part of JFC (Java Foundation Classes) that is used to create GUI
application? C) Absolute Windowing Toolkit
A) True D) None of the above
B) False 2) Which is the container that contain title bar and can have MenuBars. It
7) Which class provides many methods for graphics programming? can have other components like button, textfield etc.?
A) java.awt A) Panel
B) java.Graphics B) Frame
C) java.awt.Graphics
D) None of the above
C) Window
8) These two ways are used to create a Frame D) Container
By creating the object of Frame class (association) 3) Which is a component in AWT that can contain another components like
By extending Frame class (inheritance) buttons, textfields, labels etc.?
A) True A) Window
B) False B) Container
9) The Following steps are required to perform
1) Implement the Listener interface and overrides its methods
C) Panel
2) Register the component with the Listener D) Frame
4) AWT is used for GUI programming in java?
A) True 12) To use the ActionListener interface it must be implemented by a class
B) False there are several ways to do that find in the following?
5) The following specifies the advantages of A) Creating a new class
B) using the class the graphical component
It is lightweight. C) an anonymous inner class
It supports pluggable look and feel. D) All mentioned above
It follows MVC (Model View Controller) architecture. 13) The ActionListener interface is not used for handling action events?
A) True
A) Swing B) False
B) AWT 14) The ActionListener interface is used for handling action events,For
C) Both A & B example,it's used by a
D) None of the above A) JButton
6) Swing is not a part of JFC (Java Foundation Classes) that is used to B) JCheckbox
create GUI application? D) JMenuItem
A) True C) All of these
B) False 15) Which is the container that doesn't contain title bar and MenuBars. It
7) Which class provides many methods for graphics programming? can have other components like button, textfield etc?
A) java.awt A) Window
B) java.Graphics B) Frame
C) java.awt.Graphics C) Panel
D) None of the above D) Container
8) These two ways are used to create a Frame 16) How many types of controls does AWT supports these controls are
By creating the object of Frame class (association) subclasses of component?
By extending Frame class (inheritance) A) 7
A) True B) 6
B) False C) 5
9) The Following steps are required to perform D) 8
1) Implement the Listener interface and overrides its methods 17) Which are passive controls that do not support any interaction with the
2) Register the component with the Listener user?
A) Exception Handling A) Choice
B) String Handling B) List
C) Event Handling C) Labels
D) None of the above D) Checkbox
10) In which places can put the event handling code 18) By which method You can set or change the text in a Label?
A) Same class A) setText()
B) Other class B) getText()
C) Annonymous class C) Both A & B
D) All mentioned above D) None of the above
11) Which package provides many event classes and Listener interfaces 19) Which class is used to create a pop-up list of items from which the
for event handling? user may choose?
A) java.awt A) List
B) java.awt.Graphics B) Choice
C) java.awt.event C) Labels
D) None of the above D) Checkbox
20) Which object can be constructed to show any number of choices in the 4)public void setVisible(boolean)
visible window? A) Graphics class
A) Labels B) Component class
B) Choice C) Both A & B
C) List D) None of the above
D) Checkbox 28) In Graphics class which method is used to draws a rectangle with the
21) Which class is used for this Processing Method processActionEvent( specified width and height?
)? A) public void drawRect(int x, int y, int width, int height)
A) Button,List,MenuItem B) public abstract void fillRect(int x, int y, int width, int height)
B) Button,Checkbox,Choice C) public abstract void drawLine(int x1, int y1, int x2, int y2)
C) Scrollbar,Component,Button D) public abstract void drawOval(int x, int y, int width, int height)
D) None of the above 29) Implement the Listener interface and overrides its methods is required
22) The Swing Component classes that are used in Encapsulates a to perform in event handling?
mutually exclusive set of buttons? A) True
A) AbstractButton B) False
B) ButtonGroup 30) The Java Foundation Classes (JFC) is a set of GUI components which
C) JButton simplify the development of desktop applications?
D) ImageIcon A) True
23) Which is used to store data and partial results, as well as to perform B) False
dynamic linking, return values for methods, and dispatch exceptions? Unit - IV
A) Window
B) Panel JDBC
C) Frame ) JDBC is a Java API that is used to connect and execute query to the
D) Container database?
24) The following way is used to create a frame is by creating the object of A) True
Frame class? B) False
A) inheritance 2) Which of these API represents that software programs can follow to
B) association communicate with each other?
C) Both A & B A) Interfaces
D) None of the above B) Classes
25) AWT more powerful components like tables, lists, scroll panes, color C) Both A & B
chooser, tabbed pane etc.? D) None of the above
A) True 3) An API can be created for
B) False A) applications
26) In Graphics class Which method is used to set the graphics current B) libraries
color to the specified color? C) operating systems
A) public abstract void setFont(Font font) D) All mentioned above
B) public abstract void setColor(Color c) 4) How many types of JDBC drivers available?
C) public abstract void drawString(String str, int x, int y) A) 3
D) None of the above B) 4
27) These four methods commonly used in? C) 2
1)public void add(Component c) D) 5
2)public void setSize(int width,int height) 5) In the following JDBC drivers which is known as partially java driver?
3)public void setLayout(LayoutManager m) A) JDBC-ODBC bridge driver
B) Native-API driver
C) Network Protocol driver 15) The default username for the mysql database is?
D) Thin driver A) System
7) Which driver uses ODBC driver to connect to the database? B) root
A) JDBC-ODBC bridge driver C) Both A & B
B) Native-API driver D) None of the above
C) Network Protocol driver 17) In DriverManager class which method is used to establish the
D) Thin driver connection with the specified url?
8) Which driver converts JDBC calls directly into the vendor-specific A) public static void registerDriver(Driver driver)
database protocol? B) public static void deregisterDriver(Driver driver)
A) Native-API driver C) public static Connection getConnection(String url)
B) Network Protocol driver D) public static Connection getConnection(String url,String
C) Thin driver userName,String password)
D) Both B & C 18) In Connection interface which method Drops all changes made since
9) Why java program cannot directly communicate with an ODBC driver? the previous commit/rollback?
A) ODBC written in C# language A) public void rollback()
B) ODBC written in C language B) public void commit()
C) ODBC written in C++ language C) public void close()
D) None of the above D) public Statement createStatement()
10) How many steps are used to connect any java application with the 19) Which interface provides methods to execute queries with the
database in java using JDBC? database?
A) 5 A) Connection interface
B) 4 B) Statement interface
C) 3 C) ResultSet interface
D) 6 D) None of the above
11) Which method of Class class is used to register the driver class, This 20) Which maintains a cursor pointing to a particular row of data,Initially,
method is used to dynamically load the driver class? cursor points to before the first row?
A) forName() A) Connection interface
B) getConnection() B) Statement interface
C) createStatement() C) ResultSet interface
D) executeQuery() D) None of the above
12) The default username for the oracle database is system? 21) ResultSet object can be moved forward only and it is updatable?
A) True A) True
B) False B) False
13) Give the ways to set Temporary Path of JDK in Windows? 22) Which is used to execute parameterized query?
A) Open command prompt A) Statement interface
B) copy the path of jdk/bin directory B) PreparedStatement interface
C) write in command prompt: set path=copied_path C) ResultSet interface
D) All mentioned above D) None of the above
14) Abbrevate the term DSN? 23) The performance of the application will be faster if you use
A) Digital Source Name PreparedStatement interface because query is compiled only once?
D) Data Source Name A) True
C) Data Socket Name B) False
D) Data String Name 24) This is an example of prepared statement interface that ?
PreparedStatement stmt=con.prepareStatement("select * from emp");
ResultSet rs=stmt.executeQuery(); 32) ARRAY,CLOB,BLOB and REF type columns can be updated in?
while(rs.next()){ A) JDBC 2.0
System.out.println(rs.getInt(1)+" "+rs.getString(2)); B) JDBC 1.0
} C) JDBC 3.0
D) JDBC 4.0
A) deletes the record 33) In Transaction Management of JDBC which means once a transaction
B) retrieve the record has been committed, it will remain so, even in the event of errors, power
C) updates the record loss etc.?
D) inserts the record A) Atomicity
25) ResultSetMetaData interface is useful because it provides methods to B) Isolation
get metadata from the ResultSet object? C) Consistency
A) True D) Durability
B) False 34) In Transaction Management in JDBC Transaction represents?
26) By using Which interface You can store images in the database in java A) single unit of work
by the help of ? B) Multiple unit of work
A) PreparedStatement interface C) Both A & B
B) ResultSetMetaData interface D) None of the above
C) DatabaseMetData interface 35) which interfaces provide methods for batch processing in JDBC?
D) None of the above A) java.sql.Statement
27) Abbreviate the full form of CLOB? B) java.sql.PreparedStatement
A) Character Large Object C) Both A & B
B) Character Loop Object D) None of the above
C) Collection Large Object 36) JDBC RowSet is the wrapper of ResultSet,It holds tabular data like
D) Collection Loop Object ResultSet but it is easy and flexible to use?
28) Which is used to call the stored procedures and functions, A) True
CallableStatement interface? B) False
A) CallableStatement Interface 1. When we invoke repaint() for a java.awt.Component object, the AWT invokes the
B) PreparedStatement Interface method:
• draw()
C) Both A & B
• show()
D) None of the above • paint()
29) The performance of the application will be faster if you use • update()
PreparedStatement interface because query is compiled only once? 2. What does the following line of code do?
A) True Textfield text = new Textfield(10);
B) False • Creates text object that can hold 10 rows of text.
30) The ACID properties does not describes the transaction management • Creates text object that can hold 10 columns of text.
• Creates the object text and initializes it with the value 10.
well ? • The code is illegal.
A) True 3. Which of the following applet tags is legal to embed an applet class named Test into
B) False a Web page?
31) JDBC stands for? • < applet
A) Java database connectivity class = Test width = 200 height = 100>
B) Java database concept • < applet
code = Test.class width = 200 height = 100>
C) Java database communications
• < applet>
D) None of the above code = Test.class width = 200 height = 100>
• < applet
code = Test.class width = 200 height = 100 • (A) & (C)
• < applet • (C) & (D)
param = Test.class width = 200 height = 100> 9. DataInput is
4. Which of the following methods can be used to draw the outline of a square within a • an abstract class defined in java.io.
java.awt.Component object? • an interface that defines methods to read primitive data types.
(A) fillRect() • a class we can use to read primitive data types.
(B) drawLine() • an interface that defines methods to open files.
(C) drawRect() 10. Which of the following statements are true?
(D) drawString() (A) Unicode characters are all 16 bits.
(E) drawPolygon() (B) UTF characters are all 24 bits.
• (A), (B), (C) & (E) (C) Reader class has methods that can read integers and floats.
• (A), (B) & (C) (D) File class may be used to rename a file.
• (C), (D) & (E) (E) DataOutputStream objects are used to write primitive data to a file.
• (B) & (C) • (A), (C), (D) & (E)
• (B), (C) & (E) • (A), (B) & (D)
5. Which of the following methods can be used to change the size of a • (B), (D) & (E)
java.awt.Component object? • (A), (D) & (E)
(A) dimension() • (A) & (D)
(B) setSize() 11. Which are the valid ways to create DataInputStream streams?
(C) area() • new DataInputStream();
(D) size() • new DataInputStream(new FileInputStream("in.dat");
(E) resize() • new DataInputStream("in.dat", "r");
• (A), (B), (C) & (E) • new DataInputStream("in.dat")
• (A), (B) & (E) • new DataInputStream(new File("in.dat"));
• (B), (D) & (E) 12. Which exception is thrown by the read() method of InputStream class?
• (B) & (E) • Exception
• (D) & (E) • FileNotFoundException
6. Which of the following methods can be used to remove a java.awt.Component • IOException
object from the display? • ReadException
• delete() • None of these
• remove() 13. If you want to assign a value of 99 to the variable year, then which of the following
• disappear() lines can be used within an tag?
• hide() • number = getParameter(99)
• move() • < number = 99 >
7. The setBackground() method is part of the following class in java.awt package: • < param = radius value = 99 >
• Graphics • < param name = number value = 99 >
• Applet • < param number = 99 >
• Container 14. Given file is a File object, which of the following are legal statements to create a
• Object new file?
• Component (A) file.create();
8. Which of the following strings can be used as mode strings for creating a (B) FileOutputStream fos = new FileOutputStream(file);
RandomAccessFile object? (C) FileWrter out = new FileWriter(file);
(A) "r" (D) FileInputStream fis = new FileInputStream(file);
(B) "w" (E) RandomAccessFile raf = new RandomAccessFile(file);
(C) "rw" • (B), (C) & (E)
(D) "wr" • (A), (B), (D) & (E)
(E) "0" • (B), (C) & (D)
• (A), (B), (C) & (E) • (B), (D) & (E)
• (A), (B) & (C) • (B) & (C)
• (B), (D) & (E)

You might also like