Revise Flashcards

1
Q
Which of the following modifiers can be applied to a class that is not a nested class? (choose all
that apply):
A. public
B. protected
C. private
D. abstract
A

A, D

Can’t apply protected or private to a top-level class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Consider the following code:

public class MyOuterClass {
 public class MyNestedClass { }
} 
Which of the following is a correct statement to instantiate MyNestedClass from a class outside of
MyOuterClass? (Choose all that apply):

A. MyNestedClass mn = new MyOuterClass.MyNestedClass();

B. MyOuterClass.MyNestedClass mn = new MyOuterClass.MyNestedClass();

C. MyOuterClass.MyNestedClass mn = new MyNestedClass();

D. MyOuterClass mo = new MyOuterClass();
 MyOuterClass.MyNestedClass mn = mo.new MyNestedClass();
A

D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the output when you try to compile and run the following code?

public class MyClass{
int i;
public static void main(String[] args){
 System.out.println(i);
}
}

A. no output – compiler error
B. 0
C. i

A

A.

Why? Can’t reference a non-static variable from a static context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the output of the following program?

class Q10 {
public static void main(String[] args) {
long i=0L;
switch(i){
case 1:
System.out.println("one");
case 2:
System.out.println("two");
case 3:
System.out.println("three");
}}}

A. one
two
three

B. compiles, but produces no output when executed

C. compiler error

A

C.

Why? Can’t use longs in a switch operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Given that the following code works correctly, what are the possible types of variable c?

short a = 10;
short b = 2;
c = a * b;

A. short, int, long
B. short, int, long, float, double
C. int, long, float, double
D. None of the above

A

C.

Why? Any binary operation between two integers (however small) will automatically be converted to ints. So, int is the lowest denomination..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which one of the following statements is true?

A. Polymorphism represents a has-a relationship between objects.
B. Inheritance represents a has-a relationship between objects.
C. Class membership represents a has-a relationship between objects.
D. Association represents a has-a relationship between objects.

A

D.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Given the following code, what is the expected result?

  1. import java.io.PrintWriter;
  2. class DoFormat {
  3. public static void main(String [] args) {
  4. String s1 = null;
  5. String s2 = “TrUe”;
  6. String s3 = “yes”;
  7. String s4 = “no”;
  8. Boolean b1 = new Boolean(“tRuE”);
  9. boolean b2 = false;
  10. System.out.printf(“%b %b %b %b %b”, s1, s2, s3, b1, b2, s4);
  11. }
  12. }

A. false true false true false
B. false true true true false
C. false true true true false false
D. An exception is thrown at runtime

A

B - it doesn’t matter that an extra string argument is passed in…it will just ignore the s4 argument and only format 5 args

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following is an appropriate situation for assertions? (Choose all that
apply)

A. Preconditions of a public method
B. Postconditions of a public method
C. Preconditions of a private method
D. Postconditions of a private method

A

B,C,D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Examine the following code and select the correct option(s), which if
independently inserted at line 5 will compile/execute successfully and read/write
‘Cafe4Java’ to file Cafe4Java.txt

  1. import java.io.*;
  2. public class CodeInsert{
  3. public static void main (String args[]) throws Exception {
  4. File file = new File (“Cafe4Java.txt”);
  5. //// INSERT CODE HERE ////
  6. w.write (“Cafe4Java”, 0, 9);
  7. w.flush();
  8. w.close();
    9 System.out.println(new BufferedReader(new FileReader (file)).readLine());
  9. }
  10. }
    A. BufferedWriter w = new BufferedWriter (new FileWriter (new PrintWriter (file)));
    B. BufferedWriter w = new BufferedWriter (new PrintWriter (new FileWriter (file)));
    C. PrintWriter w = new PrintWriter (new FileWriter (new BufferedWriter (file)));
    D. FileWriter w = new FileWriter (new BufferedWriter (new PrintWriter (file)));
    E. PrintWriter w = new PrintWriter (new BufferedWriter (new FileWriter (file)));
    F. FileWriter w = new FileWriter (new PrintWriter (new BufferedWriter (file)));
A

