DEV Community

Cover image for Oracle Certified Java 8 Associate (OCA) Exam Preparation
Mercy
Mercy

Posted on

Oracle Certified Java 8 Associate (OCA) Exam Preparation

Taking the 1Z0-808 - Java SE 8 requires practice. One has to be fully prepared so as to pass the exam. Familiarizing oneself with the exam structure and types of questions is crucial.

Here are some important insights from individuals who have previously taken the exam.

  1. Know the difference between str1 == str2 and str1.equals(str2) The string class equals method compares objects yet the == operator compares reference.
// Java program to understand 
// the concept of == operator

public class Test {
   public static void main(String[] args) {
      String s1 = "HELLO";
      String s2 = "HELLO";
      String s3 = new String("HELLO");

      System.out.println(s1 == s2); // true
      System.out.println(s1 == s3); // false
      System.out.println(s1.equals(s2)); // true
      System.out.println(s1.equals(s3)); // true
   }
}
Enter fullscreen mode Exit fullscreen mode

2. Ternary operators and their compile-time errors
Java ternary operator is the only conditional operator that takes three operands. It’s a one-liner replacement for the if-then-else statement and is used a lot in Java programming.

Image description

class Test {
   public static void main(String[] args) {
      int marks = 90;
      String result = marks > 35 ? "Pass" : "Fail";
      System.out.println(result);
   }
}
Enter fullscreen mode Exit fullscreen mode

The above will return pass

3. Study the rule “String objects are Immutable” .
strings are immutable, we can not change them after creating a new object. whenever we change a string, a new instance is created.The concat() method creates a new object.

class Test {
   public static void main(String[] args) {
      String ta = "A ";
      ta = ta.concat("B ");
      String tb = "C ";
      ta = ta.concat(tb);
      ta.replace('C', 'D');
      ta = ta.concat(tb);
      System.out.println(ta);
   }
}
Enter fullscreen mode Exit fullscreen mode

On the above ABCC is the output.
The contact() method can not be used on strings because strings are not mutable.

3. lambda expressions and its simplified forms
A lambda expression is a short block of code that takes in two parameters and returns a value. They have to immediately return a value. They can not contain variables, assignments, or statements such as if or for.

3 Lambda expression parameters

  • Zero parameter
  • Single parameter
  • Multiple parameters

Zero parameter Lambda

// This a java method
void printHello()
{
    System.out.println("Hello World");
}

Or

// As lambda the above method can be written as below
() -> { System.out.println("Hello World"); };

Or

// {} is optional for single line statement
() -> System.out.println("Hello World");

Enter fullscreen mode Exit fullscreen mode

READMORE here to know more about Lambas

5. Study the difference between &(Bitwise) and &&(logical and) operator
The double && operators are usually used in loops and conditional statements. It is usually used in boolean expressions. The result is always 0 or 1.

The difference between && and & operator is that the && operator supports short circuit evaluation and the single & does not.

The bitwise (&) operator evaluates both the left and the right side of the given expression.

The logical (&&) operator evaluates only the left side of the given expression

&& operand doesn't check the second operand if the value of the second operand is false.

& operand must check both operands

6. Binary representation
eg converting a number 3 to binary

  1. Divide 3 by 2
  2. Record the remainder (0 or 1)
  3. Continue dividing the quotient by 2 until you get the quotient of 0
  4. The binary representation is the remainder read from bottom to top

So if we use 4-digit bits for consistency(0011)
and 3 in binary is 0011

The bitwise & operator compares each bit of its first operand to the corresponding bit of its second operand. If both are 1 then the corresponding result is set to 1.
So 3 & 9 in binary = 0001 which is 1 in decimal. Zeros should be added to the left only if they are needed.

*7. Access modifiers *
On access modifiers, I am not going to talk much because I have written an article on that. Here is the link to the article.

8. Instance initializer blocks
The run each time an object of a class is created

  • Initializer Blocks
    Contains the code that will always execute whenever an instance is created.

  • Constructors
    They are used to initialize the object state-like methods. Constructors also contain a collection of statements. I am also not going to talk much about constructors, check out this article that I wrote about constructors.

9. Order of execution of initialization blocks and constructors.

  1. Static initialization blocks will run whenever a class is loaded first time in the JVM.
  2. Initialization blocks run in the same order in which they appear in the program.
  3. Instance blocks are executed whenever a class is initialized and before constructors are invoked.

10. The Main Difference Between Reference And Primitive Data Types
The main difference between these two lies in how they store data

  • Primitive data type stores data directly making them memory efficient and faster to access.
  • Reference type stores memory addresses, enabling them to reference complex and share data among different program parts. Reference data type is also used for encapsulation (e.g classes, arrays, and interfaces). Stay tuned I will write an article on this one.

Engaging with practice exams and coding exercises can significantly enhance one’s understanding and retention of the material. Utilizing online resources, books, and study groups can create a robust learning environment. Joining forums or communities centered around Java can provide valuable insights and support from others who have previously tackled the same certification. I recommend taking Enthuware exams before taking the final exam.

Image description

Hands-on coding practice is essential. Building small projects, contributing to open-source code, or collaborating with peers can reinforce the practical application of concepts learned.

Image description
Staying consistent with a study schedule maintains a positive mindset 🥂.

Top comments (3)

Collapse
 
ben_dunk_5cabf3ef423f6cc9 profile image
Ben Dunk

I took the Oracle 1z0-808 and studied through Pass4surexams.com as it has all the mock tests and exam dumps along with practicing material. I scored 93% on the test.

Collapse
 
devmercy profile image
Mercy

Wow, this is great to hear, congratulations on your pass🥂. I haven't tried it yet but I'm gonna do so for my next exams.

Collapse
 
devnenyasha profile image
Melody Mbewe

I agree with you Mercy! Maintaining consistency with a study schedule can indeed help cultivate a positive mindset.