devxlogo

Tip Bank

Adding Custom Attributes to HTML Elements

A custom attribute is any user-defined attribute, just like other primitive HTML element attributes. You can add custom attributes to any HTML element. For example, suppose you wanted to add

Associate a ServerSocket with a ServerSocketChannel in an NIO App

This tip shows you how to create a ServerSocketChannel, to which you’ll then associate a standard ServerSocket: //create the ServerSocketChanneltry{ serverNIO=ServerSocketChannel.open(); serverNIO.configureBlocking(false); }catch(IOException e) {System.out.println(” Error: ” + e.getMessage());}//indicate the

How to Use Properties Files in Java

In Java, you can easily create and use a properties file containing name/value pairs. First, make a .properties file?name it Properties.properties. Place key/value pairs such as name = java in

Truncate a Path String

Sometimes you need to truncate a long path string to make it fit in a control. Currently, there is no .NET class that provides this functionality. The workaround is to

Using the Final Keyword in Java

Contrary to popular opinion, the compiler cannot safely inline methods that have been declared as final. This is because these methods may have non-final declarations at runtime. For example, suppose

Trimming Items in a String Array

When you use a For Each loop to iterate through a String Array and perform some action with each item, the change doesn’t affect the String Array itself. Consider the

Changing the Style of a String in JavaScript

JavaScript’s String object provides functions that display style of the text: big() blink() bold() fixed() fontsize(&ltsize&gt): This function takes a parameter to specify the font-size in pixels. fontcolor(““): This function

Encode and Decode URLs Using UTF-8

This tip shows you how to encode and decode your URLs using the UTF-8 character encoding: import java.net.*;public class URL_Encoder_Decoder{ public static void main(String[] args){ String url = “@sir de