Thursday, November 20, 2008

Javascript: Making Initial Letter Capital for text box

Following script will work to make the initial letter in your text box automatically.

I have placed this in onKeyup event, you can use it according to your own requirements.

onkeyup=
"this.value=this.value.substring(0,1).toUpperCase()
+this.value.substring(1,this.value.length)"


Here is the example:

Thursday, November 13, 2008

JavaScript: Function To Check Whether provided string contains some wildcard character

The following function returns true if the string value contains the specific wild-card character.

Parameters:

1- fieldValue -- String

It is a string that needs to be checked whether it contains some special/wildcard characters

2- wildChar -- String/ Single Char

It is a character that you want to search whether it is present in the string passed as first parameter of this function.


function containsWildCard(fieldValue, wildChar)
{
// var fieldValue = window.document.getElementById("fieldID").value;
if (fieldValue.split(wildChar).length > 1)
{
alert ("WildCard!");
return false;
}
else
{
alert ("No - WildCard!");
return true;
}

}

Monday, November 3, 2008

Javascript: Function To Get Currrent Time

function getCurrentTime()
{
var d = new Date();

var hour=d.getHours();
var minute=d.getMinutes();
var second=d.getSeconds();

if(hour<10)
{
hour = '0'+hour;
}
if(minute<10)
{
minute= '0'+minute;
}

if(second<10)
{
second= '0'+second;
}

var time =hour+':'+minute+':'+second

return time;
}

Thursday, October 16, 2008

JAVA Certification Track Summary

JAVA Certification Track


1. Sun Certified Associate for the Java Platform, Exam Version 1.0 (CX-310-019)
  • Delivered at: Authorized Prometric Testing Centers
  • Prerequisites: None
  • Other exams/assignments required for this certification: None
  • Exam type: Multiple choice and Drag and Drop
  • Number of questions: 51
  • Pass score: 68% (35 of 51 questions)
  • Time limit: 115
2. Sun Certified Java Programmer, Standard Edition 6 (CX-310-065)
  • Delivered at: Authorized Worldwide Prometric Testing Centers
  • Prerequisites: None
  • Other exams/assignments required for this certification: None
  • Exam type: Multiple choice and drag and drop
  • Number of questions: 72
  • Pass score: 65% (47 of 72 questions)
  • Time limit: 210 minutes
3. Sun Certified Web Component Developer (SCWCD)
  • Delivered at: Delivered at: Authorized Worldwide Prometric Testing Centers
  • Prerequisites: Sun Certified Programmer for the Java Platform (any edition)
  • Exam type: Multiple Choice and Drag and Drop
  • Number of questions: 69
  • Pass score: 70% (49 of 69 questions)
  • Time limit: 180 minutes
4. Sun Certified Business Component Developer (SCWCD)
  • Delivered at: Authorized Worldwide Prometric Testing Centers
  • Prerequisites: Sun Certified Programmer for the Java 2 Platform (any edition)
  • Exam type: Multiple-Choice, Scenario-based questions and Drag-and-Drop questions
  • Number of questions: 61
  • Pass score: 59% (36 of 61 questions)
  • Time limit: 145 minutes
5. Sun Certified Developer for Java Web Services (SCDJWS)
  • Delivered at: Authorized Worldwide Prometric Testing Centers
  • Prerequisites: Sun Certified Programmer for the Java 2 Platform (any edition)
  • Other exams/assignments required for this certification: None
  • Exam type: Multiple choice, drag and drop
  • Number of questions: 69
  • Pass score: 68% (47 items of 69 questions)
  • Time limit: 150 minutes
6. Sun Certified Mobile Application Developer (SCMAD)
  • Delivered at: Authorized Worldwide Prometric Testing Centers
  • Prerequisites: Sun Certified Programmer for the Java 2 Platform (any edition)
  • Exam type: Multiple choice, drag and drop
  • Number of questions: 68
  • Pass score: 55% (38 items of 68)
  • Time limit: 150 minutes
7. Sun certified Java Developer (SCJD)

This exam consists of two parts first part is an programming assignment. The scale of the assignment can be imagined by the lines of code; roughly this assignment consists of 3500 lines of code.

The second part of this exam is an essay type consisting of four different questions that are related from your programming assignment of part one.

PART ONE:
  • Delivered at: CertManager database
  • Prerequisites: Must be Sun Certified Programmer for the Java Platform (any edition)
  • Other exams/assignments required for this certification: Step 2 (CX-310-027)
  • Exam type: Programming assignment
  • Number of questions: N/A
  • Pass score: 320 points out of 400 possible points *
  • Time limit: None
Categories - Maximum points

General Considerations - 80
Documentation - 50
Object-Oriented Design - 50
GUI - 70
Locking - 80
Language Fluency - 70

