Logging with Lombok
Primitive data types
The primitive data types include boolean, char, byte, short, int, long, float and double.
Java uses the Unicode character set encoding system, not the ASCII code system. Java originally used UTF-16 for
charvalues, meaning eachcharis 16 bits and can store a Unicode code unit (not always a full Unicode character if it’s outside the Basic Multilingual Plane).
Application.java
@Slf4j
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
byte myByte = 31;
short myShort = -1000;
int myInt = 1234567;
long myLong = 76543210L;
float myFloat = 2.54f;
double myDouble = 4.545569d;
boolean myBoolean = true;
char myChar = 65;
log.info("byte: {}", myByte);
log.info("short: {}", myShort);
log.info("int: {}", myInt);
log.info("long: {}", myLong);
log.info("float: {}", myFloat);
log.info("double: {}", myDouble);
log.info("boolean: {}", myBoolean);
log.info("char: {}", myChar);
}
}Output

Wrapper classes of the Java primitive data types
It includes eight wrapper classes Byte, Short, Integer, Long, Float, Double, Boolean, Character. Wrapper classes allow us to perform various operations on primitive values, such as converting them to strings, parsing strings to obtain primitive values, and providing utility methods for arithmetic operations and comparisons.
Application.java
Output

Non-primitive data types
The non-primitive data types includes Classes, Interfaces, and Arrays, Strings and Collections such as ArrayList, HashMap etc.
Note, we will use Lombok @Data annotation which will automatically override toString() method
Class
Person.java
Application.java
Output
Arrays
Category: Based on Data Type
Array of Primitive Types

Array of Wrapper Classes
Arrays can be created to hold elements of wrapper classes for primitive types, such as Integer, Double, Character, etc.

Array of Strings
Since String is an object type in Java, an array can be created specifically to hold elements of type String.

Array of Classes
We can create an array of objects where each object is an instance of a class. This allows us to store multiple instances of the same class in an array.
Person.java
Application.java
Output

Array of Object class (java.lang.Object)
Every class in Java directly or indirectly inherits from the Object class. It provides a set of methods and behaviors that are available to all objects in Java. We can create an array of objects of the Object class in Java. The Object class is a superclass of all other classes in Java, so an array of Object can hold instances of any class.
Application.java
Output

Category: Based on Dimensions
In Java, we can create multi-dimensional arrays, which are arrays with more than one dimension. This allows to create arrays of arrays, forming a matrix-like structure. The Arrays.toString() method in Java is primarily designed to work with one-dimensional arrays. When we pass a multi-dimensional array (such as a two-dimensional array) to Arrays.toString(), it will not provide the desired output because it does not support nested arrays. The deepToString() method handles nested arrays and provides a string representation of the entire multi-dimensional array.

List
An ordered collection that allows duplicate elements.
ArrayList
ArrayList is a class in Java that provides a resizable array implementation of the List interface. It belongs to the java.util package and is commonly used to store and manipulate collections of objects.
Some commonly used types that can be used as the "type" parameter in ArrayList<type>:

LinkedList
LinkedList uses a doubly-linked list structure to store elements and dynamically allocates memory for each element.

Vector
Vector is a class in Java that provides a dynamic array-like implementation similar to ArrayList. It is part of the java.util package.

Stack
Stack is a class that represents a last-in, first-out (LIFO) data structure. It is part of the java.util package and extends the Vector class. However, it is usually recommended to use the Deque interface and its implementing class LinkedList instead, as Stack inherits from Vector, which is a legacy class.

Set
A collection that does not allow duplicate elements.
HashSet
HashSet is a class that implements the Set interface and provides an unordered collection of unique elements. It is part of the java.util package and offers constant-time performance for basic operations such as adding, removing, and checking for the presence of elements.

LinkedHashSet
LinkedHashSet is a class that extends HashSet and provides a hash table implementation with predictable iteration order. It is part of the java.util package and combines the uniqueness of elements provided by HashSet with the insertion order preservation of LinkedHashMap

TreeSet
TreeSet is a class that implements the SortedSet interface and provides a sorted set of unique elements. It is part of the java.util package and uses a self-balancing binary search tree to store and maintain its elements in sorted order.

Queue
A collection designed for holding elements prior to processing.
LinkedList
LinkedList can also be used to implement a Queue data structure. A queue is a collection that follows the first-in, first-out (FIFO) principle, where elements are added at the end and removed from the beginning.

PriorityQueue
PriorityQueue is a class that implements the Queue interface and provides a priority-based ordering of elements. It is part of the java.util package and internally uses a binary heap data structure to maintain the elements in the queue.

Deque
A double-ended queue that supports adding and removing elements from both ends.
ArrayDeque
ArrayDeque is a class that implements the Deque interface and provides a resizable-array implementation of a double-ended queue. It is part of the java.util package and offers efficient insertion and removal operations at both ends of the deque

LinkedList
LinkedList can also be used to implement a Deque data structure. A deque (short for double-ended queue) is a collection that allows insertion and removal of elements at both ends.

Map
An object that maps keys to values, where each key is unique.
HashMap
HashMap is a class that implements the Map interface and provides a hash table-based implementation of a map. It is part of the java.util package and allows storing key-value pairs, where each key is unique.

LinkedHashMap
LinkedHashMap is a class that extends HashMap and provides a hash table-based implementation of a map that maintains the insertion order of elements. It is part of the java.util package and offers the same key-value mapping functionality as HashMap, with the additional guarantee of predictable iteration order based on the order of insertion.

TreeMap
TreeMap is a class that implements the NavigableMap interface and provides a sorted map implementation based on a red-black tree data structure. It is part of the java.util package and offers key-value mapping where the keys are sorted in natural order or based on a custom comparator.

Hashtable
Hashtable is a class that implements the Map interface and provides a hash table-based implementation of a map. It is part of the java.util package and offers key-value mapping where the keys are hashed to provide efficient lookup and retrieval.

Properties
The Properties class is a subclass of Hashtable that represents a persistent set of properties. It is part of the java.util package and provides a convenient way to handle key-value pairs, typically used for configuration settings or application properties.

SortedSet
A set that maintains its elements in sorted order.
TreeSet
TreeSet is a class that implements the SortedSet interface. It represents a sorted set of elements stored in a tree-like structure. It is part of the java.util package and offers functionality similar to HashSet, but with elements sorted in their natural order or according to a custom comparator.

SortedMap
A map that maintains its entries in sorted order.
TreeMap
TreeMap is a class that implements the SortedMap interface. It represents a sorted map based on a red-black tree data structure. It is part of the java.util package and offers functionality similar to HashMap, but with the keys sorted in their natural order or according to a custom comparator.

Enumeration
An interface representing an enumeration of a collection of objects.
Vector
Vector is a class that represents a dynamic array, similar to ArrayList, and is part of the java.util package. The Enumeration interface is also part of the java.util package and provides a way to iterate over a collection of objects.

Stack
Stack class implements the Vector class and provides additional methods to support a LIFO (Last-In-First-Out) stack of objects. The Enumeration interface is part of the java.util package and provides a way to iterate over a collection of objects.
Iterator
An interface that provides a way to access elements in a collection. All collection classes provide iterators.

ListIterator
An interface that extends the Iterator interface to provide additional functionality for traversing and modifying lists.
ArrayList

LinkedList

Last updated