What is the difference between File and RandomAccessFile objects?

Both `File` and `RandomAccessFile` classes “operate” on files but they have different areas of expertise. We’ll talk about both of those classes.

File

`java.io.File` deals with the file-system aspects of the file i.e creating it, deleting, querying if it exists, getting paths etc.

To read a File we usually either use a `Reader` (e.g `java.io.FileReader`) or an `InputStream` […]

What is the purpose of bit sets in Java?

There are two ways to view a `java.util.BitSet` in Java: either it is a convenient way to conveniently store a set of integers (or some other data that may be converted to an integer) or `BitSets` may be viewed as a growable vector of booleans (or bits).

Individual bits can be set on and off (elements […]

What is epoch and what is its significance in java?

Epoch also known as the unix epoch is a single date 1 January 1970 at 00:00:00 UTC. It is quite common to measure time from this date something known as epoch time or unix time.

There is some ceremony in handling leap seconds (seconds inserted into a minute so that the astronomical time matches more […]

What is the purpose of class named Lock in Java and what are the various sub types of Lock class?

The `java.util.concurrent.Lock` class provides more advanced locking mechanisms then using vanilla synchronization on Objects.

We use locks to control the access to some resource so that it may be safely used by multiple threads. Using simple locks (synchronized Object) this is a very coarse grained strategy in which only one thread can access a shared resource.

Using […]

How do StringBuilder and StringBuffer to grow dynamically in size?

`StringBuffer` and `StringBuilder` are two classes responsible for dynamic string construction. They’re both grow-able data structures to which the programmer can append, insert or delete characters. The `StringBuffer` class can be though as a synchronized `StringBuilder` class and for simplicity we’ll only talk about the `StringBuilder` class.

But how this is done? How can `StringBuilder` work […]

IllegalThreadStateException and InterruptedException in a Java

InterruptedException

`InterruptedException` is thrown in a thread every exactly under two conditions (both of which must be true):

A thread is waiting on a resource either directly through the Thread.sleep, Thread.wait, or Thread.join methods or blocked using the `java.nio.channels.InterruptibleChannel` or `java.nio.channels.Selector`classes.
Some other thread interrupts it (by the `interrupt()` method).

If a thread throws the `InterruptedException` the interrupt status […]

Object Oriented Analysis (OOA), Object Oriented Design (OOD) and Object Oriented Programming (OOP)?

Programming and software engineering is full of TLA (three letter acronyms). In this article we will delve into three three TLAs: OOP (object oriented programming), OOA (object oriented analysis) and OOD (object oriented design).

Object Oriented Programming

Object Oriented Programming is a very loaded term with many conflicting definitions, some people don’t even consider object orientation to […]

What is race condition and how is it different from deadlock?

It is common knowledge that programming multi-threaded applications is much more difficult then programming single threaded ones. One must be careful where and how he synchronizes or else one might find race conditions or deadlocks.

Race condition

A race condition is where the execution of a program depends on the sequence of execution – most commonly we […]

How to stop a Thread gracefully in Java

You may have wondered how you should stop a thread in Java. While browsing the documentation for the Java Thread class you may notice the following methods that seem to do what you want:

`destroy()`

`stop()`

`stop(Throwable)`

(these are methods to “stop” a running thread) but they have one thing in common: they are […]

Handling complete exception heirarchy or specific exceptions?

As we know, exceptions are the unexpected events occurred during program execution and usually are caught by the application code to take the necessary actions. An ‘Exception’ also being a class in Java, we can extend the same to create the exception hierarchies. To create application specific custom exceptions we have to extend the ‘exception’ […]

x

Enter your email address:

Delivered by FeedBurner

Java ExperienceA place for all type of Java web tutorials2014