Archive for category Core Java

Returning Data from Java Threads

There are a couple of ways in which threads can be created. i.e. Implementing Runnable Interface and extending Thread Class (Example here). Further we need to implement run method and do our processing inside the run method. This would look like below. One thing to note about above snippet is the return type of run() […]

, , , ,

6 Comments

Creating and Running thread in Java

Like any other Object in java, Threads are Objects. There are a couple of ways threads can be created in Java. Extending the Thread class and overriding it’s Run() method Building a class that implements Runnable Interface and implementing it’s run() method. Then create an Object of the Thread class and pass an instance of […]

, , ,

1 Comment

Bubble Sort in Java

Bubble Sort is a generic algorithm to sort the elements and can be implemented in any programming language. The algorithm gets its name from the way smaller elements “bubble” to the top of the list. it is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair […]

, , ,

Leave a comment

List of all Locales

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat.getAvailableLocales() method returns an array of Locale objects for which localized DateFormat instances can be obtained. Code snippet below lists all available locales ListAllLocales.java Output References http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

, ,

Leave a comment

What is the difference between ArrayList and LinkedList

LinkedList and ArrayList are two different implementations of the List interface. LinkedList implements it with a doubly-linked list. ArrayList implements it with a dynamically resizing array. The difference between the two boils down to the basic difference between and Array and LinkedList. Here are the differences between them: Since Array is an index based data-structure […]

, , , , ,

1 Comment

Using properties file in java application

Properties files are a cool place to store your configuration details like database connection properties, error messages and other configurations for your program. You can use properties file in your application using following utility class. This class basically loads your properties file on first attempt to access any property on further attempts to access any […]

, , , , ,

8 Comments

How to Write formatted xml in Java

To write a formatted xml in java you have to set some properties of Transformer Above settings instruct Transformer to spit a formatted xml. See complete example below Output:

, , , ,

1 Comment