1Z0-803 - Java SE 7 Programmer I

Go back to Oracle

Exam FAQ

How many questions are there on the 1Z0-803 exam? How long is the 1Z0-803 exam? How much does the 1Z0-803 exam cost? What is the best way to study for the 1Z0-803 exam?

Example Questions

int[] array = {1, 2, 3, 4, 5}; for (int i : array) { if (i < 2) { keyword1; } System.out.println(i); if (i == 3) { keyword2; } } What should keyword1 and keyword2 be respectively, in oreder to produce output 2345? A method doSomething () that has no exception handling code is modified to trail a method that throws a checked exception. Which two modifications, made independently, will allow the program to compile? int [] array = {1,2,3,4,5}; for (int i: array) { if ( i < 2) { keyword1 ; } System.out.println(i); if ( i == 3) { keyword2 ; }} What should keyword1 and keyword2 be respectively, in oreder to produce output 2345? Given: public class DoCompare1 { public static void main(String[] args) { String[] table = {"aa", "bb", "cc"}; for (String ss : table) { int ii = 0; while (ii < table.length) { System.out.println(ss + ", " + ii); ii++; } } } } How many times is 2 printed as a part of the output? Given the code fragment: int [][] array2d = new int[2][3]; System.out.println("Loading the data."); for ( int x = 0; x < array2d.length; x++) { for ( int y = 0; y < array2d[0].length; y++) { System.out.println(" x = " + x); System.out.println(" y = " + y); // insert load statement here. } } System.out.println("Modify the data. "); for ( int x = 0; x < array2d.length; x++) { for ( int y = 0; y < array2d[0].length; y++) { System.out.println(" x = " + x); System.out.println(" y = " + y); // insert modify statement here. } } Which pair of load and modify statement should be inserted in the code? The load statement should set the array's x row and y column value to the sum of x and y The modify statement should modify the array's x row and y column value by multiplying it by 2 Given a java source file: class x { x () {} private void one () {} } public class Y extends x { Y () {} private void two () {one();} public static void main (string [] args) { new Y().two (); } } What changes will make this code compile? An unchecked exception occurs in a method dosomething() Should other code be added in the dosomething() method for it to compile and execute? Given the classes: * AssertionError * ArithmeticException * ArrayIndexOutofBoundsException * FileNotFoundException * IllegalArgumentException * IOError * IOException * NumberFormatException * SQLException Which option lists only those classes that belong to the unchecked exception category? Given: class Overloading { int x(double d) { System.out.println("one"); return 0; } String x(double d) { System.out.println("two"); return null; } double x(double d) { System.out.println("three"); return 0.0; } public static void main(String[] args) { new Overloading().x(4.0) } } What is the result? Given the code fragment: class MySearch { public static void main(String[] args) { String url = "http://www.domain.com/index.html"; if (XXXX) { System.out.println("Found"); } } } Which code fragment, replace with XXXX, enables the code to print Found? Given the code fragment: int j = 0, k = 0; for (int i = 0; i < x; i++) { do { k = 0; while (k < z) { k++; System.out.print(k + " "); } System.out.println(" "); j++; } while (j < y); System.out.println("----"); } What values of x, y, z will produce the following result? 1 2 3 1 2 3 1 2 3 1 2 3 ---- 1 2 3 ---- Given: public abstract class Wow { private int wow; public wow (int wow) { this.wow = wow; } public void wow () {} private void wowza () {} } What is true about the class Wow? Given the code fragment: class Lang { private String category = "procedura1"; public static void main(String[] args) { Lang obj1 = new Lang(); Lang obj2 = new Lang(); if (obj1.category == obj2.category) { System.out.println("Equal"); } else { System.out.println("Not equal"); } if (obj1.category.equals(obj2.category)) { System.out.println("Equal"); } else { System.out.println("Not equal"); } } } What is the result? Which statement will empty the contents of a StringBuilder variable named sb? Given: Public static void main (String [] args) { int a, b, c = 0; int a, b, c; int g, int h, int i, = 0; int d, e, F; int k, l, m; = 0; Which two declarations will compile? Given: class Mid { public int findMid(int n1, int n2) { return (n1 + n2) / 2; } } public class Calc extends Mid { public static void main(String[] args) { int n1 = 22, n2 = 2; // insert code here System.out.print(n3); } } Which two code fragments, when inserted at // insert code here, enable the code to compile and print 12? Give: Public Class Test { } Which two packages are automatically imported into the java source file by the java compiler? Given the code fragment: String h1 = "Bob"; String h2 = new String ("Bob"); What is the best way to test that the values of h1 and h2 are the same? You are writing a method that is declared not to return a value. Which two are permitted in the method body? Given: public class MainMethod { void main() { System.out.println("one"); } static void main(String args) { System.out.println("two"); } public static void main(String[] args) { System.out.println("three"); } void main(Object[] args) { System.out.println("four"); } } What is printed out when the program is excuted? Given the code fragment: String color = "Red"; switch (color) { case "Red": System.out.println("Found Red"); case "Blue": System.out.println("Found Blue"); break; case "White": System.out.println("Found White"); break; default: System.out.println("Found Default"); } What is the result? Given the code fragment: class Test { public static void main(String[] args) { Test t = new Test(); int[] arr = new int[10]; arr = t.subArray(arr, 0, 2); } // insert code fragment here } Which method definition can be inserted at line 7 to enable the code to compile? Given: class X { static void m(String s1) { s1 = "acting"; } public static void main(String[] args) { String s2 = "action"; m(s2); System.out.println(s2); } } What is the result? Given: public class ScopeTest { int j, int k; public static void main(String[] args) { ew ScopeTest().doStuff(); } void doStuff() { nt x = 5; oStuff2(); System.out.println("x"); } void doStuff2() { nt y = 7; ystem.out.println("y"); or (int z = 0; z < 5; z++) { ystem.out.println("z"); ystem.out.println("y"); } Which two items are fields? Given: class Overloading { void x(int i) { System.out.println("one"); } void x(String s) { System.out.println("two"); } void x(double d) { System.out.println("three"); } public static void main(String[] args) { new Overloading().x(4.0); } } What is the result? Which two will compile, and can be run successfully using the command: java Fred1 hello walls Given: class Overloading { int x(double d) { System.out.println("one"); return 0; } String x(double d) { System.out.println("two"); return null; } double x(double d) { System.out.println("three"); return 0.0; } public static void main(String[] args) { new Overloading().x(4.0); } } What is the result? Given: import java.io.IOException; public class Y { public static void main(String[] args) { try { doSomething(); } catch (RuntimeException e) { System.out.println(e); } } static void doSomething() { if (Math.random() > 0.5) throw new IOException(); throw new RuntimeException(); } } Which two actions, used independently, will permit this class to compile? Given the code fragment: String valid = "true"; if (valid) System.out.println ("valid"); else system.out.println ("not valid"); What is the result? Which code fragment cause a compilation error? Given the code fragment: System.out.println("Result: " + 2 + 3 + 5); System.out.println("Result: " + 2 + 1 * 5); What is the result? Given the code fragment: public class ForTest { public static void main(String[] args) { int[] array = {1, 2, 3}; for ( foo ) { } } Which three code fragments, when replaced individually for foo, enables the program to compile? Which two are valid declarations of a two-dimensional array? Given: public class SampleClass { public static void main(String[] args) { AnotherSampleClass asc = new AnotherSampleClass(); SampleClass sc = new SampleClass(); sc = asc; System.out.println("sc: " + sc.getClass()); System.out.println("asc: " + asc.getClass()); }} class AnotherSampleClass extends SampleClass { } What is the result? Given the code fragment: int a = 0; a++; System.out.println(a++); System.out.println(a); What is the result? Given the code fragment: int j=0, k =0; for (int i=0; i < x; i++) { do { k=0; while (k < z) { k++; System.out.print(k + " "); } System.out.println(" "); j++; } while (j < y); System.out.println("----"); } What values of x, y, z will produce the following result? 1 2 3 4 1 2 3 4 1 2 3 4 ------ 1 2 3 4 ------ Given the code fragment: String[] cartoons = { "tom", "jerry", "micky", "tom" }; int counter = 0; And, if ("tom".equals(cartoons[0])) { counter++; } else if ("tom".equals(cartoons[1])) { counter++; } else if ("tom".equals(cartoons[2])) { counter++; } else if ("tom".equals(cartoons[3])) { counter++; } System.out.print(counter); What is the result? Given: public class Test { public static void main(String[] args) { char[] arr = { 97, '\t', 'e', '\n', 'i', '\t', 'o' }; for (char var: arr) { System.out.print(var); } System.out.print("\nThe length is :" + arr.length); } } What is the result? Given: public class Test { public static void main(String[] args) { int i = 25; int j = i+++1; if (j % 5 == 0) { System.out.println(j + " is divisible by 5"); } else { System.out.println(j + " is not divisible by 5"); } System.out.println("Done"); } } What is the result? Which two actions will improve the encapsulation of a class? Which two may precede the word "class" in a class declaration? Given: public class CheckIt { public static void main(String[] args) { if (doCheck()) { System.out.print("square "); } System.out.print("..."); } public static int doCheck() { return 0; } } What is the result? Given the code fragment: Boolean b1 = true; Boolean b2 = false; int 1 = 0; while (foo) {} Which one is valid as a replacement for foo? Given: public class DoBreak1 { public static void main(String[] args) { String[] table = {"aa", "bb", "cc", "dd"}; for (String ss: table) { if ( "bb".equals(ss)) { continue; } System.out.println(ss); if ( "cc".equals(ss)) { break; } } } } What is the result? Given: public class Basic { private static int letter; public static int getLetter(); public static void Main(String[] args) { System.out.println(getLetter()); } } Why will the code not compile? Given: public class Test { public static void main(String[] args) { int arr[] = new int[4]; arr[0] = 1; arr[1] = 2; arr[2] = 4; arr[3] = 5; int sum = 0; try { for (int pos = 0; pos <= 4; pos++) { sum = sum + arr[pos]; } } catch (Exception e) { System.out.println("Invalid index"); } System.out.println(sum); } } What is the result? Class StaticField { static int i = 7; public static void main(String[] args) { StaticFied obj = new StaticField(); obj.i++; StaticField.i++; obj.i++; System.out.println(StaticField.i + " "+ obj.i); } } What is the result? Given: class X { String str = "default"; int ivalue = 17; X(String s) { str = s; } X(int i) { ivalue = i; } void print() { System.out.println(str + " " + ivalue); } public static void main(String[] args) { new X("hello").print(); new X(92).print(); } } What is the result? Given the code fragment: Int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}}; Systemout.printIn(array [4] [1]); System.out.printIn (array) [1] [4]); What is the result? Which two will compile, and can be run successfully using the command: Java fred hello walls

Study Guides