Java Building Blocksis the first important chapter for When appearing for OCA (Oracle Certified Associate Exam 1Z0-808), (or for Java 8 Certification). You must understand the Java Basics & Java Data Type fundamental. You would not only learn the fundamental of java building blocks but also some of the important aspect of hands-on java programming which many experience developer may not be aware of. It is very important to go through each tips and techniques described in this article.

Before we deep dive on Java building blocks, I would like to list down the topic which I am going to cover it here

Java Basics

  1. Define the variables scope
  2. Define the structure of Java classes
  3. Create executable Java applications with a main method
  4. Import other Java packages to make them accessible in yourcode
  5. Compare and contrast the features and components of Javasuch as platform independence, object orientation, encapsulation, etc.

Working with Java Data Types

  1. Declare and initialise variables (including casting or primitivetypes)
  2. Differentiate between object reference variables and primitive variables
  3. Know how to read or write to object fields
  4. Explain an Objects Life-cycle (creation, deference byreassignment and garbage collection)

Read the full java certification syllabus article by clicking here, also review building block practice test paper

Understanding the Java Class Structure

In Java programs, classes are the basic building blocks. When defining a class, we describeall the parts and characteristics of one of those building blocks. To use most classes, youhave to create objects. An object is a run-time instance of a class in memory. All the variousobjects of all the different classes represent the state of your program.

Fields and Methods

Java classes have two primary elements: methods, often called functions or procedures inother languages, and fields, more generally known as variables. Together these are called themembers of the class. Variables hold the state of the program, and methods operate on thatstate. If the change is important to remember, a variable stores that change.

The simplest Java class you can write looks like this:

public class Bird{

Java calls a word with special meaning a keyword. The public keyword on line 1 meansthe class can be used by other classes. The class keyword indicates youre defining a class.Animal gives the name of the class. Granted, this isnt a very interesting class, so add yourfirst field:

public class Bird{
String name;
public string getName(){
return name;
public void setName(String newName){
name = newName;

On next line, it defines a variable named name. We also define the type of that variable tobe a String. A String is a value that we can put text into, such as “this is a string”.String is also a class supplied with Java. On lines 35, youve defined your first method. A method is an operation that can becalled. Again, public is used to signify that this method may be called from other classes.Next comes the return typein this case, the method returns a String. On lines 68 isanother method. This one has a special return type called void. void means that no value atall is returned. This method requires information be supplied to it from the calling method; this information is called a parameter. setName has one parameter named newName, and itis of type String. This means the caller should pass in one String parameter and expectnothing to be returned.The full declaration of a method is called a method signature.


Another common part of the code is called a comment. Because comments arent executablecode, you can place them anywhere. Comments make your code easier to read. Youwont see many comments on the examthe exam creators are trying to make the code difficult to readbut youll see them in this book as we explain the code. And we hope youuse them in your own code. There are three types of comments in Java. The first is called asingle-line comment:

// comment until end of line

A single-line comment begins with two slashes. Anything you type after that on thesame line is ignored by the compiler. Next comes the multiple-line comment:

/* Multiple
* line comment

A multiple-line comment (also known as a multi-line comment) includes anythingstarting from the symbol /* until the symbol /. People often type an asterisk () at thebeginning of each line of a multi-line comment to make it easier to read, but you dont have to. Finally, we have a Javadoc comment:

* Javadoc multiple-line comment
* @author Admin

This comment is similar to a multi-line comment except it starts with /**. This specialsyntax tells the Javadoc tool to pay attention to the comment. Javadoc comments have aspecific structure that the Javadoc tool knows how to read. You wont see a Javadoc commenton the examjust remember it exists so you can read up on it online when you startwriting programs for others to use.

All OCJP Java Certification Tutorials

  1. Oracle (OCJP) Java Certification Exam
  2. Java Building Blocks Java 8 Certification
  3. Operators And Statements
  4. Java Core API
  5. Java Class Design
  6. Java Exception
  7. Java Try-Catch Block
  8. Exceptional Handling in Java
  9. Common Exception in Java