Oracle 1Z0-851 Actual Free Exam Questions & Community Discussion

  • Exam Code/Number: 1Z0-851
  • Exam Name/Title: Java Standard Edition 6 Programmer Certified Professional Exam
  • Certification Provider: Oracle
  • Corresponding Certification: OCJP
  • Exam Questions: 290
  • Updated On: May 26, 2026
Given:
22.StringBuilder sb1 = new StringBuilder("123");
23.String s1 = "123";
24.// insert code here
25.System.out.println(sb1 + " " + s1);
Which code fragment, inserted at line 24, outputs "123abc 123abc"?
Correct Answer: H Vote an answer
Given:
11.public static void main(String[] args) {
12.try {
13.args = null;
14.args[0] = "test";
15.System.out.println(args[0]);
16.} catch (Exception ex) {
17.System.out.println("Exception");
18.} catch (NullPointerException npe) {
19.System.out.println("NullPointerException");
20.}
21.}
What is the result?
Correct Answer: A Vote an answer
Given a correctly compiled class whose source code is:
1.package com.sun.sjcp;
2.public class Commander {
3.public static void main(String[] args) {
4.// more code here
5.}
6.}
Assume that the class file is located in /foo/com/sun/sjcp/, the current directory is /foo/, and that the classpath contains "." (current directory). Which command line correctly runs Commander?
Correct Answer: D Vote an answer
Given:
1.public class KungFu {
2.public static void main(String[] args) {
3.Integer x = 400;
4.Integer y = x;
5.x++;
6.StringBuilder sb1 = new StringBuilder("123");
7.StringBuilder sb2 = sb1;
8.sb1.append("5");
9.System.out.println((x==y) + " " + (sb1==sb2));
10.}
11.}
What is the result?
Correct Answer: E Vote an answer
Click the Exhibit button. What two must the programmer do to correct the compilation errors? (Choose two.)
Correct Answer: C,E Vote an answer
Given:
12.Date date = new Date();
13.df.setLocale(Locale.ITALY);
14.String s = df.format(date);
The variable df is an object of type DateFormat that has been initialized in line 11. What is the result if this code is run on December 14, 2000?
Correct Answer: C Vote an answer
Given a pre-generics implementation of a method:
11.public static int sum(List list) {
12.int sum = 0;
13.for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
14.int i = ((Integer)iter.next()).intValue();
15.sum += i;
16.}
17.return sum;
18.}
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
Correct Answer: A,C,D Vote an answer
Given:
1.class Alligator {
2.public static void main(String[] args) {
3.int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};
4.int [][]y = x;
5.System.out.println(y[2][1]);
6.}
7.}
What is the result?
Correct Answer: E Vote an answer
Click the Exhibit button. What is the result?
Correct Answer: D Vote an answer
Given:
1.public class TestString1 {
2.public static void main(String[] args) {
3.String str = "420";
4.str += 42;
5.System.out.print(str);
6.}
7.}
What is the output?
Correct Answer: E Vote an answer
Given
11.public interface Status {
12./* insert code here */ int MY_VALUE = 10;
13.}
Which three are valid on line 12? (Choose three.)
Correct Answer: B,E,G Vote an answer
Given:
11.abstract class Vehicle { public int speed() { return 0; }
12.class Car extends Vehicle { public int speed() { return 60; }
13.class RaceCar extends Car { public int speed() { return 150; } ...
21.RaceCar racer = new RaceCar();
22.Car car = new RaceCar();
23.Vehicle vehicle = new RaceCar();
24.System.out.println(racer.speed() + ", " + car.speed()
25.+ ", " + vehicle.speed()); What is the result?
Correct Answer: B Vote an answer
Click the Exhibit button. Given:
25.A a = new A();
26.System.out.println(a.doit(4, 5)); What is the result?
Correct Answer: B Vote an answer
0
0
0
10