Building Blocks – 1Z0-829 Study Guide

OCP EXAM OBJECTIVES COVERED IN THIS CHAPTER:

✓✓ Handling date, time, text, numeric and boolean values

  • Use primitives and wrapper classes including Math API, parentheses, type promotion, and casting to evaluate arithmetic and boolean expressions

✓✓ Utilizing Java Object-­Oriented Approach

  • Declare and instantiate Java objects including nested class objects, and explain the object life-­cycle including creation, reassigning references, and garbage collection
  • Understand variable scopes, use local variable type inference, apply encapsulation, and make objects immutable

Welcome to the beginning of your journey to achieve a Java 17 certification. We assume this isn’t the first Java program-ming book you’ve read. Although we do talk about the basics, we do so only because we want to make sure you have all the terminology and detail you need for the exam. If you’ve never written a Java program before, we recommend you pick up an introductory book on Java 8 or higher. Examples include Head First Java, 3rd Edition (O’Reilly Media, 2022) and Beginning Programming with Java for Dummies (For Dummies, 2021). Then come back to this certification study guide.

As the old saying goes, you have to learn how to walk before you can run. Likewise, you have to learn the basics of Java before you can build complex programs. In this chapter, we present the basics of Java packages, classes, variables, and data types, along with the aspects of each that you need to know for the exam. For example, you might use Java every day but be unaware that you cannot create a variable called 3dMap or this. The exam expects you to know and understand the rules behind these principles. While most of this chapter should be review, there may be aspects of the Java language that are new to you since they don’t come up in practical use often.

Learning about the Environment

The Java environment consists of understanding a number of technologies. In the following sections, we go over the key terms and acronyms you need to know and then discuss what software you need to study for the exam.

Major Components of Java

The Java Development Kit (JDK) contains the minimum software you need to do Java development. Key commands include:

javac: Converts .java source files into .class bytecode

java: Executes the program

jar: Packages files together

javadoc: Generates documentation

The javac program generates instructions in a special format called bytecode that the java command can run. Then java launches the Java Virtual Machine (JVM) before

running the code. The JVM knows how to run bytecode on the actual machine it is on. You can think of the JVM as a special magic box on your machine that knows how to run your

.class file within your particular operating system and hardware.

Where Did the JRE Go?

In Java 8 and earlier, you could download a Java Runtime Environment (JRE) instead of the full JDK. The JRE was a subset of the JDK that was used for running a program but could not compile one. Now, people can use the full JDK when running a Java program. Alterna-tively, developers can supply an executable that contains the required pieces that would have been in the JRE.

When writing a program, there are common pieces of functionality and algorithms that developers need. Luckily, we do not have to write each of these ourselves. Java comes with

a large suite of application programming interfaces (APIs) that you can use. For example, there is a StringBuilder class to create a large String and a method in Collections

to sort a list. When writing a program, it is helpful to determine what pieces of your assign-ment can be accomplished by existing APIs.

You might have noticed that we said the JDK contains the minimum software you need. Many developers use an integrated development environment (IDE) to make writing and running code easier. While we do not recommend using one while studying for the exam, it is still good to know that they exist. Common Java IDEs include Eclipse, IntelliJ IDEA, and Visual Studio Code.