B,E - looks like FileWriter must be the last/innermost argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. In the following code fragment, after execution of line 1, s references an instance
    of the String class. True or False: after execution of line 2, s still references the same
    instance.
  2. String s = new String(“abcde”);
  3. s = s + “xyz”;
    A. True
    B. False
A

B - its values has been overridden so the original s value has not been dereferenced

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
20. Given the following code:
class ThreadBoth extends Thread implements Runnable {
public void run(){ System.out.print("hi "); }
public static void main(String [] args){
Thread t1 = new ThreadBoth();
Thread t2 = new Thread(t1);
t1.run();
t2.run();
t1.run();
}
}
What is the result?
A. Prints 'hi '
B. Prints 'hi hi '
C. Prints 'hi hi hi '
D. Compilation fails.
E. An exception is thrown at runtime.
A

C - everything works fine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
21. The TreeSet class is used to directly implement which collection interface?
A. Set
B. SortedSet
C. List
D. Tree
A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
23. Which of the following are methods of the Object class? (Choose all that apply)
A. wakeup()
B. sleep()
C. run()
D. wait()
E. notify()
A

D,E

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. Given the code:
  2. class Synch {
  3. int i;
  4. synchronized void go() {
  5. Synch s = new Synch();
  6. synchronized(this) { }
  7. synchronized(s) { }
  8. }
  9. }
    Which line will cause a compilation error? (Choose one)
    A. line 3
    B. line 4
    C. line 6
    D. none of them – compilation succeeds
A

D - synchronized blocks can be used this way

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
With which of the following values can a boolean primitive be initialized? (choose
all correct answers)
A. true
B. false
C. null
D. 0
E. -1
A

A,B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
Which of the given code fragments will compile without errors? (choose all correct
answers)
A. float f=3.5;
B. double d=3.5;
C. int i=10;
D. char c = "C";
A

B,C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
Which of the following statements about the ScopeCheck class are true? (choose
all correct answers)
public class ScopeCheck {
private String name;
private int age;
public String call(String s) {
String text;
return s;
}
}

A. The variables name and age are instance variables
B. The variable text is a method parameter variable
C. The variable text is a local variable
D. Compilation fails because variable text is not initialized

A

A,VC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Which of the following options will compile the source file Destination.java and
place the generated class files in c:\devel\dist ? (choose the correct answer)
A. javac -dest c:\devel\dist Destination.java
B. javac -D=c:\devel\dist Destination.java
C. javac -d c:\devel\dist Destination.java
D. javac Destination.java -D c:\devel\dist

A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Which of the following statements about applets are true? (choose all correct
answers)
A. An Applet runs on an application server
B. An Applet is deployed on mobile devices
C. An Applet is downloaded from a webserver to a client
D. The client needs a JRE to start an applet
E. The client does not need a JRE to start an applet

A

C,D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Which of the following statements about Servlets are true? (choose all correct
answers)
A. The communication between a web client and a servlet is asynchronous
B. WSDL is used to describe a servlet
C. A Servlet is a Java component deployed on a J2EE server
D. A Servlet can handle GET and POST requests

A

C,D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
24. Which type of EJB is mainly used to persist an object’s state?
Select the correct answer:
A. entity bean
B. message driven bean
C. stateful session bean
D. stateless session bean
A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
23. Which of the following components are developed within the J2EE?
Select all correct answers:
A. Applets
B. Servlets
C. EJBs
D. MIDlets
A

B,C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
  1. “A superclass’s constructor is not inherited in any of the subclasses”.
    Select the correct answer:
    A. The statement is true
    B. The statement is false
A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q
  1. Which of the following statements about UML multiplicity indicators are true?
    Select all correct answers:
    A. The multiplicity indicator 1..* stands for “one or more”
    B. The multiplicity indicator 1 stands for “at most one“
    C. The multiplicity indicator 0..2 stands for “zero or two“
    D. none of the above
