Home » Archives for Ilias Tsagklis » Page 32

Author Archives: Ilias Tsagklis

Avatar photo
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Conditional logging

Bipartite Graph

This is an example of how to use Conditional logging. Using conditional logging in a Class means that we check the Level for which the Logger is enabled before we log a message to that level. We have implemented a Class that uses a logger. The Class consists of a simple method that uses the logger to log messages after ...

Read More »

Log an exception

Bipartite Graph

With this example we are going to demonstrate how to log an exception. In order to do so, we will use a DateFormat and parse a String pattern to create a new Date. In short, to log the ParseException that occurs you should: Create a new SimpleDateFormat with a specific String pattern. Invoke the setLenient(boolean lenient) API method of the ...

Read More »

Use of logger console handler

Bipartite Graph

In this example we shall show you how to use a logger’s ConsoleHandler. The ConsoleHandler is a handler that takes logs from a Logger and publishes them to System.err. To use the ConsoleHandler one should perform the following steps: Create a Logger instance, with the getLogger(String name) API method of the Logger. Create a ConsoleHandler for System.err. Add the handler ...

Read More »

Create a sequence of log files

Bipartite Graph

This is an example of how to create a sequence of log files. Creating a sequence of log files implies that you should: Create a new instance of a Logger. Create an instance of FileHandler with a specific number of logging files sequences, a specific size for each file and append set to true. In the example 5 files will ...

Read More »

Set Formatter for Logger handler

Bipartite Graph

With this example we are going to demonstrate how to set a Formatter for a Logger Handler. The Formatter is used by the Handler to format LogRecords. In short, to set a Formatter for a Logger’s handler you should: Create a new Logger instance with getLogger(String name) API method of Logger. Create a new FileHandler to write to a specific ...

Read More »

Log method call

Bipartite Graph

In this example we shall show you how to log a method call. We have implemented the LogMethodCall Class, with a simple method to log its messages. The basic steps of the example are described below: The call(String arg1, Object arg2) method of the class takes a String argument and an Object argument and returns a boolean value. The method ...

Read More »

Swap List elements example

Bipartite Graph

This is an example of how to swap a List’s elements . We are using the swap(List list, int i, int j) method of the Collections Class. Collections provides static methods that operate on or return collections. We are also using the ArrayList as a List implementation, but the same API applies to any type of List implementation classes e.g. ...

Read More »

Reverse order of List example

Bipartite Graph

With this example we are going to demonstrate how to reverse the order of a List. This is provided by the reverse(List list) API method of the Collections class. The ArrayList is used as a List implementation, but the same API applies to any type of List implementation classes e.g. Vector etc. In short, to reverse the order of a ...

Read More »

Replace all elements of List example

Bipartite Graph

In this example we shall show you how to replace all elements of a List. We will use the fill(List list, Object element) API method of the Collections class. Collections provides static methods that operate on or return collections. The ArrayList is used as a List implementation, but the same API applies to any type of List implementation classes e.g. ...

Read More »

Get unmodifiable Collection

Bipartite Graph

This is an example of how to get an unmodifiable Collection. The same API applies to any type of Collection implementation classes e.g. HashSet, TreeSet, LinkedHashSet, LinkedList etc. Nevertheless Java util API provides separate methods for getting immutable Collection views based on the following Collection implementation classes: – static Collection unmodifiableCollection(Collection) – static List unmodifiableList(List) – static Set unmodifiableSet(Set) – ...

Read More »