0% found this document useful (0 votes)
107 views

Handout3-TypesofQuestions-OCA Java SE 8 Programmer I PDF

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

Handout3-TypesofQuestions-OCA Java SE 8 Programmer I PDF

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

12 Introduction

■ No file or directory path names for classes—If a question doesn’t state the filenames
or directory locations of classes, then assume one of the following, whichever
will enable the code to compile and run:
– All classes are in one file.
– Each class is contained in a separate file, and all files are in one directory.
■ Unintended line breaks—Sample code might have unintended line breaks. If you
see a line of code that looks like it has wrapped, and this creates a situation where
the wrapping is significant (for example, a quoted String literal has wrapped),
assume that the wrapping is an extension of the same line, and the line doesn’t
contain a hard carriage return that would cause a compilation failure.
■ Code fragments—A code fragment is a small section of source code that’s pre-
sented without its context. Assume that all necessary supporting code is present
and that the supporting environment fully supports the correct compilation
and execution of the code shown and its omitted environment.
■ Descriptive comments—Take descriptive comments, such as “setter and getters go
here,” at face value. Assume that correct code exists, compiles, and runs success-
fully to create the described effect.
WHAT ARE THE TYPES OR FORMATS OF QUESTIONS THAT I CAN EXPECT IN THE EXAM?
The exam uses different formats of multiple choice questions, illustrated in this sec-
tion by eight example questions with figures.
The examples for all these types of questions show how the following set of topics
might be tested using a different question format:
■ Correct declaration of the main method
■ Passing command-line parameters
■ Overloaded methods
■ Significance of method parameter names
■ Declaration of variables of varargs

Exam question type 1 (figure 4)—Includes simple code, but tricky or confusing answer
options.

Exam Tricky or
Simple
question = + confusing
code
type #1 answer options
Figure 4 Exam question type 1

The answer options in the following example would confuse a reader on whether the
command-line values would be concatenated or added as integer values:
FAQs 13

Given:

class JavaCertQType1 {
public static void main(String... cmd) {
main("private", cmd);
}
private static void main(String type, String[] args) {
System.out.println(args[0] + args[1]);
}
}

What is the output when class JavaCertQType1 is executed using


the following command (choose 1 option):

java JavaCertQType1 1 11 EJava Guru

1
1 11
111
12
1 11 EJava Guru
Compilation error
Runtime exception

NOTE In this book, the sample exam questions at the end of each chapter
and full mock exam at the end of the book show answer options as lettered
(for example, a–d) for ease on discussion. In the exam, however, the answer
options aren’t numbered or lettered. They’re preceded with either a radio
button or a check box. Radio buttons are for questions with only one correct
answer, and check boxes are for questions with multiple correct answers.

Exam question type 2 (figure 5)—Exam questions without code give you a much
needed break from reading code. But it isn’t always easy to answer them.

Exam Answer options


No
question = + with only
code
type #2 text
Figure 5 Exam question type 2

An example of exam question, type 2:

Question2) Assuming that the phrase 'the method main' refers to the method
main that starts an application, select the correct statements (choose 2
options).

A class can define multiple methods with the name main, but with
different signatures.
The method main can define its only method parameter of type varargs.
Accessibility of the method main can't be restricted to private.
A class with overloaded main methods won't compile.
14 Introduction

Exam question type 3 (figure 6)—Reading though and comprehending lots of code can
be difficult. The key is to eliminate wrong answers to find the correct answers quickly.

Exam Answer options


Lots of
question = + with probable
code
type #3 code output
Figure 6 Exam question type 3

An example:

Given:

class JavaCertQuesType3 {
public static void main(String args[]) {
System.out.println("Spring");
}
public static void main(String... args) {
System.out.println("Summer");
}
public static void main(String[] cmd) {
System.out.println("Autumn");
}
public static void main() {
System.out.println("Winter");
}
}

What is the output (choose 1 option)?

Code outputs Spring


Code outputs Summer
Code outputs Autumn
Code outputs Winter
Compilation error
Runtime exception

Exam question type 4 (figure 7)—This type of question is a classic example of “fill in
the blank.”

Code Answer options:


Exam ---- a) Code 1
question = ---- + b) Code 2
type #4
//INSERT CODE HERE c) Code 3
---- ----
---- ---- Figure 7 Exam question type 4
FAQs 15

An example:

Given:

class JavaCertQType4 {
static int c, a = 10, b = 21/2;
static {
c = a;
}
// INSERT CODE HERE
}

Which options, when inserted individually at //INSERT CODE HERE will


enable class JavaCertQType4 to output value 10 (choose 2)?

public static void main(String... variables) {


System.out.println(b);
}

private static void main(String[] commandArgs) {


System.out.println(b);
}

public static void main(String args) {


System.out.println(b);
}

