Java Constructs

Java Expressions

By: Stephen Patrick | 24 Jun 2016 | Category: Java Constructs

Java Expressions

Java expressions are pieces of code that are evaluated to produce a result. Expression can consist of variables, operators and method calls and must adhere to the rules of the java language. For example assigning a variable in java is an expression.

Read More

Java Statements

By: Stephen Patrick | 24 Jun 2016 | Category: Java Constructs

Java Statements

A statement in Java can be considered as a line of code that adheres to the rules of java language and is a unit of execution. A java statement can be considered as a sentence in natural language in that it follows the rules of the language.

Read More

Java Code Blocks

By: Stephen Patrick | 25 Jun 2016 | Category: Java Constructs

Java Code Blocks

Java statements and java expressions appear inside of code blocks. A code block is simply code that is enclosed within { and } characters or as the are commonly know in java left and right curly braces. When we write java programs that code we write is enclosed within a code block. We we create a java class the code that defines the class is enclosed within a code block.

Read More

Java If Statement

By: Stephen Patrick | 25 Jun 2016 | Category: Java Constructs

Java If Statement

Java programs are normally written sequentially, as a sequence of statements. Moreover, these statements are normally executed one after the other in the order in which they are defined. However, sometimes we want to alter the order of execution by making a decision, a selection.

Read More

Java Ternary Operator

By: Stephen Patrick | 25 Jun 2016 | Category: Java Constructs

Java Ternary Operator

The java ternary operator adds syntactic sugar to the java if else clause. However, it is slightly different to your typical if / else clause. The ternary operator is specifically used to assign the result of a condition to a variable.

Read More

Java Switch Statement

By: Stephen Patrick | 25 Jun 2016 | Category: Java Constructs

Java Switch Statement

The java switch statement is similar in a way to the Java if .. else if .. else statement. A java switch statement allows a value to be tested for equality.

Read More

Java While Loop

By: Stephen Patrick | 26 Jun 2016 | Category: Java Constructs

Java While Loop

The Java while loop will continue to execute a block of code while a condition is true. The while statement takes a boolean expression. If the boolean expression evaluates to true, the while loop will continue to execute. If the boolean expression evaluates to false the while loop will cease executing.

Read More

Java Do While Loop

By: Stephen Patrick | 26 Jun 2016 | Category: Java Constructs

Java Do While Loop

Java also provides a Do While loop construct that is similar to a while loop. However, this construct has one important difference. The condition is no longer triggered before entering the loop but instead the condition is evaluated at the end of the loop.

Read More

Java For Loop

By: Stephen Patrick | 26 Jun 2016 | Category: Java Constructs

Java For Loop

The Java for loop allows you to iterate n number of times until a terminating condition is met. The Java for loop is useful when you need to execute a section of code a number of times. The Java language provides a number of loop structures, these include while, do while, for loop and the enhanced for loop.

Read More

Java Enhanced For Loop

By: Stephen Patrick | 30 Jun 2016 | Category: Java Constructs

Java Enhanced For Loop

The Java enhanced for loop was introduced in Java 5. The Java enhanced for loop facilitates the iteration of a collection / array without the need to explicitly create a collection in code.

Read More

Java Enhanced For Loop With Custom Types

By: Stephen Patrick | 30 Jun 2016 | Category: Java Constructs

Java Enhanced For Loop With Custom Types

The Java enhanced for loop simplifies the process of iterating arrays and collections. But what if you want to use this construct with custom java types. Let's examine how we can perform this task. However, first we need to define some custom java types.

Read More

Java Break And Continue Statements

By: Stephen Patrick | 01 Jul 2016 | Category: Java Constructs

Java Break And Continue Statements

The java break and continue statements are useful constructs that allow you to leave execution of a loop or skip an iteration of a loop structure. These statements are normally used with a selection construct such as if, else, or else if construct.

Read More

Java Assertions

By: Stephen Patrick | 01 Jul 2016 | Category: Java Constructs

Java Assertions

A Java assertion is a statement written in the java programming language. An assertion allows you to test an assumption in your code. Assertions were added to the Java language at version 1.4. Assertions can be used to check the pre conditions, post conditions and invariants of your code.

Read More