A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q
17. What will be the result of compiling and running the following code?
public class Operators {
public static void main(String args[]) {
System.out.print(!(true && false || true) + " ");
System.out.print(!(true || false && true) + " ");
System.out.print(!(true && true || false) + " ");
System.out.print(!(true && true || true) + " ");
}
}
Select the correct answer:
A. false false false false
B. true true true true
C. true true false false
D. Compilation fails
A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q
  1. Which of the following statements are true?
    Select all correct answers:
    A. J2SE applications can invoke J2EE components such as EJBs
    B. J2ME applications can invoke J2EE components such as EJBs
    C. J2EE applications can invoke J2EE components such as EJBs
A

A, B, C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q
  1. Which of the following statements are true?
    Select all correct answers:
    A. SQL stands for Super Query Language
    B. JNDI stands for Java Naming and Directory Interface
    C. RMI stands for Remote Method Implementation
A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q
  1. “A JSP is often invoked by a Servlet to create a response to a HTTP request”.
    Select the correct answer:
    A. The statement is true
    B. The statement is false
A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q
  1. J2ME applications are packaged as JAR files and deployed on mobile devices.
    Select the correct answer:
    A. The statement is true
    B. The statement is false
A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q
  1. Which of the following statements about the Car and Garage classes are true? (choose all correct answers)
    class Car {private Garage garage;}
    class Garage {private Car cars[];}
    A. A Garage is associated with many Cars
    B. A Car is associated with many Garages
    C. The Garage class implements multiplicity using an array
    D. The Car class is navigable through the Garage class
A

A,C,D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q
2. With which of the following values can a boolean primitive be initialized? (choose all correct answers)
A. 1
B. 0
C. true
D. False
A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q
  1. What is the output of the following code fragment:
    String myString = “AAAAAAA”;
    System.out.println(myString.replace(“AAA”, “BBB”));
    A. AAAAAAA
    B. BBBAAAA
    C. BBBBBBA
A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q
  1. True or False: only variables declared inside a class declaration, but outside of any method, can be declared static
    A. True
    B. False
A

B - Interfaces can have public static final variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q
  1. A JSP is compiled back to which one of the following components before being run?
    A. Applet
    B. Servlet
    C. EJB
A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

With which of the following values can an int primitive be initialized?

A. 0
B. 0.0
C. -130
D. 0X2a

A

A, C, D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Multiple inheritance is one of they key concepts of the Java programming language.

A. The statement is true
B. The statement is false

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q
Which one of the following statement about a class in a UML class diagram is true?
A. The name of the class is in the top section
B. The name of the class is in the middle section
C. The name of the class is in the bottom section
A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q
Which of the following statements about abstract classes in Java are true?
A. A class must be declared abstract if one or more methods are abstract
B. A class can be declared abstract if one or more methods are abstract
C. A class can be declared abstract if it has no abstract methods
D. An abstract class cannot be extended
A

A, C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Which of the following statements about the School and Student classes are true?

class Student {}
class School {
      private Student students[];
}

A. A School is associated with one Student
B. A School is associated with many Students
C. The School class implements multiplicity using an array
D. student[] is navigable through the School class

A

B, C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

A local variable of type java.lang.String which is not explicitly assigned a value at declaration is automatically initialized to null.

A. The statement is true.
B. The statements is false.

A

B

41
Q

Select the appropriate Java edition for the following application: ‘the application is an applet which is nested inside a HTML page.’

A. J2SE
B. J2EE
C. J2ME

A

A

42
Q

Which of the following protocols are used for accessing JSPs and Servlets?

A. RMI
B. RMI over IIOP
C. HTTP
D. HTTPs

A

C, D

43
Q

Which one of the following statements about Swing components is true?

A. Swing components rely on the underlying operating system to render windows for a Java application
B. Swing components are heavyweight compared to AWT
C. Swing components are lightweight compared to AWT

A

C

44
Q

Information about the history of viewed items for an online shop user should be kept for the whole time the user spends on the shop site. Which object is an appropriate way to store this data?

A. HttpSession
B. HttpServletRequest
C. HttpServletResponse

A

A

45
Q

With which of the following values can a byte primitive be initialized?

A. true
B. false
C. 130
D. 0
E. -1
A

D, E

46
Q

A subclass is usually more specific than its superclass.

A. The statement is true.
B. The statement is false.

A

A

47
Q

