PRJ311

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 30

c

To get an object NumberFormat class that initialized to the specified locale, we use
Select one:
a. getNumberFormat()
b. getCurrencyInstance()
c. getNumberInstance()
d. getInstance()
b
Which type of driver can interpret JDBC calls to the database-specific native call
interface
Select one:
a. Type-1
b. Type-2
c. Type-4
d. Type-3
bc
Which are advantages of JDBC ? (select two)
Select one or more:
a. enable connecting to any database system
b. vendor independent
c. platform independent
d. database access faster than other languages
a
Formatting the captions of the GUI components ensures that the look and feel of the
application is in a locale-sensitive manner
Select one:
a. TRUE
b. FALSE
ac
Which statements are CORRECT about properties file? (Select 2)

Select one or more:


a. A Locale is an identifier for a particular combination of language and region
b. To create a properties file, it must use Netbeans or a Java editor
c. Extensions of the properties file must be ".properties"
b
Internationalized software should be developed such that it can be adapted without
engineering changes
Select one:
a. FALSE
b. TRUE
c
Which type of driver can use a bridging technology that provides JDBC access via
ODBC drivers
Select one:
a. Type-4
b. Type-2
c. Type-1
d. Type-3
b
RMI does not allow you to serialize and transmit objects
Select one:
a. TRUE
b. FALSE
b
Which distributed object technology is most appropriate for systems that consist entirely
of Java objects?
Select one:
a. CORBA
b. RMI
c. DOM
d. DCE
b
When using URL class, which method is used to make a connection with that URL?
Select one:
a. makeConnection()
b. openConnection()
c. connect()
d. accept()
c
When a connection is established, we can get which streams
Select one:
a. input stream
b. output stream
c. both input stream and output stream
d. in-out stream
b
A server must retrieve the InputStream and OutputStream from the proxy socket object
to communicate with the client
Select one:
a. FALSE
b. TRUE
Nâng cấp để gỡ bỏ quảng cáo
Chỉ 0,99 US$ / tháng
c
The _______ method wakes up all threads that are waiting for a monitor
Select one:
a. notify()
b. join()
c. notifyAll()
d. wait()
a
Which RMI layer make invocation to remote methods
Select one:
a. Remote Reference layer
b. Transport layer
c. Stub and Skeleton layer
a
______ facilitates many parts of same program to run serially but access a same
resource
Select one:
a. Multithread
b. DaemonThread
c. Threading
d. MonoThread
b
You are trying to retrieve the InputStream of the socket. Which of the options will help
you to achieved this?

