Advanced Java Programming One Mark Questions
Advanced Java Programming One Mark Questions
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)