Thursday, September 15, 2011

New Features in Java version 7

The new release of Java 7 introduced exciting new features in the language; following is the list of these features:

  • Strings in the Switch Statement
For details please visit: http://download.oracle.com/javase/7/docs/technotes/guides/language/strings-switch.html
  • Type Inference for Generic Instance Creation (diamond symbol <>)
For details please visit:
http://download.oracle.com/javase/7/docs/technotes/guides/language/type-inference-generic-instance-creation.html
  • The try-with-resources Statement
For details please visit:
http://download.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html

  • Catching multiple Exception Types and Rethrowing Exception with Improved Type Checking
For details please visit:
http://download.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html
  • Enhancements in Java I/O (new package named java.nio)
For details please visit:
http://download.oracle.com/javase/7/docs/technotes/guides/io/enhancements.html#7
http://download.oracle.com/javase/tutorial/essential/io/notification.html

  • Java Virtual Machine Support for Non-Java Languages
For details please visit:
http://download.oracle.com/javase/7/docs/technotes/guides/vm/multiple-language-support.html

  • JLayer Pane to Decorate Components with JLayer Class
For details please visit:
http://download.oracle.com/javase/tutorial/uiswing/misc/jlayer.html

Wednesday, August 10, 2011

To Check Internet Explorer (IE) version


Little helper function to return details about IE 8 and its various compatibility settings either use as it is or incorporate into a browser object. Remember browser sniffing is not the best way to detect user-settings as spoofing is very common so use with caution.


function IEVersion(){
var _n=navigator,_w=window,_d=document;
var version="NA";
var na=_n.userAgent;
var ieDocMode="NA";
var ie8BrowserMode="NA";
// Look for msie and make sure its not opera in disguise
if(/msie/i.test(na) && (!_w.opera)){
// also check for spoofers by checking known IE objects
if(_w.attachEvent && _w.ActiveXObject){
// Get version displayed in UA although if its IE 8 running in 7 or compat mode it will appear as 7
version = (na.match( /.+ie\s([\d.]+)/i ) || [])[1];
// Its IE 8 pretending to be IE 7 or in compat mode
if(parseInt(version)==7){
// documentMode is only supported in IE 8 so we know if its here its really IE 8
if(_d.documentMode){
version = 8; //reset? change if you need to
// IE in Compat mode will mention Trident in the useragent
if(/trident\/\d/i.test(na)){
ie8BrowserMode = "Compat Mode";
// if it doesn't then its running in IE 7 mode
}else{
ie8BrowserMode = "IE 7 Mode";
}
}
}else if(parseInt(version)==8){
// IE 8 will always have documentMode available
if(_d.documentMode){ ie8BrowserMode = "IE 8 Mode";}
}
// If we are in IE 8 (any mode) or previous versions of IE we check for the documentMode or compatMode for pre 8 versions
ieDocMode = (_d.documentMode) ? _d.documentMode : (_d.compatMode && _d.compatMode=="CSS1Compat") ? 7 : 5;//default to quirks mode IE5
}
}

return {
"UserAgent" : na,
"Version" : version,
"BrowserMode" : ie8BrowserMode,
"DocMode": ieDocMode
}
}
var ieVersion = IEVersion();
var IsIE8 = ieVersion.Version != "NA" && ieVersion.Version >= 8;

if (!IsIE8) {
alert("Please upgrade to Internet Explorer 8 or better!" ) ;
}

Wednesday, July 13, 2011

Masking a HTML TextField as Numeric or Float

Add these functions to your JavaScript code under <script> tag.

function getKey(evt) { // works for IE, Netscape, Firefox, Opera, Chrome

var theEvent = evt || window.event;

var key = theEvent.keyCode || theEvent.which;

return key;

}

function MaskNumeric(evt) {

//8 Delete, 39 left cursor, 37 right cursor, 35 end, 36 home, 9 tab, 116 f5

//127 Backspace 48-57 0-9

var key = getKey(evt);

if( (key == 116 || key == 8 || key == 9 || key == 39 || key == 37 || key == 35 ||

key == 36 || key == 189 || key == 109 || key == 127 || key == 46) ||

(key >= 48 && key <= 57) ||

(key >= 96 && key <= 105) ) {

return true;

} else {

return false;

}

}

function MaskFloat(evt) {

//8 Delete, 39 left cursor, 37 right cursor, 35 end, 36 home, 9 tab, 116 f5

//127 Backspace 48-57 0-9

var key = getKey(evt);

if( (key == 116 || key == 8 || key == 9 || key == 39 || key == 37 || key == 35 ||

key == 36 || key == 189 || key == 109 || key == 127 || key == 46 || key == 110 || key == 190) ||

(key >= 48 && key <= 57) ||

(key >= 96 && key <= 105) ) {

return true;

} else {

return false;

}

}


Then use the following code in your HTML form.

For Numeric Masked Field:

<input type="text" onkeypress="return MaskNumeric(event);" />

For Float Masked Field.

<input type="text" onkeypress="return MaskNumeric(event);" />