Top 20 Free Java 8 Certification Questions -sample Questions for OCAJP8 and OCPJP8 – 1Z0-808 and 1Z09

Top 20 Free Java 8 Certification Questions -sample Questions for OCAJP8 and OCPJP8 - 1Z0-808 and 1Z09

Oracle Java Certification Exam was earlier called as SCJP (Sun Certified Java Professional) but after the takeover by Oracle, it’s known as Oracle Java Certification Exam. It is divided into two levels- OCAJP and OCPJP. OCAJP includes Java for beginners, and thus it’s easier than OCPJP whereas OCPJP includes Advanced Java and thus, is complex than OCAJP.

OCA / OCP Java SE 8 Programmer Practice Tests

OCAJP8 (1Z0-808) is the associate level exam for Java SE 8 Programmer and OCPJP8 (1Z0-809) is the professional level exam for Java SE 8 Programmer. The duration of both the programs is same, which is two and a half hours. However, the numbers of questions asked in both the programs are different. In OCAJP 8, the candidate has to answer 80 questions within 150 minutes. While in OCPJP 8, the candidate has to answer 85 questions within the same time limit. The passing score required in both the exams is 65%. You can’t get OCPJP certification from Oracle if you don’t pass OCAJP Oracle Java exam first. Here are the top questions asked in both the 1Z0-809 and 1Z0-909 exams.

Top 10 Questions For OCAJP8 (1Z0-808) Exam:

  
Q1. Given
1.       class Test{
2.
3.               public static void main(String[] args){
4.
5.               int []a = {1,2,3,4,5,6};
6.               int i = a.length;
7.
8.                        while(i>=1){
9.                                 System.out.print(a[i]);
10.                                i–;
11.                       }
12.              }
13.      }
What would be the output, if
it is executed as a program?
A. 123456
B. 65432
C. 12345
D. An exception could be
thrown at runtime.
E. Compile error.
Q2. Given
1.       class Ex6{
2.               public static void main(String args[]){
3.                        int i = 0, j=10;
4.                        try{
5.                                 j /=i;
6.                        }
7.                        System.out.print(“Divide by Zero!
“);
8.                        catch(Exception e){
9.                                 System.out.print(“error”);
10.                       }
11.              }
12.      }
What is the output?
A. 0
B. 0 Divide by Zero!
C. Divide by Zero! Error
D. Error
E. Compilation fails.
F. An uncaught exception is
thrown at runtime.
Q3. Consider
–        A and E are Classes
–        B and D are interfaces
–        C is an abstract class
Which are true? (Choose 3)
A. class F implements B ,C{ }
B. class F implements B{ }
C. class F extends A,E{ }
D. class F extends E{ }
E. class F implements B,D{ }
Q4. Given
1.       class Test{
2.               public static void main(String[] args) {
3.                        int a[] = {};
4.                        System.out.print(a instanceof Object);
5.               }
6.       }
Note: The keyword
“instanceof” is use to check whether an object is of a particular
type
Which is true?
A. Will produce output as
false.
B. Compilation fails due to
error at line 3.
C. Will produce output as
true.
D. Compilation fails due to
error at line 4.
E. Length of this array is 3.
Q5. Given
1.       class Program{
2.
3.               static Integer i;
4.
5.               public static void main(String [] args){
6.                        try{
7.                                 System.out.println(i.compareTo(0));
8.                        }catch ( ArithmeticException |
NullPointerException e){
9.                                 System.out.println(“Exception”);
10.                       }
11.              }
12.      }
Which is the output?
A. -1
B. 0
C. 1
D. Exception
E. Compilation fails.
Q6. Given
1.       class Ex1{
2.               public static void main(String[] args) {
3.                        int a[] = { 1,2,053,4};
4.                        int b[][] = { {1,2,4} , {2,2,1},{0,43,2}};
5.                        System.out.print(a[3]==b[0][2] );
6.                        System.out.print(” ” +
(a[2]==b[2][1]));
7.               }
8.       }
Which is the output?
A. true  false
B. false  false
C. false true
D. true true
E. Compilation fails
Q7. Choose three legal
identifiers.
A. 2ndtName
B. _8_
C. &name
D. $
E. new
Q8. Given
1.       class Test{
2.               int value = 10;
3.               public static void main(String[] args) {
4.                        new Test ().print();
5.               }
6.               public void print(){
7.                        int value = 8;
8.                        System.out.print(value);
9.               }
10.      }
Which is the output?
A. 8
B. 10.
C. Compilation fails due to
error at line 4.
D. Compilation fails due to
error at line 7.
Q9. Given
1.       class Test{
2.               static int x = 0;
3.               public static void main(String[] args) {
4.                        for(int x=0;x<5;x++){     }
5.                        System.out.print(x);
6.               }
7.       }
Which is the output?
A. 4
B. 5
C. 0
D. Compilation fails.
E. Runtime exception will be
thrown.
Q10. Given
1.       class Exer{
2.               public static void main(String [] args){
3.                        String s = “Java”;
4.                        s.concat(” SE 7″);
5.                        s.replaceAll(“7″,””);
6.                        System.out.print(s);
7.               }
8.       }
What is the result?
A. Java SE “”
B. Java SE 7
C. Java SE
D. Java.
E. Compilation fails.

 

 