APIs relevant to the assignment
  • Thread handling and synchronization
  • Swing (and AWT to the extent necessary to support Swing)
  • Standard file IO (java.io, not java.nio)
  • Either: Socket-based network programming and serialization _or_ Java RMI (Java Remote Method Invocation) (your choice of one or the other, not both)
APIs and facilities may not be used:
  • Enterprise JavaBeans
  • Servlets, JSP technology, or any other web-oriented APIs
  • NIO, the New IO facilities
  • Java DataBase Connectivity (JDBC) and SQL
  • Java IDL API and CORBA
  • Third party software libraries or tools (such as browsers)
PART TWO:
  • Delivered at: Authorized Prometric testing centers
  • Prerequisites: Must be Sun Certified Programmer for the Java Platform (any edition) Completion of Step 1 (CX-310-252A)
  • Other exams/assignments required for this certification: Step 1 (CX-310-252A)
  • Exam type: Essay
  • Number of questions: 4
  • Pass score: Subject to the evaluation of the essay exam and validation of the
  • Time limit: 120 minutes

Monday, September 1, 2008

JavaScript: Ways to Hit Server Side using JavaScript

There are three ways to hit the server side application using JavaScript that may be some servlet/JSP/CGI Script. Following are the ways:

  1. Use AJAX to hit the Server Side. You can get the details on this from following post: http://www.codeproject.com/KB/ajax/SimpleAJAX.aspx
  2. Second way is to submit the form data using the JavaScript. Following sample JavaScript function will perform the required task. Make sure you place this function in your HEAD tag of HTML in a script tag.



function goForward() {
// alert ("Go Forward ..... ");
frm=document.forms[0];
frm.method="GET"; // POST

frm.action="ServerSidePage.jsp";//Some servlet/Some CGI Script/URL
frm.submit();
}

3. You can use the "document.location.href", and you can specify the server side path of any servlet/JSP/ CGI Script/ Other URL.

Example No:1
The following code segment will display an button on your page and when u will click on it, it will open the Google page.

"< i n p u t name="myButt" value="Call Server Side" onclick="document.location.href='http://www.google.com'" type="button" >

This example will look like this:


Example No:2

In this example, we select the an item from the drop down list and it will go to the page that you have specified in the value of selected option.

Place the following method in your HEAD section of HTML:

function callURL()
{
document.location.href= document.formName.SelectListID.options[document.formName.SelectListID.selectedIndex].value
}


Andplace the following code in body section of your HTML:

"
< f o r m name="formName">
< s e l e c t name="SelectListID" onchange="callURL();"> < o p t i o n value="http://www.sabahmyrsh.blogspost.com" select e d="selected">select an item from List:< o p t i o n value="http://www.alislam.org">AlIslam

Friday, August 22, 2008

Javascript function similar to Sleep of JAVA

Here is a Javascript function that works similar to the Thread.sleep(milliseconds) method of JAVA.

The code of the JavaScript function is as under:

function pause(numberMillis)
{
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true)
{
now = new Date();
if (now.getTime() > exitTime)
return;
}
}

You need to call this function like
pause(1000) ;
to wait a second!

Monday, August 18, 2008

JavaScript: Print Button on Your Web Page

It is fairly simple to add a PRINT Button on your web pages using JavaScript. The best practise to provide the facility of printing on web page is to provide a page that does not contain the banners/headers/footers/menus etc.
For this just create another web page containing only the data you actually need to print; For this make sure the background is not dark or does not contains the darked background image. etc

You can use simple JavaScript built in method window.print(). For example the following code segment will place a print link on your webpage using the img tag of HTML.

< i m g onclick="window.print();" src="/images/PrinterIcon.gif"
style="cursor:hand;" />

(Replace the text /images/PrinterIcon.gif with the location of an icon in your site.)

Wednesday, August 13, 2008

JAVA: Method That Removes Specified Characters From String

I needed a method that can remove specified set of characters from a given string. I came up with this solution. This method takes two parameters.

1. First parameter is original String from which you want to remove the characters.
2. Second parameter is a string containing the characters that we want to remove from the original string.

EXAMPLE:

If we provide the following input:

removeFromString("MYRSH Blogs by Sabah u Din Irfan","asi");

The method will return the followin output:

MYRSH Blog by Sbh u Dn Irfn
///////////////////////////////////////////


public static String removeFromString(String str,String rem)
{
StringBuffer result=new StringBuffer();

char[] s = str.toCharArray();
char [] r = rem.toCharArray();

boolean [] flags =new boolean[128];

int len=str.length();
int src, dest;

for(src = 0 ; src < r.length; ++src )
{
//System.out.println("src="+src);
flags[r[src]]=true;
}

src = 0 ; dest = 0 ;
while(src < len)
{
if( !flags[(int)s[src]] )
{
result.append(s[src]);
}
++src;
}
return result.toString();
}

