Creating user defined exceptions

java-thumbnail

Though Java provides an extensive set of in-built exceptions, there are cases in which we may need to define our own exceptions in order to handle the various application specific errors that we might encounter. also read: Java Tutorials Java EE Tutorials Design Patterns Tutorials Java File IO Tutorials While defining an user defined exception, […]

Copying File Contents using FileChannel

java-thumbnail

In this technical tip, let us see an easy way of achieving file copy using File Channels. File Channels are part of Java New I/O Packages. A file can be viewed as a sequence of bytes. The various Buffer classes in New I/O Packages serve as a container for manipulating the primitive byte contents. It […]

Working with Virtual Proxy Pattern

java-thumbnail

Application is often a collection of components and in most of the situations it may be the case that a component should be loaded until it is first accessed by the Client. Reasons may be that the component in consideration may be using most of the system resources. For example, consider the Microsoft Word Application […]

Making use of the Properties class

java-thumbnail

In this section, let us make use of the Properties class for storing and loading application related configuration values as well as other user information. It is also possible to query or modify the various System properties using this class. For example, the following code tries to get all the properties that are available for […]

Parsing Input using Scanner

java-thumbnail

A Scanner object can be used to read text input from a number of sources. The input source can be a file, an input stream or even from a string. It internally uses the Regular Expression Api for parsing and getting the input. Let us see a simple example to parse a String object, also […]

Randomly accessing the file contents

java-thumbnail

In this techincal tip, let us see how to access the contents of a file randomly instead of the traditional sequential access. Imagine that we want to search for a particular record in a file. If we prefer Sequential access in this case, then it will involve traversing over the file byte by byte and […]

Sorting Custom Types in Java

java-thumbnail

The class java.util.Collections provides many Utility methods for simplifying the most commonly used operations. One of the methods available in that class is sort() which is used for sorting elements. Let us the see how the Collections.sort() method operates on pre-defined data-types as well as user-defined data-types. also read: Java Tutorials Java EE Tutorials Design […]

Recursively traversing files and folders using Java File API

java-thumbnail

In this section, let us see how to recursively traverse over files and folders by making use of Java File API. Whether it is a folder or a file, both are represented as a java.io.File object. For example, consider the following code snippet, also read: Java Tutorials Java EE Tutorials Design Patterns Tutorials Java File […]

Factory pattern – Design Patterns in Java/J2EE

java-thumbnail

Creational pattern deals with the creation of objects and it hides the complex logic involved in the object creation object from the clients. One of the common creational patterns is the Factory pattern and it is used extensively in Applications. Let us understand what factors should be considered in mind while designing a Factory pattern […]

Conversion between Array and List types

java-thumbnail

In some cases, we may need to convert an array to a list or vice versa. The method asList() is available in the Arrays class, and the toArray() method in list and set classes serve this purpose. also read: Java Tutorials Java EE Tutorials Design Patterns Tutorials Java File IO Tutorials The Arrays.asList() method converts […]