Select one:
a. Socket socket;
String host;
BufferedReader reader;
try {
socket = new Socket("localhost", -200);
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch(Exception ex) {
ex.printStackTrace();
}
b. Socket socket;
String host;
BufferedReader reader;
try {
socket = new Socket("localhost", 200);
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch(Exception ex) {
ex.printStackTrace();
} Correct
c. Socket socket;
String host;
BufferedReader reader;
try {
socket = new Socket("localhost", 200);
reader = new BufferedReader(new InputStreamReader(socket.getStream()));
} catch(Exception ex) {
ex.printStackTrace();
}
d. Socket socket;
String host;
BufferedReader reader;
try {
socket = new Socket("localhost", 200);
reader = new BufferedReader(new InputStream(socket.getInputStream()));
} catch(Exception ex) {
ex.printStackTrace();
}
b
To create ServerSocket object, it should know the address or port of the client to
communicate
Select one:
a. TRUE
b. FALSE
b
A remote object is an instance of the class that implements the java.rmi.Remote
interface
Select one:
a. FALSE
b. TRUE
d
The _______ condition describes a situation where two or more threads a blocked
forever, waiting for each other
Select one:
a. synchronization
b. race
c. blocking
d. deadlock
b
Remote object and remote server are the same concept
Select one:
a. TRUE
b. FALSE
c
_____ is used to transmit and receive data
Select one:
a. Transport layer
b. Remote Reference layer
c. Stub and Skeleton layer
a
All the remote methods declared should be qualified to throw the exception
___________
Select one:
a. java.rmi.RemoteException
b. java.rmi.ServerRuntimeException
c. java.rmi.MarshalException
d. java.rmi.RMIException
a
Which class stores information about an Internet resource address including host name,
file name, port number.
Select one:qualified
a. URL
b. Connection
c. InternetAddr
d. URLConnection
c
Which protocol is used in RMI connection
Select one:
a. rmip
b. ftp
c. rmic
d. http
a
The isAlive() method sends a query to inquire, whether the thread is block or not
Select one:
a. FALSE
b. TRUE
b
The ______ method with the argument as true will convert the user thread to a daemon
thread
Select one:
a. isDaemon()
b. setDaemon()
c. convertToDaemon()
d. SetDaemon()
c
Which package providing classes and interfaces for distributed computing in Java
Select one:
a. java.net
b. javax.rmi
c. java.rmi
d. javax.net
c
Which statements are TRUE about accept() method - select 2?

Select one or more:


a. The accept() method, once invoked, server will wait till a client requests for a
connection Incorrect
b. The accept() method is a blocking method
c. When a client requests, the accept() method creates an object of class ServerSocket
and returns it
b
The ServerSocket class has a method clientAccept() for listening to client request?
Select one:
a. TRUE
b. FALSE
c
Which method is used to to retrieve the row IP address in textual format
Select one:
a. getFile()
b. getLocalHost()
c. getHostAddress()
d. getHost()
c
The _____ method forces the current running thread to wait until the thread it is joining
with is no longer alive
Select one:
a. interrupt()
b. wait()
c. join()
d. sleep()
b
TCP is a connection-based protocol that provide a reliable flow of data between two
computers
Select one:
a. FALSE
b. TRUE
a
Java provides the java.net package which contains all the necessary classes to perform
system-dependent network communications

Select one:
a. TRUE
b. FALSE
b
The JFileChooser by default displays all the files in the current directory
Select one:
a. FALSE
b. TRUE
a
Thread priorities are numbers and range from Thread.NORM_PRIORITY to
Thread.MAX_PRIORITY
Select one:
a. FALSE
b. TRUE
a
The ______ method causes a thread to release the lock or monitor of the object,
allowing another thread to access it
Select one:
a. wait()
b. notifyAll()
c. finalize()
d. notify()
c
The ______ method returns true if the thread is a user thread
Select one:
a. verifyDaemon()
b. setDaemon()
c. isDaemon()
d. getDaemon()
a
The getPriority() and setPriority() methods retrieve and set the current priority of any
thread respectively
Select one:
a. TRUE
b. FALSE
a
The deadlock situation allows the normal execution of the program after few minutes
Select one:
a. FALSE
b. TRUE
b
Using new TextField(10) will create a TextField that only accepts 10 characters of input.
Select one:
a. Depends on the particular implementation of the Java Virtual Machine
b. FALSE
c. TRUE
a
The JList has a method addListSelectionListener() to register a selection listener
Select one:
a. TRUE
b. FALSE
e
Which method do you use to start a Thread?
Select one:
a. init()
b. Depends on the particular implementation of the Java Virtual Machine
c. run()
d. begin()
e. start()
f. departure()
ba
A synchronised block is a _____ or a _____ qualified by synchronized keyword
Select one or more:
a. block of code
b. method
c. class
d. function
b
The lock in synchronized block is based on the method and on the object
Select one:
a. FALSE
b. TRUE
a
A menu system provides a bar above the window's title bar called as menu bar
Select one:
a. FALSE
b. TRUE
acd
Which statements are CORRECT about network resource? (Select 3)

Select one or more:


a. The resource can be an HTML page, an image or simply any file
b. In URL, port number to which you connect has to be specified
c. URL is a reference or an address to a resource on the Internet
d. The format of the resource name depends on the protocol being used
b
Reserved ports ranges from 0 to 1023
Select one:
a. FALSE
b. TRUE
a
A JDialog is a top-level container
Select one:
a. TRUE
b. FALSE
b
How many items can be selected from a JComboBox object at a time?

A. 0
B. 1
C. 2
D. Unlimited
b
_______________ returns the selected item on a JComboBox jcbo.

A. jcbo.getSelectedIndex()
B. jcbo.getSelectedItem()
C. jcbo.getSelectedIndices()
D. jcbo.getSelectedItems()
c
The method __________ adds an item s into a JComboBox jcbo.

A. jcbo.add(s)
B. jcbo.addChoice(s)
C. jcbo.addItem(s)
D. jcbo.addObject(s).
b
Clicking a JComboBox object generates an ItemEvent event,

A. if an item is selected.
B. if a new item is selected.
c
____________ is a component that enables the user to choose a single value or
multiple values.

A. A text field
B. A combo box
C. A list
D. A label
c
______________ sets the background of the selected item in list jlst to yellow.

A. jlst.setBackground(Color.YELLOW)
B. jlst.setSelectedBackground(Color.YELLOW)
C. jlst.setSelectionBackground(Color.YELLOW)
D. jlst.setSelectionbackground(Color.YELLOW)
a
Clicking a JList object generates __________ events.

A. ActionEvent and ItemEvent


B. ItemEvent and ComponentEvent
C. ComponentEvent and ContainerEvent
D. ActionEvent and ContainerEvent
a
The coordinate of the upper-left corner of a frame is __________.

A. (0, 0)
B. (25, 25)
C. (100, 100)
D. (10, 10)
a
Suppose a button jbt is placed in a frame, the coordinate of the button within the content
pane of the frame is _______.
A. (jbt.getX(), jbt.getY())
B. (jbt.x, jbt.y)
C. cannot be obtained
D. (0, 0)
b
The header for the paintComponent method is ________________.

A. private void paintComponent(Graphics g)


B. protected void paintComponent(Graphics g)
C. public void paintComponent(Graphics g)
D. protected void paintComponent()
c
You should override the __________ method to draw things on a Swing component.

A. repaint()
B. update()
C. paintComponent()
D. init()
a
You can draw graphics on any GUI components.

A. true
B. false
c
To draw graphics, it is better to define a class that extends ________ and override the
paintComponent method.

A. JLabel
B. JButton
C. JPanel
D. JComponent
d
import java.awt.*;
import javax.swing.*;

public class Test {


public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.add(new MyDrawing("Welcome to Java!"));
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setVisible(true);
}
}
class MyDrawing extends JPanel {
String message;

public MyDrawing(String message) {


this.message = message;
}

public void paintcomponent(Graphics g) {


super.paintComponent(g);

g.drawString(message, 20 ,20);
}
}

A. The program runs fine and displays Welcome to Java!


B. The program has a compile error because the paintcomponent should be spelled as
paintComponent.
C. The program has a runtime error because the paintcomponent should be spelled as
paintComponent.
D. The program runs, but it does not display the message.
E. It is a runtime error to invoke the setVisible(true) twice.
c
import java.awt.*;
import javax.swing.*;

public class Test extends JFrame {


public Test() {
add(new MyDrawing("Welcome to Java!"));
}

public static void main(String[] args) {


JFrame frame = new JFrame();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

class MyDrawing extends JPanel {


String message;

public MyDrawing(String message) {


this.message = message;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);

g.drawString(message, 20 ,20);
}
}

A. The program runs fine and displays Welcome to Java!


B. The program would display Welcome to Java! if new JFrame() is replaced by Test().
C. The program would display Welcome to Java! if new JFrame() is replaced by new
Test().
D. The program would display Welcome to Java! if new JFrame() is replaced by new
Test("My Frame").
d
Analyze the following code.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test1 extends JFrame {


public Test1() {
add(new MyCanvas());
}

public static void main(String[] args) {


JFrame frame = new Test1();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

class MyCanvas extends JPanel {


private String message;

public void setMessage(String message) {


this.message = message;
}

public void paintComponent(Graphics g) {


super.paintComponent(g);

g.drawString(message, 20, 20);


}
}
A. The program runs fine and displays nothing since you have not set a string value.
B. The program would display Welcome to Java! if you replace new MyCanvas() by new
MyCanvas("Welcome to Java!").
C. The program has a compile error because new Test1() is assigned to frame.
D. The program has a NullPointerException since message is null when
g.drawString(message, 20, 20) is executed.
b
Given a Graphics object g, to draw a line from the upper left corner to the bottom right
corner, you use __________.

A. g.drawLine(0, 0, 100, 100)


B. g.drawLine(0, 0, getWidth(), getHeight())
C. g.drawLine(0, 0, getHeight(), getHeight())
D. g.drawLine(0, 0, getWidth(), getWidth())
c
Given a Graphics object g, to draw an outline of a rectangle of width 20 and height 50
with the upper-left corner at (20, 20), you use __________.

A. g.drawRect(20, 50, 20, 20)


B. g.drawRectFill(20, 20, 20, 50)
C. g.drawRect(20, 20, 20, 50)
D. g.drawRectFill(20, 50, 20, 20)
d
Given a Graphics object g, to draw an circle with radius 20 centered at (50, 50), you use
__________.

A. g.drawOval(50, 50, 20, 20)


B. g.drawOval(50, 50, 40, 40)
C. g.drawOval(30, 30, 20, 20)
D. g.drawOval(30, 30, 40, 40)
e
Given a Graphics object g, to draw a filled oval with width 20 and height 30 centered at
(50, 50), you use __________.

A. g.fillOval(50, 50, 20, 30)


B. g.fillOval(50, 50, 40, 30)
C. g.fillOval(30, 30, 20, 30)
D. g.fillOval(30, 30, 40, 30)
E. g.fillOval(40, 35, 20, 30)
a
To repaint graphics, invoke __________ on a Swing component.

A. repaint()
B. update()
C. paintComponent()
D. init()
c
Invoking __________ returns the width of the string in a FontMetrics object fm.

A. getLength(s)
B. fm.getHeight(s)
C. fm.stringWidth(s)
D. fm.getWidth(s)
b
To create an Image object from an ImageIcon object imageIcon, use the __________
method.

A. imageIcon.image()
B. imageIcon.getImage()
C. imageIcon.setImage()
D. imageIcon.returnImage()
a
Swing components that don't rely on native GUI are referred to as ___________.

A. lightweight components
B. heavyweight components
C. GUI components
D. non-GUI components
a
__________ are referred to as heavyweight components.

A. AWT components
B. Swing components
C. GUI components
D. Non-GUI components
d
Which of the following classes is a heavyweight component?

A. JButton
B. JTextField
C. JPanel
D. JFrame
c
Which component cannot be added to a container?

A. JPanel
B. JButton
C. JFrame
D. JComponent
c
What is best to describe the relationship between a container and a SWing GUI object
in the container?

A. Association
B. Aggregation
C. Composition
D. Inheritance
b
What is best to describe the relationship between a container and a layout manager?

A. Association
B. Aggregation
C. Composition
D. Inheritance
d
What is best to describe the relationship between JComponent and JButton?

A. Association
B. Aggregation
C. Composition
D. Inheritance
c
Analyze the following code.

import java.awt.*;
import javax.swing.*;

public class Test {


public static void main(String[] args) {
Component c = new JButton("OK");
JFrame frame = new JFrame("My Frame");
frame.add(c);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

A. You cannot assign a JButton to a variable of java.awt.Component.


B. You can only add c to a container because c's type is Component.
C. You cannot add a Swing component directly to a JFrame using add(c) prior to JDK
1.4, but it is OK in JDK 1.5.
D. You cannot create a JFrame using new JFrame("My Frame").
c
The correct order of the following three statements is ___________.

1. frame.setLocationRelativeTo(null);
2. frame.setSize(100, 200);
3. frame.setVisible(true);

A. 1 2 3
B. 1 3 2
C. 2 1 3
D. 3 2 1
b
Analyze the following code.

import java.awt.*;
import javax.swing.*;

public class Test {


public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.add(new JButton("OK"));
frame.add(new JButton("Cancel"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}

A. Only button OK is displayed.


B. Only button Cancel is displayed.
C. Both button OK and button Cancel are displayed and button OK is displayed on the
left side of button OK.
D. Both button OK and button Cancel are displayed and button OK is displayed on the
right side of button OK.
a
How many frames are displayed?

import javax.swing.*;

public class Test {


public static void main(String[] args) {
JFrame f1 = new JFrame("My Frame");
JFrame f2 = f1;
JFrame f3 = f2;
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
}
}
A. 1.
B. 2.
C. 3.
c
How many frames are displayed?

import javax.swing.*;

public class Test extends JFrame {


public static void main(String[] args) {
JFrame f1 = new Test();
JFrame f2 = new Test();
JFrame f3 = new Test();
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
}
}

A. 1.
B. 2.
C. 3.
D. 0.
a
Which of the following statements is for terminating the program when closing the
frame?

A. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
B. frame.setDefaultCloseOperation(null)
C. frame.setDefaultCloseOperation(JFrame.STOP_ON_CLOSE)
D. frame.setDefaultCloseOperation(JFrame.TERMINATE_ON_CLOSE)
c
Which of the following statements is for placing the frame's upper left corner to (200,
100)?

A. frame.setLocation(100, 100)
B. frame.setLocation(100, 200)
C. frame.setLocation(200, 100)
D. frame.setLocation(200, 200)
b
What layout manager should you use so that every component occupies the same size
in the container?

A. a FlowLayout
B. a GridLayout
C. a BorderLayout
D. any layout
a
What should you use to position a Button within an application Frame so that the size of
the Button is NOT affected by the Frame size?

A. a FlowLayout
B. a GridLayout
C. the center area of a BorderLayout
D. the East or West area of a BorderLayout
E. the North or South area of a BorderLayout
D
How do you indicate where a component will be positioned using Flowlayout?
a) North, South,East,West
b) Assign a row/column grid reference
c) Pass a X/Y percentage parameter to the add method
d) Do nothing, the FlowLayout will position the component
A
How do you change the current layout manager for a container?
a) Use the setLayout method
b) Once created you cannot change the current layout manager of a component
c) Use the setLayoutManager method
d) Use the updateLayout method
B
When using the GridBagLayout manager, each new component requires a new
instance of the GridBagConstraints class. Is this statement true or false?
a) true
b) false
D
In Java, what do you call an area on the screen that has nice borders and various
buttons along the top border?
A. A window.
B. A screen.
C. A box.
D. A frame.
C
What is the name of the Swing class that is used for frames?
A. Window
B. Frame
C. JFrame
D. SwingFrame
A
What method sets the size of the displayed JFrame?
A. setSize( int width, int height)
B. setSize( int height, int width)
C. setVisible( int width, int height)
D. setVisible( int height, int width)
D
The size of a frame on the screen is measured in:
A. inches
B. nits
C. dots
D. pixels
D
What is a container object in GUI programming?