private static void main() {


System.out.println(b);
}
public static void main(String... method) {
System.out.println(b);
}

Exam question type 5 (figure 8)—This question type will include code, a condition,
or both. The answer options will include changes and their results, when applied to
the code in the question. Unless otherwise stated, changes in the answer options
that you choose are applied individually to the code or the specified situation.
Result of a correct answer option won’t involve changes suggested in other correct
answer options.

Exam Answer options


question = Code + including suggested
type #5 changes to code
Figure 8 Exam question type 5
16 Introduction

An example:

Given:

1. class JavaCertQType5 {
2. protected static void main() {
3. System.out.println("EJavaGuru.com");
4. }
5. public static void main(String... method) {
6. main();
7. System.out.println("MissionOCAJ8");
8. }
9. }

Select correct option (choose 2):

Code will compile successfully if code on line 6 is commented.


Code will output the same result if access modifier of main() is
changed to private at line 2.
Code won't compile if code on line 6 is placed after code on line 7.
The code compiles successfully, but throws a runtime exception.

Exam question type 6 (figure 9)—Because your mind is programmed to select the cor-
rect options, answer this type of question very carefully. My personal tip: cross fingers
in one of your hands to remind you that you need to select the incorrect statements.

Exam Select
question = Code + incorrect
type #6 options
Figure 9 Exam question type 6

An example:

Given:

1. class JavaCertQType6 {
2. public static void main(String... method) {
3. main();
4. main(method);
5. }
6. protected static void main() {
7. System.out.println("EJavaGuru");
8. }
9. }

Select incorrect options (choose 2):

Code will compile successfully only if code on line 3 is commented.


Code will output the same result if access modifier of main() is
changed to public at line 6.
Code will compile sucessfully and execute without any runtime
exceptions.
If the order of code on lines 3 and 4 is reversed, the code won't
output 'EJavaGuru'.
FAQs 17

Exam question type 7 (figure 10)—This question won’t include any code in the text of
the question; it will state a condition that needs to be implemented using code given
in the answer options.

Exam
No Answer options
question = +
code with code
type #7 Figure 10 Exam question type 7

An example:

Which of the following options can be used to define a main method that
outputs the value of the second and fourth command parameters (choose 2):

public static void main(String... method) {


for (int i = 1; i < method.size && i < 6; i = i + 2)
System.out.println(method[i]);
}

public static void main(String[] main) {


for (int i = 1; i < main.length && i < 6; i = i + 2)
System.out.println(main[i]);
}

public static void main(String... arguments) {


int ctr = 0;
while (ctr < arguments.length) {
if (ctr >= 4) break;
if (ctr %2 != 0)
System.out.println(arguments[ctr]);
++ctr;
}
}

public static void main(String[] arguments) {


int ctr = 1;
while (ctr < arguments.length) {
if (ctr >= 4) break;
if (ctr %2 == 0)
System.out.println(arguments[ctr]);
++ctr;
}
}

Exam question type 8 (figure 11)—This question includes a pictorial representation


of a single or multidimensional array, stating a situation and asking you to select code
as input to get the required array formation.

Exam Diagram
Answer options
question = representing +
as code
type #8 the code Figure 11 Exam question type 8
18 Introduction

An example:

Assuming that the following array and image represents variation of


Connect4 game, where a player wins if she places same number in a row or
column:

char[][] grid = new char[][]{{'7',' ',' ',' '},{'5','7',' ','5'},


{'7','7','5','5'},{'5','7','7','5'}};

5 7 5

7 7 5 5

5 7 7 5

Which of the following assignments would enable a player with number 7


to win (choose 2 options)?

grid[0] = new char[]{'7','7',' ',' '};


grid[1] = new char[]{'7','7',' ',' '};
grid[0] = {'7','7',' ',' '};
grid[1] = {'7','7',' ',' '};
grid[0][1] = '7';
grid[1][2] = '7';
grid[0] = new char[4]{'7','7',' ',' '};
grid[1] = new char[4]{'7','7',' ',' '};

7.2 FAQs on taking the exam


This section contains a list of frequently asked questions related to the exam registra-
tion, exam coupon, do’s and don’ts while taking the exam, and exam retakes.
WHERE AND HOW DO I TAKE THIS EXAM?
You can take this exam at an Oracle Testing Center or Pearson VUE Authorized Test-
ing Center. To sit for the exam, you must register for the exam and purchase an exam
voucher. The following options are available:
■ Register for the exam and pay Pearson VUE directly
■ Purchase an exam voucher from Oracle and register at Pearson VUE to take
the exam
■ Register at an Oracle Testing Center
Look for the nearest testing centers in your area, register yourself, and schedule an
exam date and time. Most of the popular computer training institutes also have a testing
center on their premises. You can locate a Pearson VUE testing site at www.pearsonvue
.com/oracle/, which contains detailed information on locating testing centers and

You might also like