An association navigation between class A and class B exists if class A extends class B.

A. The statement is true.
B. The statement is false

A

B.

48
Q

Which of these code fragments will compile without errors?
A. float f=6.5f;
B. int i = 10;
C. char c = “t”;

A

A, B

49
Q
Which of the following statements are true in Java?
A. An abstract class cannot be instantiated
B. A concrete class cannot be instantiated
C. An interface cannot be instantiated.
A

A, C

50
Q

Which of the following statements are true?

class CommunityCenter{}
class Town {
   private CommunityCenter comCenter;
}

A. A Town is associated with one CommunityCenter
B. A Town is associaated with many CommunityCenters
C. The Town class implements multiplicity using an array.
D. The Town class is in a ‘has-a’ relationship with CommunityCenter.

A

A, D

51
Q

An instance variable of type java.lang.String which is not explicitly assigned a value at declaration is automatically initialized to null.

A. The statement is true.
B. The statement is false.

A

A

52
Q

Which one of the following statements is true about method overloading?

A. Multiple methods exist with a different name but same argument list.
B. Multiple methods exist with the same name and same argument list.
C. Multiple methods exist with the same name but a different argument list.

A

C.

53
Q

Which of the following statements are true?
A. RMI stands for Remote Method Interaction
B. JNDI stands for Java Naming and Directory Interface
C. JMS stands for Java Message Servlet

A

B

54
Q
Which of the following components are developed within the J2EE?
A. Applets
B. Servlets
C. EJBs
D. MIDlets
A

B,C

55
Q
Which type of EJB is mainly used to persist an object's state?
A. entity bean
B. message driven bean
C. stateful session bean
D. stateless session bean
A

A

56
Q

Web services can only be used to exchange data between Java applications.
A. The statement is true.
B. The statement is false.

A

B

57
Q

Whenever a subclass extends a superclass, all methods that are contained in the superclass are accessible from the subclass.

A. The statement is true.
B. The statement is false.

A

B

58
Q

Composition is a special kind of association.

A. The statement is true
B. The statement is false

A

A

59
Q

In which compartment of a class can operations be named in a UML class diagram?
A. The top section
B. The middle section
C. The bottom section

A

C

60
Q

Only variables declared inside a class declaration but outside of any method can be declared static.

A. True
B. False

A

B

61
Q
Which one of these EJB types is used to mark information that may be processed after a delay?
A. entity bean
B. message driven bean
C. stateful session bean
D. stateless session bean
A

B

62
Q

An instance variable of type boolean which is not explicitly assigned a value at declaration is automatically initialized to false.

A. The statement is true
B. The statement is false

A

A.

63
Q

Which of the following statements about imports and packages are true?

A. When a package statement exists, it is placed after all import statements.
B. When a package statement exists, it is placed before all import statements.
C. The first line in a Java source file must always be an import statement.
D. To use classes in the java.net package, you must explicitly import them into your code.

A

B,D

64
Q

Which of the following statements represent correct import statements in a Java source file?
A. import java.util.*;
B. import java.io;
C. import java.io.FileReader;

A

A,C

65
Q

Which J2SE component delivers dynamic content while running inside a web browser?
A. applet
B. servlet
C. JSP

A

A

66
Q
Handling an incoming HTTP request is the responsibility of which Java component?
A. EJB
B. JSP
C. applet
D. servlet
A

D

67
Q

Which one of these EJB types would be the best choice when implementing a shopping cart component on a website.
A. Message Driven Bean
B. Stateful Session Bean
C. Stateless Session Bean

A

B

68
Q
Which of the following are signed datatypes?
A. float
B. char
C. short
D. boolean
E. int
A

A, C, E

69
Q

A superclass’s constructor is not inherited in any of the subclasses.

A. The statement is true.
B. The statement is false

A

A

70
Q

Which of the following statements are true?
A. J2SE applications can invoke J2EE components such as EJBs.
B. J2ME applications can invoke J2EE components such as EJBs
C. J2EE applications can invoke J2EE components such as EJBs

A

A, B, C

71
Q

JNDI

A

Java Naming and Directory Interface

72
Q

