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 ....



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 »

Java Generics Examples

1. Introduction Sun Microsystems included Java Generics in java 1.5 to introduce the type-safety feature while using the collection classes. It also complements auto-boxing, auto-unboxing, bounded variables, covariance, etc. There are other benefits of Generics such as java generic methods. We will uncover each. 2. What is Java Generics Java Generics is a technical term denoting a set of language features ...

Read More »

Static Variable Java Example

1. Introduction This is a static variable Java Example. Static variables are declared with the static word before the type of variable. The main difference among regular variables is that static variables are not bounded by any object instances, and are shared among all instances. static datatype Variable //static variable example static int count = 0; 2. Simple Static Variable ...

Read More »


In this example we shall show you how to use a short type in Java. The short data type is a 16-bit signed two’s complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive).  To create a variable of short type you can just use the short keyword in the variable, as described in the code ...

Read More »


With this example we are going to demonstrate how to use a long type in Java. The long data type is a 64-bit signed two’s complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int. In short, ...

Read More »


This is an example of how to use an int type in Java. The int data type is a 32-bit signed two’s complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason to choose something else. This data ...

Read More »


In this example we shall show you how to use a float type in Java. The float data type is a single-precision 32-bit IEEE 754 floating point. Use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, ...

Read More »