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

 

 

long

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 »

int

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 »

float

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 »

double

With this example we are going to demonstrate how to use a double type in Java. The double data type is a double-precision 64-bit IEEE 754 floating point. For decimal values, this data type is generally the default choice. This data type should never be used for precise values, such as currency. In short, to create a variable of double ...

Read More »

char

This is an example of how to use a char type in Java. The char data type is a single 16-bit Unicode character. It has a minimum value of ‘\u0000’ (or 0) and a maximum value of ‘\uffff’ (or 65,535 inclusive). In order to create variable of char type you should type the char keyword in a variable. Let’s take ...

Read More »

byte

In this example we shall show you how to use a byte type in Java. The byte data type is an 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They ...

Read More »

boolean

With this example we are going to demonstrate how to use a boolean type in Java. The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its “size” isn’t something that’s precisely defined. In short, to create variable ...

Read More »

Using an enum as a state machine

In this short example, a parser state machine processes raw XML from a ByteBuffer. Each state has its own process method and if there is not enough data available, the state machine can return to retrieve more data. Each transition between states is well defined and the code for all states is together in one enum. interface Context { ByteBuffer ...

Read More »

Each Enum Instance a different sub-class

In this example we shall show you how to have each enum instance represent a different sub-class. To make each enum instance represent a different sub-class one should perform the following steps: Create an enum with different enum constants. Give each enum constant a different behavior for some method. Declare the method abstract in the enum type and override it with ...

Read More »

Enum to implement an interface

With this example we are going to demonstrate how to use an enum to implement an interface. Implementing an interface with an enum can be useful when we need to implement some business logic that is tightly coupled with a discriminatory property of a given object or class. In short, to implement an interface with an enum you should: Create ...

Read More »