A. A container is another name for an array or vector.


B. A container is any class that is made up of other classes.
C. A container is a primitive variable that contains the actual data.
D. A container is an object like a frame that has other GUI components placed inside of
it.
B
Fill in the blanks so that this program displays a JFrame:>

import java.awt.*;
import javax.swint.*;

public class microGUI


{
public static void main ( String[] args )
{
JFrame frm = new ___________();
frm.___________( 150, 100 );
frm.___________( true );
}
}
A. Form, setVisible, setOn
B. JFrame, setSize, setVisible
C. Frame, setVisible, setSize
D. Window, setSize, paint
A
Which of the following sets the frame to 300 pixels wide by 200 high?

A. frm.setSize( 300, 200 );


B. frm.setSize( 200, 300 );
C. frm.paint( 300, 200 );
D. frm.setVisible( 300, 200 );
A
What is it called when a program is written to respond to the button clicks, menu
selections, and other actions of the user in whatever order the user does them?
a. Event-driven programming.
b. Action-driven programming.
c. User-driven programming.
d. Mouse-driven programming
B
Usually GUI programs are written by using existing software components provided in a
toolkit. The Java toolkit used in this chapter is the:
a. GUI toolkit
b. Abstract Windowing Toolkit
c. Graphics Event Toolkit
d. Java Enhancement Toolkit
C
The three software parts of a GUI program are:
a. Windows, Buttons, Mice
b. GUI Components, Graphics, Code
c. GUI Components, Event Listeners, Application Code
d. Frames, Code, Events
A
What is the one component that nearly all GUI programs will have?
a. Frame
b. Mouse
c. Monitor
d. Button
D
What is a container object in GUI programming?
a. A container is another name for an array or vector.
b. A container is any class that is made up of other classes.
c. A container is a primitive variable that contains the actual data.
d. A container is an object like a Frame that has other GUI components placed inside of
it.
B
Fill in the blanks so that the following draws a Frame containing "Hello".
import java.awt.*;

