How to sort an array in java

2Jun2010 In: Core Java

A Java array is an indexed table with a fixed number of slots, each slot holds a item, and all elements have the same type, this tutorial will demo how to sort an array in Java. Read the rest of this entry »

CXF web service client example

2Jun2010 In: Web Services

CXF Client overview

In previous chapter, we introduced get starting CXF web service example and CXF interceptor, CXF also provides you with many options to build CXF clients, today we will have quick view how to develop web Service client. Read the rest of this entry »

CXF Interceptor example: how to get HTTP Headers in CXF

28May2010 In: Web Services

CXF Interceptor Overview:

CXF has high federated extensibility which benefits from the design of interceptor and InterceptorChain, Interceptor is the fundamental processing unit inside CXF, the series of interceptors inside CXF are responsible for the whole handling process started by invoking a web service request to sent a response. and includes processing soap XML, transforming data, parsing headers and even more. Read the rest of this entry »

How do I Get User Application Data Directory in Java?

28May2010 In: Core Java

The Java program sometimes need to access the user application data directory, to save or get some temp or cache dates, the application data file path is defined as following: Read the rest of this entry »

How to recursively List All Files in a Directory in Java

28May2010 In: Core Java

The propose of this tutorial is to demonstrate how do I list all files In a directory in Java, unfortunately, such common function isn’t supported in JDK specification standard API. Read the rest of this entry »

Java Interview Swing Questions

26May2010 In: Core Java

Here list some java interview swing questions:

Interview Questions (1):  What’s swing?
Answer:  It is the Java graphical user interface (GUI) toolkit which is built on earlier Abstract Windowing Toolkit (AWT) libraries.   Read the rest of this entry »

How do I sort a Map by Key in Java

25May2010 In: Core Java

The elements in map are stored as {<”testkey1″, “value1″>, <”testkey2″, “value2″>, Map class makes no guarantees as to the order, it is unordered so that we can’t assume anything beyond that, in this how-to, we will look at how to sort a map by Key in Java.

1. Use HashMap sort the collections.

Object[] key = map.keySet().toArray();
for (int i = 0; i < key.length; i++) {

(2) Use TreeMap instead of HashMap, this is precisely what its for, if this map is passed to you and you cannot determine the type, so you can do the following:

TreeSet<String> keys = new TreeSet<String>(map.keySet());
for (String key : keys) {
String value = map.get(key);
// do something

(3) If  TreeMap is not what you want and you can’t use generic:

List sortedKeys=new ArrayList(yourMap.keySet());
// Do what you need with sortedKeys.
Map is an interface defined in JDK, it has three generic implementations: HashMap, TreeMap and LinkedHashMap, also some additional Map implementations are: IdentityHashMap, RenderingHints, TreeMap, WeakHashMap.

Java RMI example – Just get starting

22May2010 In: Distributed Java

Java remote method invocation(Java RMI) Overview

In order to execute the binary class on remote machine, the traditional way is error-prone pattern and difficult to understand. What we do today is to use The Java Remote Method Invocation (RMI), it allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. Read the rest of this entry »

How Do I Share a HttpURLConnection Sessions across Multiple Requests

20May2010 In: Core Java

HttpURLConnection is subclass of URLConnection with support for HTTP-specific features, for example: open a connection, retrieve message and post data to server.

Read the rest of this entry »

Java RMI error unmarshalling arguments

19May2010 In: Distributed Java

Java RMI(Java Remote Method Invocation) is a Java API that performs the object-oriented equivalent of remote procedure calls (RPC), it allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. It provides for remote communication where all participating applications are written by Java. Read the rest of this entry »