ASSESMENT OCJP Name: Date: e

advertisement
ASSESMENT OCJP
Name: ____________________________________________________________
Date: ______________
e-mail: ______________________________________
Time: 60 minutes.
Instructions: Choose ONE answer for the following questions, until the question asks to
select many options.
1. Choose the option that better describes the Java Virtual Machine
a) Composed of the Java Virtual Machine and Java Class Libraries
b) Manipulates objects instead of a pointer
c) Executes plattform-independent bytecode
d) Removes unreferenced objects from memory
e) Executes within a web browser
f) Creates Java Bytecode
g) Executed by the Java Virtual Machine
2. Choose the option that better describes an Applet
a) Composed of the Java Virtual Machine and Java Class Libraries
b) Manipulates objects instead of a pointer
c) Executes plattform-independent bytecode
d) Removes unreferenced objects from memory
e) Executes within a web browser
f) Creates Java Bytecode
g) Executed by the Java Virtual Machine
3. Choose the option that better describes a Compiler
a) Composed of the Java Virtual Machine and Java Class Libraries
b) Manipulates objects instead of a pointer
c) Executes plattform-independent bytecode
d) Removes unreferenced objects from memory
e) Executes within a web browser
f) Creates Java Bytecode
g) Executed by the Java Virtual Machine
4. Choose the option that better describes a Reference
a) Composed of the Java Virtual Machine and Java Class Libraries
b) Manipulates objects instead of a pointer
c) Executes plattform-independent bytecode
d) Removes unreferenced objects from memory
e) Executes within a web browser
f) Creates Java Bytecode
g) Executed by the Java Virtual Machine
5. Choose the option that better describes a Bytecode
a) Composed of the Java Virtual Machine and Java Class Libraries
b) Manipulates objects instead of a pointer
c) Executes plattform-independent bytecode
d) Removes unreferenced objects from memory
e) Executes within a web browser
f) Creates Java Bytecode
g) Executed by the Java Virtual Machine
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
6. Choose the option that better describes the Java Runtime Environment
a) Composed of the Java Virtual Machine and Java Class Libraries
b) Manipulates objects instead of a pointer
c) Executes plattform-independent bytecode
d) Removes unreferenced objects from memory
e) Executes within a web browser
f) Creates Java Bytecode
g) Executed by the Java Virtual Machine
7. Choose the option that better describes the Garbage Collector
a) Composed of the Java Virtual Machine and Java Class Libraries
b) Manipulates objects instead of a pointer
c) Executes plattform-independent bytecode
d) Removes unreferenced objects from memory
e) Executes within a web browser
f) Creates Java Bytecode
g) Executed by the Java Virtual Machine
8. It is referred as the process of ignoring details to concentrate in essential
characteristic. It promotes reuse since specific characteristics that would
make the abstracted item less “generic” are ignored.
a) Encapsulation.
b) Abstraction.
c) Inheritance.
d) Polymorphism.
9. It is the mechanism which separates the external aspects of an object, which
are accessible to other objects, from the internal implementation details of
the object.
a) Encapsulation.
b) Abstraction.
c) Inheritance.
d) Polymorphism.
10.It is the mechanism for defining a new class in terms of an existing class.
a) Encapsulation.
b) Abstraction.
c) Inheritance.
d) Polymorphism.
11.This concept is implemented when an operation may be applied to objects of
different classes to achieve the same semantic result.
a) Encapsulation.
b) Abstraction.
c) Inheritance.
d) Polymorphism.
12.It is a template for objects. It describes the characteristics and actions of
the objects.
a) Class.
b) Attributes.
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
c) Operations.
d) Object.
13.It is an entity consisting of state (attributes and relationships), behavior
(operations) and identity.
a) Class.
b) Attributes.
c) Operations.
d) Object.
14.Which one represents the state (the characteristics) of an object?
a) Class.
b) Attributes.
c) Operations.
d) Object.
15.Which of the following represents the behavior (the actions) of an object?
a) Class.
b) Attributes.
c) Operations.
d) Object.
16.Which of the following is not part of a method’s signature?
a) The modifiers and return type of the method.
b) The name and list of arguments of the method.
c) A and B are correct.
d) None of the above.
17.Which is the correct syntax for packing a class and import classes in other
packages?
a) import java.awt.*;
import java.lang.*;
package myclasses;
b) package myclases.*;
import java.util.Date;
import java.*.*;
c) package pack1;
package pack2;
import java.io.*;
import java.net.*;
d) package misclases;
import java.util.Date;
import java.io.*;
18.Which of the following removes unreferenced objects from memory?
a) Garbage Collector.
b) Applet.
c) JVM.
d) JRE.
19.What will be displayed when you attempt to compile and run the following
code.
//Code start
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
import java.awt.*;
public class Butt extends Frame{
public static void main(String argv[]){
Butt MyBut=new Butt();
}
Butt(){
Button HelloBut=new Button("Hello");
Button ByeBut=new Button("Bye");
add(HelloBut);
add(ByeBut);
setSize(300,300);
setVisible(true);
}
}
//Code end
Select any 1 option:
a) Two buttons side by side occupying all of the frame, Hello on the left and Bye on
the right
b) One button occupying the entire frame saying Hello
c) One button occupying the entire frame saying Bye
d) Two buttons at the top of the frame one saying Hello the other saying Bye
20.If g is a graphics instance what will the following code draw on the screen?.
g.fillArc(45,90,50,50,90,180);
Select any 1 option:
a) An arc bounded by a box of height 45, width 90 with a centre point of 50,50,
starting at an angle of 90 degrees traversing through 180 degrees counter
clockwise.
b) An arc bounded by a box of height 50, width 50, with a centre point of 45,90
starting at an angle of 90 degrees traversing through 180 degrees clockwise.
c) An arc bounded by a box of height 50, width 50, with a top left at coordinates of
45, 90, starting at 90 degrees and traversing through 180 degrees counter
clockwise.
d) An arc starting at 45 degrees, traversing through 90 degrees clockwise bounded
by a box of height 50, width 50 with a centre point of 90, 180.
21.If you create a TextField with a constructor to set it to occupy 5 columns,
what difference will it make if you use it with a proportional font (ie Times
Roman) or a fixed pitch typewriter style font (Courier).
Select one option.
a) With a fixed font you will see 5 characters, with a proportional it will depend on
the width of the characters
b) With a fixed font you will see 5 characters,with a proportional it will cause the
field to expand to fit the text
c) The columns setting does not affect the number of characters displayed
d) Both will show exactly 5 characters
22.You want to lay out a set of buttons horizontally but with more space
between the first button and the rest. You are going to use the
GridBagLayout manager to control the way the buttons are set out. How will
you modify the way the GridBagLayout acts in order to change the spacing
around the first button?
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
Select one option:
a) Create an instance of the GridBagConstraints class, call the weightx() method and
then pass the GridBagConstraints instance with the component to the
setConstraints method of the GridBagLayout class.
b) Create an instance of the GridBagConstraints class, set the weightx field and then
pass the GridBagConstraints instance with the component to the setConstraints
method of the GridBagLayout class.
c) Create an instance of the GridBagLayout class, set the weightx field and then call
the setConstraints method of the GridBagLayoutClass with the component as a
parameter.
d) Create an instance of the GridBagLayout class, call the setWeightx() method and
then pass the GridBagConstraints instance with the component to the
setConstraints method of the GridBagLayout class.
23.Which of the following will compile without error?
Select any 2 options
a)
import java.awt.*;
package Mypackage;
class Myclass {}
b)
package MyPackage;
import java.awt.*;
class MyClass{}
c)
/*This is a comment */
package MyPackage;
import java.awt.*;
class MyClass{}
24.What is an event?
Select any 1 option:
a) An event is what happens when the user manipulates a Windows control, whether
that control be a pushbutton, a radio button, a slider or many other such
controls.
b) An event is created automatically by the components of a window.
c) An event success when you execute your application program.
d) A component has only one event.
25.What is an event handler?
Select any 1 option:
a) Is a characteristic of the GUI components.
b) An event handler is a software method provided by programmers such as you and
me, that the Operating System calls to handle a particular event.
c) Allow the users to see the GUI.
d) Adds echo character to hide text input in component.
26.What will happen when you attempt to compile and run this code. Select any
one option.
//Demonstration of event handling
import java.awt.event.*;
import java.awt.*;
public class MyWc extends Frame implements WindowListener{
public static void main(String argv[]){
MyWc mwc = new MyWc();
}
public void windowClosing(WindowEvent we){
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
System.exit(0);
}//End of windowClosing
public void MyWc(){
setSize(300,300);
setVisible(true);
}
}//End of class
a)
b)
c)
d)
Error at compile time
Visible Frame created that that can be closed
Compilation but no output at run time
Error at compile time because of comment before import statements
27.Which of the following are correct event handling methods.
Select any 2 options.
a) mousePressed(MouseEvent e){}
b) MousePressed(MouseClick e){}
c) functionKey(KeyPress k){}
d) componentAdded(ContainerEvent e){}
28.Which of the following statements are correct?
Select any 2 options.
a) If multiple listeners are added to a component only events for the last listener
added will be processed
b) If multiple listeners are added to a component the events will be processed for all
but with no guarantee in the order
c) Adding multiple listeners to a component will cause a compile time error
d) You may remove as well add listeners to a component.
29.Given the following code.
import java.awt.*;
public class SetF extends Frame{
public static void main(String argv[]){
SetF s=new SetF();
s.setSize(300,200);
s.setVisible(true);
}
}
How could you set the frame surface color to pink.
Select any 1 option:
a) s.setBackground(Color.pink);
b) s.setColor(PINK);
c) s.Background(pink);
d) s.color=Color.pink
30.What most closely matches the appearance when this code runs?
import java.awt.*;
public class CompLay extends Frame{
public static void main(String argv[]){
CompLay cl = new CompLay();
}
CompLay(){
Panel p = new Panel();
p.setBackground(Color.pink);
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));
add("South",p);
setLayout(new FlowLayout());
setSize(300,300);
setVisible(true);
}
}
Select any 1 option:
a) The buttons will run from left to right along the bottom of the Frame
b) The buttons will run from left to right along the top of the frame
c) The buttons will not be displayed
d) Only button three will show occupying all of the frame
31.How do you indicate where a component will be
Flowlayout? Select any 1 option:
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
positioned
using
32.How do you change the current layout manager for a container.
Select any 1 option:
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
33.Which of the following are fields of the GridBagConstraints class?
Select any 3 options:
a) ipadx
b) fill
c) insets
d) width
34.Which of the following statements are true about the sleep method of Thread
class?
Select any 2 options:
a) A thread releases any locks it is holding when it is invoked on the thread.
b) It is defined as static within the Thread class.
c) A thread starts running as soon as it wakes up from the sleeping state.
d) The sleep method throws InterruptedException
35.Which of the following statements are true about synchronization?
Select any 2 options:
a) Static methods cannot be synchronized.
b) Synchronized methods cannot make calls to non – synchronized methods.
c) A Synchronized method can be overridden to be non – synchronized and
viceversa.
d) When a thread is executing a synchronized method, other threads can freely
access non synchronized methods of the same object.
36.What will happen when you attempt to compile and run the following code?
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
Select any 1 options:
a) It will print – ABC XYZ ABC XYZ in that secuence.
b) It will print – ABC ABC XYZ XYZ in that secuence.
c) It will print – ABC and XYZ but the secuence cannot be determined.
d) The code will not compile
37.Given that a static method doit() in the Work class represents work to be
done, which of the following blocks of code will succeed in starting a new
thread that will do the work?
Select Any 1 option: Answer a).
38.Which of the following lines will not compile?
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
a)
b)
c)
d)
e)
f)
Line
Line
Line
Line
Line
Line
1
2
3
4
5
6
39.Which of the following statements regarding the wait() method are correct?
Select any 3 options:
a) It is an Instance method of Object Class.
b) It is a static method of the Object Class.
c) It is an Instance method of Thread Class.
d) The Thread must have a lock on the object on which the wait() method is to
be invoked.
e) An object can have only one Thread in a waiting state at a time.
f) It must be called in a synchronized code.
40.Select the appropriate methods to match the given descriptions.
1. Can only be called from synchronized code.
2. Waits for a thread to die.
3. Thread temporarily ceases execution.
4. Called by JVM when the Thread get CPU access.
Select
a)
b)
c)
d)
e)
any 1 option:
notify, wait, sleep, start
volatile, wait, notify, start
notify all, join, sleep, run
start, sleep, wait, run
none of these
41.What is the result of compile and execute the following code?
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
Select any 1 option:
a) The code does not compile.
b) The code does compile and executes but produces no output.
c) The code throws an exception.
d) None of the above.
42.FileWriter is a subclass of OutputStreamWriter?
Select any 1 option:
a) True
b) False
43.What is a Socket?
Select any 1 option:
a) Is a system that is used to communicate between two telephones.
b) Is used to block the communication on the workstation connected to the
network.
c) Is used as a tool to emulate a Firewall.
d) A socket is a communication system between two machines on the network.
44.Which of the following are methods used on the SeverSocket class?
Select any 2 option:
a) open()
b) close()
c) accept()
d) closed()
45.Which of the following piece of code is an example of the Server listening for
a connection?
Select Any 1 option: Answer a).
Ingenieros Militares No. 105 – 1C, Col. Lomas de Sotelo, Del. Miguel Hidalgo, México D.F. CP 11200. Tel: 5557 5012
www.develop.com.mx
Download