Friday, August 8, 2008

JSP: Save As Pop Up in JSP Another way

Place the following code segment in your scriptlet tag of JSP page.

response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=abc.xls");
ServletOutputStream so = response.getOutputStream();
String filename = "c:\\reports\myreport.xls";
String mimetype = "application/vnd.ms-excel";
ByteArrayOutputStream output = new ByteArrayOutputStream();
InputStream in = new BufferedInputStream(new FileInputStream(filename));
byte bytebuff[] = new byte[500];
for(int lengthread = 0; (lengthread = in.read(bytebuff)) != -1;){
output.write(bytebuff, 0, lengthread);
}
byte data[] = output.toByteArray();
response.setContentType(mimetype);
so.write(data);
in.close();
so.close();


WHERE:


abc.xls
is the file name that will automatically appear in the file Name box of SaveAs Pop Up.

and

filename
is the actual file path on your server machine. It may be outside of your WEB-INF directory.

JSP: Save As Pop Up in JSP

Step First:

Add the following method in the declaration tag of your JSP page.

<%!

void returnFile(String filename, OutputStream out)throws Exception
{
// open file here using File object
File inputFile =new File(filename);
// open stream from that file
FileReader in = new FileReader(inputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);

// close the stream
in.close();
// close the file

}
%>

Step Two:

Add the following code segment in scriptlet tag.

response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=ASPTransBreakOut.txt");

// Send the file.
OutputStream outstr = response.getOutputStream( );
returnFile(fileLocation, outstr); // Method implemented in declarative tag in step first
outstr.flush();

WHERE:

ASPTransBreakOut.txt
is the name that will automatically show you up in SaveAs Popup menu

and

fileLocation

is the location of the actual fine on your server.

Wednesday, July 9, 2008

SQL Server: Lising all the Databses Names and Their Size

Following stored procedure lists all of the data bases names along with their sizes and remarks/

exec sp_databases

Column name Data type Description

DATABASE_NAME

sysname

Name of the database. In the Database Engine, this column represents the database name as stored in the sys.databases catalog view.

DATABASE_SIZE

int

Size of database, in kilobytes.

REMARKS

varchar(254)

For the Database Engine, this field always returns NULL.

Wednesday, April 16, 2008

ON LIVE PERSON

Ask an Expert - Visit my Virtual Office at LivePerson

DOS Command To Delete Those Files Having Attribute Other than A

If you want to delete the files that have their Attribute value equal to "-A"(Other than A), Use the following Command:

DEL /Q /A:-A *.*

Where:

/A is a switch that selects files to delete based on attributes

-A means that only those files that have attribute value other than A

/Q is a switch for Quiet mode, do not ask if ok to delete on global wildcard

and

*.* means all files.

For further details you can visit the following reference page.
http://www.computerhope.com/delhlp.htm




Ask an Expert - Visit my Virtual Office at LivePerson

Tuesday, April 8, 2008

JAvaScript function to Count no Of Specific Fields( Like TextBoxes)

Sometimes, you create textboxes or othe form fields dynamically using some server side scripting language. Then you may need to count the number of fields using some JAvaScript. The following javascript function will return the no of specific fields of a form passed in parameters:

It has two parameters:
1- formName:- It is the attribute name of the form
2- inputtype:- Type of Field as a String argument.

For Example if you would like to count the number of textBoxes in the HTML form, the following call will work.

var noOfTextBoxes = countElement(formName,"text");

Similarly, to count no of buttons in HTML form, call the function like:

var noOfTextBoxes = countElement(formName,"button");


Here is the implementation of JavaScript function:

function countElement(formName,inputtype)
{
var count =0;
for(i=0; i < formName.elements.length ; i++ )
{
if(formName.elements[i].type==inputtype)
{
//
alert(formName.elements[i].value);
count=count+1;

}
}
return count;
}







View Sabah u Din Irfan's profile on LinkedIn

Monday, April 7, 2008

JAVA@ Removing Duplicate Records from ArrayList

The following code removes the duplicate records from the ArrayList of Java.

//////////////////////////////////////

import java.util.ArrayList;