class helloFrame ___________ Frame


{
public void ___________( Graphics g )
{
g.___________("Hello", 10, 50 );
}
}

public class Tester


{
public static void main ( String[] args )
{
helloFrame frm = new helloFrame();
frm.setSize( 150, 100 );
frm.setVisible( true );
}
}
a. import, drawString, paint
b. extends, paint, drawString
c. extends, draw, paint
d. include, drawString, paint
C
When is the paint() method of a frame object called?
a. The user calls it to display the frame.
b. The main() method calls it once when the program starts.
c. The Java system calls it every time it decides to display the frame.
d. The Java system calls it once when the program starts.
D
What is a Graphics object?
a. The Graphics object represents the part of the Frame that you can draw on.
b. The Graphics object represents the whole Frame.
c. The Graphics object represents the entire monitor.
d. The Graphics object represents the graphics board.
D
Which of these is a process of extracting/removing the state of an object from a stream?
a) Serialization
b) Externalization
c) File Filtering
d) Deserialization
D
Which of these process occur automatically by java run time system?
a) Serialization
b) Memory allocation
c) Deserialization
d) All of the mentioned
B
Which of these is an interface for control over serialization and deserialization?
a) Serializable
b) Externalization
c) FileFilter
d) ObjectInput
D
Which of these interface extends DataInput interface?
a) Serializable
b) Externalization
c) ObjectOutput
d) ObjectInput
C
Which of these is a method of ObjectInput interface used to deserialize an object from a
stream?
a) int read()
b) void close()
c) Object readObject()
d) Object WriteObject()
B
Which of these class extend InputStream class?
a) ObjectStream
b) ObjectInputStream
c) ObjectOutput
d) ObjectInput
A
import java.io.*;
class streams {
public static void main(String[] args) {
try {
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(5);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
int z;
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
z = ois.readInt();
ois.close();
System.out.println(x);
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
a) 5
b) void
c) serialization
d) deserialization
D
What is the output of this program?

