Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions


and many more ....



Continue Java Statement

1. Continue Java Statement In this example, we shall show you how to use the continue keyword statement in Java. The continue statement skips the current iteration of a for, while, or do-while loop and it continues the current flow of the program. In case of an inner loop, the continue statement continues only the inner loop. In this example, ...

Read More »

Compare integers

With this example we are going to demonstrate how to compare integers. The comparation between two integers can be performed using the greater than and less than symbols. In short, to compare two integers i1 and i2 you should: Check if i1 is greater than i2 in an if statement. If it is true, that means that i1 is greater ...

Read More »

Simple if else Java Example

In this post, we feature a simple if else Java Example. The Java if statement is used to test a boolean condition i.e. true or false. 1. Introduction The logic inside the if condition executes when the condition is true otherwise the else block is executed. Java supports various types of if statements. if statementif else statementif else if statementnested ...

Read More »

Simple if statement

In this example we shall show you how to use a simple if statement. The if-else statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular expression evaluates to true. To use a simple if statement one should perform the following steps: Create a new boolean ...

Read More »

Free Flowing Switch Statement

With this example we are going to demonstrate how to create a free flowing switch statement. A free flowing switch statement is a switch statement where break statement is not specified, thus all cases after the matching one (including the default) will be executed. In short, to create a free flowing switch statement you should: Create a switch statement that evaluates ...

Read More »

try/catch/finally InputStream example

This is an example of an InputStream in a try/catch/finally statement. Using try/catch/finally statement to create an InputStream implies that you should: Create an InputStream and initialize it to null. Open a try statement and initialize the InputStream to a FileInputStream, by opening a connection to an actual file. Include the catch statement to catch any IOExceptions thrown while trying ...

Read More »

try with resource example

The NewResource code below: public class NewResource implements AutoCloseable{ String closingMessage; public NewResource(String closingMessage) { this.closingMessage = closingMessage; } public void doSomeWork(String work) throws ExceptionA{ System.out.println(work); throw new ExceptionA("Exception thrown while doing some work"); } public void close() throws ExceptionB{ System.out.println(closingMessage); throw new ExceptionB("Exception thrown while closing"); } public void doSomeWork(NewResource res) throws ExceptionA{ res.doSomeWork("Wow res getting res to do ...

Read More »

Java throw Exception Example

In this post, we feature a comprehensive Java throw Exception Example.  1. What is an Exception in Java? Exception is mechanism which Java uses to handle any unforeseen use-case/scenario. Basically an exception is thrown when either something unexpected happened during code execution which is not covered in any code block(converting some null value to lowercase()) or some IO operation communicating ...

Read More »

Create custom Exception example

This is an example of how to create and use a custom exception that will be thrown in a specified condition. In order to create a custom exception and use it in a method invocation we have followed the steps below: We have created an InvalidPassException class that extends the Exception and uses the Exception’s constructors in its constructors.  We have ...

Read More »

Checked and Unchecked Exceptions example

In this example we shall show you how to use a checked and an unchecked exception. A checked exception is anything that is a subclass of Exception, except for RuntimeException and its subclasses. In order to use a checked and an unchecked exception we have followed the steps below: We have created a method, void checkSize(String fileName) that creates a ...

Read More »