Top 10 Questions For OCPJP8 (1Z0-809) Exam:

Q1. Consider the following class:

public final class Program {

         final private String name;

         Program (String name){
                 this.name = name;

                 getName();
         }

         //code here
}

Which of the following codes will make an instance of this class immutable?
A. public String getName(){return name;}
B. public String getName(String value){ name=value; return value;}
C. private String getName(){return name+"a";}
D. public final String getName(){return name+="a";}
E. All of Above.

Q2. Consider the following code:
1.       class SuperClass{
2.               protected void method1(){
3.                        System.out.print("M SuperC");
4.               }
5.       }
6.
7.       class SubClass extends SuperClass{
8.               private  void method1(){
9.                        System.out.print("M SubC");
10.              }
11.
12.              public static void main(String[] args){
13.                       SubClass sc = new SubClass();
14.                       sc.method1();
15.              }
16.      }

What will be the result?
A. M SubC.
B. M SuperC.
C. M SuperCM SubC.
D. Compilation fails.
E. None of above.

Q3. Given the following class:
1.       public class Test {
2.               public static void main(String args[]) {
3.                        //Code Here
4.                        Thread thread = new Thread(r);
5.                        thread.start();
6.               }
7.       }

Which of the following lines will give a valid Thread creation?
A.       Thread r = () -> System.out.println("Running");
B.       Run r = () -> System.out.println("Running");
C.       Runnable r = () -> System.out.println("Running");
D.       Executable r = () -> System.out.println("Running");
E.       None Of Above

Q4. Which of the following database urls are correct?
A. jdbc:mysql://localhost:3306
B. jdbc:mysql://localhost:3306/sample
C. jdbc:mysql://localhost:3306/sample/user=root?password=secret
D. jdbc:mysql://localhost:3306/sample?user=root&password=secret
E. All

Q5. Given the following code:
1.       public class Program {
2.
3.               public static void main (String args[]) throws IOException {
4.                        Console c = System.console();
5.                        int i = (int)c.readLine("Enter value: ");
6.                        for (int j = 0; j < i; j++) {
7.                                 c.format(" %2d",j);
8.                        }
9.               }
10.      }

What will be the result of entering the value 5?
A. 1 2 3 4 5
B. 0 1 2 3 4
C. 0 2 4 6 8
D. The code will not compile because of line 5.
E. Unhandled exception type NumberFormatException at line 7.

Q6. Given the following class:
1.       class Singleton {
2.               private int count = 0;
3.               private Singleton(){};
4.               public static final Singleton getInstance(){ return new Singleton(); };
5.               public void  add(int i){ count+=i; };
6.               public int getCount(){ return count;};
7.       }
8.
9.       public class Program {
10.              public static void main(String[] args) {
11.                       Singleton s1 = Singleton.getInstance();
12.                       s1.add(3);
13.                       Singleton s2 = Singleton.getInstance();
14.                       s2.add(2);
15.                       Singleton s3 = Singleton.getInstance();
16.                       s2.add(1);
17.                       System.out.println(s1.getCount()+s2.getCount()+s3.getCount());
18.               }
19.      }

What will be the result?
A. 18
B. 7
C. 6
D. The code will not compile.
E. None of above

Q7. Given the following class:
1.       public class Program {
2.
3.               public static void main(String[] args) {
4.
5.                        List list = Arrays.asList(4,6,12,66,3);
6.
7.                        String  s = list.stream().map( i -> {
8.                                 return ""+(i+1);
9.                        }).reduce("", String::concat);
10.
11.                       System.out.println(s);
12.              }
13.      }

What will be the result?
A. 4612663
B. 5713674
C. 3661264
D. The code will not compile because of line 7.
E. Unhandled exception type NumberFormatException al line 8.

Q8. Which of the following are correct overrides of Object class?
I.       public int hashCode();
II.      public String toString();
III.    public boolean equals(Object obj);
IV.      public Class getClass();

A. I, II, III, IV.
B. I, II, III.
C. I, II.
D. III, IV.
E. All.

Q9. Consider the following class:
1.       public class Test {
2.               public static  int count(T[] array, T elem) {
3.                        int count = 0;
4.                        for (T e : array)
5.                                 if( e.compareTo(elem) > 0) ++count;
6.
7.                        return count;
8.               }
9.               public static void main(String[] args) {
10.                       Integer[] a = {1,2,3,4,5};
11.                       int n = Test.count(a, 3);
12.                       System.out.println(n);
13.              }
14.      }
What will be the result?
A. 2
B. 3
C. The code will not compile because of line 5.
D. An exception is thrown.
E. None of Above.

Q10. Given the following class:
1.       public class Program {
2.               public static void main(String[] args) {
3.
4.                        Thread th = new Thread(new Runnable(){
5.
6.                                 static {
7.                                          System.out.println("initial");
8.                                 }
9.
10.                                @Override
11.                                public void run() {
12.                                         System.out.println("start");
13.                                }
14.                       });
15.
16.                       th.start();
17.              }
18.      }
What will be the result?
A. start initial
B. initial start
C. initial
D. A runtime exception is thrown.
E. The code will not compile because of line 6.

 

Although above are the few best Java certification questions, it’s recommended to go through each topic in detail, and practice questions as the questions vary in each Oracle Java Certification Exam.

 

Previous
Next