import java.io.*;
class serialization {
public static void main(String[] args) {
try {
Myclass object1 = new Myclass("Hello", -7, 2.1e10);
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object1);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
int x;
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
x = ois.readInt();
ois.close();
System.out.println(x);
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
class Myclass implements Serializable {
String s;
int i;
double d;
Myclass(String s, int i, double d){
this.d = d;
this.i = i;
this.s = s;
}
}
a) -7
b) Hello
c) 2.1E10
d) deserialization
D
import java.io.*;
class serialization {
public static void main(String[] args) {
try {
Myclass object1 = new Myclass("Hello", -7, 2.1e10);
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object1);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
int x;
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
x = ois.readInt();
ois.close();
System.out.println(x);
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
class Myclass implements Serializable {
String s;
int i;
double d;
Myclass(String s, int i, double d){
this.d = d;
this.i = i;
this.s = s;
}
}
a) -7
b) Hello
c) 2.1E10
d) deserialization
D
What is the output of this program?
import java.io.*;
class streams {
public static void main(String[] args) {
try {
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeFloat(3.5);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
ois.close();
System.out.println(ois.available());
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
a) 1
b) 2
c) 3
d) 4
a
When creating a client on a server port that is already in use, __________.

A. the client can connect to the server regardless of whether the port is in use.
B. java.net.BindException occurs.
C. the client is blocked until the port is available.
D. the client encounters a fatal error and must be terminated.
a
The client requests a connection to a server using the following statement:

A. Socket s = new Socket(ServerName, port);


B. Socket s = serverSocket.accept();
C. Socket s = serverSocket.getSocket();
D. Socket s = new Socket(ServerName);
b
When a client requests connection to a server that has not yet started, __________.

A. java.net.BindException occurs.
B. java.net.ConnectionException occurs.
C. the client is blocked until the server is started.
D. the client encounters a fatal error and must be terminated.
b
o create an InputStream on a socket s, you use __________.

A. InputStream in = new InputStream(s);


B. InputStream in = s.getInputStream();
C. InputStream in = s.obtainInputStream();
D. InputStream in = s.getStream();
c
______________ models an IP address, which can be used to find the host name and
IP address of the client.

A. The ServerSocket class


B. The Socket class
C. The InetAddress class
D. The Connection interface
c
The ____________ method in the InetAddress class returns the IP address.

A. getIP()
B. getIPAddress()
C. getHostAddress()
D. getAddress()
d
A ServerSocket can connect to ________ clients.

A. one
B. two
C. ten
D. an unlimited number of
b
You can obtain the server's hostname by invoking _________ on an applet.

A. getCodeBase().host()
B. getCodeBase().getHost()
C. getCodeBase().hostName()
D. getCodeBase().getHostName()
e
To obtain an ObjectOutputStream from a socket, use ________.
A. socket.getOutputStream()
B. socket.getObjectStream()
C. socket.getObjectOutputStream()
D. socket.objectOutputStream()
E. new ObjectOutputStream(socket.getOutputStream())
a
Clicking a JButton object generates __________ events.