public class RemoveDuplicateArrayElement {
public static void main(String [] as)
{
// String [] temp={"sqqa","as","sa","sd","sa","fd","sa","sa","sa"};
ArrayList aryDuplicate=new ArrayList();

aryDuplicate.add(new String("sabah"));
aryDuplicate.add(new String("irfan"));
aryDuplicate.add(new String("waqas"));
aryDuplicate.add(new String("sabah"));
aryDuplicate.add(new String("sabah"));
aryDuplicate.add(new String("Ahmad"));
// for(int i=0;i
// {
// if(listContains(aryL,temp[i]))
// {
// // This is already in the List, Don't push it.
// //System.out.println("List already contains"+temp[i]);
// }
// else
// {
// aryL.add(new String(temp[i]));
// }
// }
// aryDuplicate1=aryDuplicate;//
//
// for(int j=0;j
// {
// //System.out.println(j+":"+(String)aryDuplicate1.get(j));
// }

aryDuplicate=RemoveDuplicates(aryDuplicate);
System.out.println(aryDuplicate.size());
for(int j=0;j
{
System.out.println(j+":"+(String)aryDuplicate.get(j));
}
//System.out.println("List contains = "+listContains(aryL,"sfa") );
}
/////////////////////////////////////

public static ArrayList RemoveDuplicates(ArrayList aryLst)
{
ArrayList noDuplicate=new ArrayList();
for(int i=0;i
{

if(listContains(noDuplicate,(String)aryLst.get(i)))
{
//This is already in the List, Don't push it.
// System.out.println((String)aryLst.get(i));
}
else
{
noDuplicate.add(new String((String)aryLst.get(i)));

}
}

return noDuplicate;
}
/////////////////////////
public static boolean listContains(ArrayList aryList, String str)
{
boolean result=false;

for(int i=0;i
{
// System.out.println((String)aryList.get(i));
if(str.equalsIgnoreCase((String)aryList.get(i)))
{
result= true;
break;
}
else
{
result= false;
}

}

return result;
}
///////////////////////////////////

public static boolean listContains(String[] aryList, String str)
{
boolean result=false;

for(int i=0;i
{
// System.out.println((String)aryList.get(i));
if(str.equalsIgnoreCase((String)aryList[i]))
{
result= true;
break;
}
else
{
result= false;
}

}

return result;
}


} // end class

Friday, March 14, 2008

JAVAScript: Function To Validate UK ZipCodes

// Method that validates the Basic Business Rules for UK Zip codes.

function checkPostCode(pc) { //check postcode format is valid
var test = pc;
var size = test.length
test = test.toUpperCase(); //Change to uppercase
while (test.slice(0,1) == " ") { //Strip leading spaces
test = test.substr(1,size-1);size = test.length
}
while(test.slice(size-1,size) == " ") { //Strip trailing spaces
test = test.substr(0,size-1);size = test.length
}
if (size == 0) {
return "please enter a valid postcode";
}
//document.details.pcode.value = test; //write back to form field
if (size <> 8){ //Code length rule
//return "please enter a valid postcode";
return test + " is not a valid postcode - wrong length";
}
if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
//return "please enter a valid postcode";
return test + " is not a valid postcode - cannot start with a number";
}
if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
// return "please enter a valid postcode";
return test + " is not a valid postcode - alpha character in wrong position";

}
if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
//return "please enter a valid postcode";
return test + " is not a valid postcode - number in wrong position";
}
if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
//return "please enter a valid postcode";
return test + " is not a valid postcode - number in wrong position";
}
if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
//return "please enter a valid postcode";
return test + " is not a valid postcode - space in wrong position";

}
count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
if (count1 != count2){//only one space rule
return "please enter a valid postcode";
return test + " is not a valid postcode - only one space allowed";
}
return "OK";
}

Wednesday, March 12, 2008

JAVAScript: StringTokenizer Function

String.prototype.tokenize = tokenize;

function tokenize()
{
var input = "";
var separator = " ";
var trim = "";
var ignoreEmptyTokens = true;

try {
String(this.toLowerCase());
}
catch(e) {
window.alert("Tokenizer Usage: string myTokens[] = myString.tokenize(string separator, string trim, boolean ignoreEmptyTokens);");
return;
}

if(typeof(this) != "undefined")
{
input = String(this);
}

if(typeof(tokenize.arguments[0]) != "undefined")
{
separator = String(tokenize.arguments[0]);
}

if(typeof(tokenize.arguments[1]) != "undefined")
{
trim = String(tokenize.arguments[1]);
}

if(typeof(tokenize.arguments[2]) != "undefined")
{
if(!tokenize.arguments[2])
ignoreEmptyTokens = false;
}

var array = input.split(separator);

if(trim)
for(var i=0; i
{
while(array[i].slice(0, trim.length) == trim)
array[i] = array[i].slice(trim.length);
while(array[i].slice(array[i].length-trim.length) == trim)
array[i] = array[i].slice(0, array[i].length-trim.length);
}

var token = new Array();
if(ignoreEmptyTokens)
{
for(var i=0; i
if(array[i] != "")
token.push(array[i]);
}
else
{
token = array;
}

return token;
}
/////////////////////////////////

Thursday, January 31, 2008