What is the representation of inheritance in a UML class diagram?

A. an open headed arrow pointing to the inheriting class
B. a closed headed arrow pointing to the inheriting class
C. A closed headed dashed arrow pointing to the parent class
D. A closed headed arrow pointing to the parent class
A

D

73
Q
The CharSequence interface is a super interface to which concrete class?
A. String
B. StringBoxer
C. StringBuffer
D. StringBuilder
A

A, C, D

74
Q

Which statement is false about the toString method?

A. The toString method is a method of the Object class.
B. The toString method returns a string representation of the object.
C. The toString method must return the object’s state information in the form of a string.
D. The toString method is commonly overridden.

A

C

75
Q
Which indexOf method is invalid?
A. indexOf(int ch)
B. indexOf(int ch, int fromIndex)
C. indexOf(String str, int fromIndex)
D. indexOf(CharSequence str, int fromIndex)
A

D

76
Q

Private variables:

a) are read only if only an accessor is provided
b) are set only if a mutator is provided
c) cannot be directly accessed by the parent class
d) cannot be directly accessed by subclasses

A

A, B, C, D

77
Q

Protecting instance variables by making them private is known as which of the following concepts?

a. data inheritance
b. data implementation
c. data encapsulation
d. data privating

A

C

78
Q

Internal methods of a class should:

a) be marked as private, so only the class can access them
b) be marked as private, so external classes cannot see them
c) have instance properties passed as arguments to the method
d) be able to access all instance methods of the class

A

A, B, D

79
Q

A non-static method can only access other non-static methods or non-static variables.

A. The statement is true
B. The statement is false

A

B

80
Q

How can a static method help() of the utility class CertificationUtil be invoked?

a. Create an instance of CertificationUtil and call the help() method on the instance
b. Use CertificationUtil->help() to invoke the method
c. Use CertificationUtil.getHelp() to invoke the method
d. Use CertificationUtil.help() to invoke the method

A

A, D

81
Q

Which of the following statements about static variables are true?

a. Changing the value of a static variable is not possible.
b. A static variable must be private
c. An interface cannot contain static variables
d. None of the above

A

d

82
Q
What variable scope is best suited for a temporary variable?
A. Local variable
B. Static variable
C. Global variable
D. Method parameters
E. Instance variable
A

A

83
Q
What type of object can polymorphically behave as another?
A. An object can act as any subclass of the class it was created from.
B. An object can act as any superclass of the class it was created from.
C. An object can act as any other abstract class.
A

B

84
Q
Polymorphism helps to facilitate which of the following?
A. Highly optimized code.
B. Code reuse
C. Code obfuscation
D. Code that is generic and flexible
A

B, D

85
Q

What is a correct ‘is-a’ relationship?
A. A specific object ‘is-a’ more generic one.
B. A generic object ‘is-a’ more specific one.
C. A null object ‘is-an’ object

A

A

86
Q

Which of the following statements explain why an object can polymorphically behave as an interface?
A. By implementing the interface, the object is required to have all of the functionality that the interface presents.
B. By implementing the interface, the object inherits all the required methods it defines.
C. An object can behave as an interface because interfaces do not have a strict expected behaviour and therefore any object can act as an interface.

A

A.

87
Q
What is the best data type to use if you are required to perform many addition, subtraction and multiplication calculations on a whole number?
A. float
B. Float
C. int
D. Integer
A

c

88
Q

range of short

A

-2^15 to 2^15 - 1

89
Q

range of char

A

0 - (2^16 - 1)

90
Q

range of byte

A

-2^7 to (2^7 - 1)

91
Q

Weak association relationships

A

Direct
Temporary
Aggregation

92
Q

What associations are considered strong relationships?

A

Composition

93
Q

has-an

A

Direct association

94
Q

is-part-of

A

Aggregation

95
Q

is-composed-of

A

Composition

96
Q

Association-navigation

A

bidirectional, unidirectional

97
Q

Information hiding

A

Hiding implementation details and protecting variables from being used the wrong way.

98
Q
Switch statements work with which wrapper types:
A. Character
B. Byte
C. Short
D. Int
A

A, B, C