Snippet IT IT News, Programming, Internet and Blogging

5Jan/102

Java: Format Integer Into Fixed Width String

Sometime, you may want to format an integer or a long value into a fixed width String. You need to display the value in fixed width especially in reports where you want to keep the numbers in aligned (e.g. 3456 as 0003456 and 1234 as 0001234).

Other than that, you may also want to format the integer value for a better visibility. For example, to display integer value as a document number (e.g. 12345678 as 00-01234-5678), for example an account number.

The Java.format() is not flexible enough to solve my problem. At least it cannot be used to format a fixed length document number in the format I want: XX-XXXX-XXXX. Therefore I decide write my own format function.

17Dec/090

Java: Continuously Read Data From FileChannel Without MappedByteBuffer

When programmer writes a program to read data from a file continuously and sequentially with a fixed data type reading sequence (e.g. to read three integers then 2 doubles repeatedly), he or she may find the MappedByteBuffer from Java library is useful.

26Nov/090

WordPress: How To Add Table Into A Post

WordPress' WYSIWYG post editor does not come with the functionality that allows user to create table when editing a post (like what you can do in Microsoft word).

10Nov/091

Java: Loading Large Data into JTable or JList

In software programming (especially Graphical User Interface or GUI programming), many times, we need to load data from file or database into a table or list to be displayed to user on computer screen. Most of the time, the size of the data can be determined only during runtime. The data could be very small to a few rows of record and could be very large to a few millions rows of record.

18Aug/092

Java: Format Long Integer Into Hexadecimal String

In software programming, sometime you may want to convert a long integer or integer into hexadecimal string for viewing purpose or also as a text format to be stored in text file or database.

The Java API itself does not have a class or function to convert a long into a fixed 16 characters hexadecimal string or an integer into  fixed 8 characters hexadecimal string.

The Java's Long.toHexString(long i) or Integer.toHexString(int i) only able to convert the integer value to a string of ASCII digits in hexadecimal (base 16) with no extra leading 0s and it does not support the reverse way (from hexadecimal string to long integer value).

16Jun/090

Java: Stop A Thread Correctly

In Java programming, it is very common to use threads to perform multi tasks simultaneously. Starting a thread is pretty easy but stopping a thread might be a headache for some programmers, especially when the thread needs to run a task that takes some times.

11May/090

JSP: How to Declare Methods and Inner Class in JSP

JSP itself is just a plaint text and will be translated into Java source file (actually a servlet), compiled into class file and only interpreted at the end during runtime. All these happen at the backend.

When the whole JSP is translated into Java source file, all the HTML codes will be translated and source lines in <% %> tag will be included in a function of the translated servlet source file.

8May/092

WordPress Theme: How to Enable Gravatar in WordPress Theme

Gravatars are Globally Recognized Avatars. An avatar or gravatar is an icon, or representation, of a user in a shared virtual reality, such as a forum, chat, website, or any other form of online community in which the user(s) wish to have something to distinguish themselves from other users. 

Gravatar 

7May/090

Gmail: How to Search Your Email Quickly in Gmail

If your are using Gmail as you email client,  how do you search all your emails from your girl friends with keywords "I love your" for a certain date range for the received emails? 

Gmail Search 

4May/092

Gmail: How to Monitor Your Mail Account Activities

How do you know your Gmail account's actitivies like the date and time when you signin, access type (mobile, web and etc) and the IP addresses where you signin your Gmail mail account. 

Sometime you may have signed in at other PC (like cyber cafer, friends's house and etc) and may have forgotten to sign out. How can you ensure that all your Gmail mail account sessions has been signed out.