A. ActionEvent
B. ItemEvent
C. ComponentEvent
D. ContainerEvent
a
Pressing the Enter key on a JTextField generates _____________ events.

A. ActionEvent
B. ItemEvent
C. ComponentEvent
D. ContainerEvent
c
The method __________ appends a string s into the text area jta.

A. jta.setText(s)
B. jta.appendText(s)
C. jta.append(s)
D. jta.insertText(s)
b
To wrap a line in a text area jta, invoke ____________.

A. jta.setLineWrap(false)
B. jta.setLineWrap(true)
C. jta.WrapLine()
D. jta.wrapText()
b
To wrap a line in a text area jta on words, invoke ____________.

A. jta.setWrapStyleWord(false)
B. jta.setWrapStyleWord(true)
C. jta.wrapStyleWord()
D. jta.wrapWord()
a
The method __________ adds a text area jta to a scrollpane jScrollPane.

A. jScrollPane.add(jta)
B. jScrollPane.insert(jta)
C. jScrollPane.addItem(jta)
D. None of the above.
d
How many items can be added into a JComboBox object?

A. 0
B. 1
C. 2
D. Unlimited
D
You can invoke ______________ on a Socket object, say socket, to obtain an
InetAddress object.
A. socket.obtainInetAddress();
B. socket.InetAddress();
C. socket.retrieveInetAddress();
D. socket.getInetAddress();
D
To connect to a server running on the same machine with the client, which of the
following can be used for the hostname?
A. InetAddress.getLocalHost(),
B. "127.0.0.1"
C. "localhost"
D. All of the above.
A
The server listens for a connection request from a client using the following statement:
A. Socket s = serverSocket.accept()
B. Socket s = new Socket(ServerName);
C. Socket s = serverSocket.getSocket()
D. Socket s = new Socket(ServerName, port);
B
The server can create a server socket regardless of whether the port is in use or not.
A. true
B. false
A
The client can connect to the server regardless of whether the port is in use or not.
A. true
B. false
B
You cannot get instances of InputStream or OutputStream because InputStream and
OutputStream are abstract classes.
A. true
B. false
B
An applet cannot connect to a server program on a Web server where the applet was
loaded.
A. false
B. true
B
You can transmit objects over the socket.
A. false
B. true
A
The URL constructor throws MalformedURLException if the URL is syntactically
incorrect.
A. true
B. false
B
getInputStream() and getOutputStream() are used to produce InputStream and
OutputStream on the socket.
A. false
B. true
C
Which of the following code is correct to obtain hour from a Calendar object cal?
A. cal.getHour();
B. cal.get(Hour);
C. cal.get(Calendar.HOUR);
D. cal.hour();
A
A resource bundle is ___________
A. a Java class file or a text file that provides locale-specific information.
B. a Java source code the contains image, audio, and text files.
C. an audio file.
D. an image file.
A
To display number in desired format, you have to use the NumberFormat class or its
subclasses.
A. true
B. false
B
You can find all the available locales from a Swing object.
A. true
B. false
A
The locale property is in the Component class, thus, every Java Swing component has
the locale property.
A. true
B. false
A
You can get year, month, day, hour, minute, and second from an instance of
GregorianCalendar.
A. true
B. false
A
You can get hour, minute and second from the Date class.
A. false
B. true
B
The TimeZone class has a static method for obtaining all the available time zone IDs.
A. false
B. true
B
You can get all the available locales from an instance of Calendar, Collator,
DateFormat, or NumberFormat.
A. false
B. true

You might also like