Selection sort C C++ source code

Selection sort C C++ source code
//selection sort
#include <iostream.h>
void selectionSort(int *array,int length)//selection sort function 
{
    int i,j,min,minat;
    for(i=0;i<(length-1);i++)
    {
        minat=i;
        min=array[i];

      for(j=i+1;j<(length);j++) //select the min of the rest of array
      {
          if(min>array[j])   //ascending order for descending reverse
          {
              minat=j;  //the position of the min element 
              min=array[j];
          }
      }
      int temp=array[i] ;
      array[i]=array[minat];  //swap 
      array[minat]=temp;      
    }
}

void printElements(int *array,int length) //print array elements
{
    int i=0;
    for(i=0;i<10;i++)
        cout<<array[i]<<endl;
}
void main()
{

    int a[]={9,6,5,23,2,6,2,7,1,8};   // array to sort 
    selectionSort(a,10);                 //call to selection sort  
    printElements(a,10);               // print elements 
}

Java iterate through map, hashmap - working source code

Iterating through Map in Java - working efficient source code 

Map<String, Object> map = ...;

The solution uses map.keySet(), map.values(), and map.entrySet().

Text Prompted Remote Speaker Authentication : Joint Speech and Speaker Recognition/Verification System :: Major Project ::: Introduction

Biometrics is, in the simplest definition, something you are. It is a physical characteristic unique to each individual such as fingerprint, retina, iris, speech. Biometrics has a very useful application in security; it can be used to authenticate a person’s identity and control access to a restricted area, based on the premise that the set of these physical characteristics can be used to uniquely identify individuals.

Speech signal conveys two important types of information, the primarily the speech content and on the secondary level, the speaker identity. Speech recognizers aim to extract the lexical information from the speech signal independently of the speaker by reducing the inter-speaker variability. On the other hand, speaker recognition is concerned with extracting the identity of the person speaking the utterance. So both speech recognition and speaker recognition system is possible from same voice input.

Desired Output of the Combined System
Text Prompted Remote Speaker Authentication is a voice biometric system that authenticates a user before permitting the user to log into a system on the basis of the user’s input voice. It is a web application. Voice signal acquisition and feature extraction is done on the client. Training and Authentication task based on the voice feature obtained from client side is done on Server. The authentication task is based on text-prompted version of speaker recognition, which incorporates both speaker recognition and speech recognition. This joint implementation of speech and speaker recognition includes text-independent speaker recognition and speaker-independent speech recognition. Speaker Recognition verifies whether the speaker is claimed one or not while Speech Recognition verifies whether or not spoken word matches the prompted word.

java calculate method run time


long startTime = System.currentTimeMillis();

doReallyLongThing(); // call your method here
long endTime = System.currentTimeMillis();
// calculate the difference - that the method just took to executeSystem.out.println("That took " + (endTime - startTime) + " milliseconds");

SQL basics- complete reference guide - part8 SQL System Commands

Part8: SQL System Commands Reference guide

TOPICTEXTSYNTAXExample
ARRAY_GETReturns one element of an array.ARRAY_GET(arrayExpression, indexExpression)
ARRAY_LENGTHReturns the length of an array.ARRAY_GET(arrayExpression)
AUTOCOMMITReturns true if auto commit is switched on for this session.AUTOCOMMIT()
CANCEL_SESSIONCancels the currently executing statement of another session.CANCEL_SESSION(sessionInt)
CASEWHEN FunctionReturns 'a' if the boolean expression is true, otherwise 'b'.CASEWHEN(boolean, aValue, bValue)
CASTConverts a value to another data type.CAST(value AS dataType)
COALESCEReturns the first value that is not null.COALESCE(aValue, bValue [,...])
CONVERTConverts a value to another data type.CONVERT(value, dataType)
CURRVALReturns the current (last) value of the sequence, independent of the session.CURRVAL( [ schemaName, ] sequenceString )
CSVREADReturns the result set of reading the CSV (comma separated values) file.CSVREAD(fileNameString [, columnsString [, csvOptions ] ] )
CSVWRITEWrites a CSV (comma separated values).CSVWRITE ( fileNameString, queryString [, csvOptions [, lineSepString] ] )
DATABASEReturns the name of the database.DATABASE()
DATABASE_PATHReturns the directory of the database files and the database name, if it is file
based.
DATABASE_PATH()
FILE_READReturns the contents of a file.FILE_READ(fileNameString [,encodingString])
GREATESTReturns the largest value that is not NULL, or NULL if all values are NULL.GREATEST(aValue, bValue [,...])
IDENTITYReturns the last inserted identity value for this session.IDENTITY()
IFNULLReturns the value of 'a' if it is not null, otherwise 'b'.IFNULL(aValue, bValue)
LEASTReturns the smallest value that is not NULL, or NULL if all values are NULL.LEAST(aValue, bValue [,...])
LOCK_MODEReturns the current lock mode.LOCK_MODE()
LOCK_TIMEOUTReturns the lock timeout of the current session (in milliseconds).LOCK_TIMEOUT()
LINK_SCHEMACreates table links for all tables in a schema.LINK_SCHEMA(targetSchemaString, driverString, urlString,
userString, passwordString, sourceSchemaString)
MEMORY_FREEReturns the free memory in KB (where 1024 bytes is a KB).MEMORY_FREE()
MEMORY_USEDReturns the used memory in KB (where 1024 bytes is a KB).MEMORY_USED()
NEXTVALReturns the next value of the sequence.NEXTVAL ( [ schemaName, ] sequenceString )
NULLIFReturns NULL if 'a' is equals to 'b', otherwise 'a'.NULLIF(aValue, bValue)
READONLYReturns true if the database is read-only.READONLY()
ROWNUMReturns the number of the current row.ROWNUM()
SCHEMAReturns the name of the default  schema for this session.SCHEMA()
SCOPE_IDENTITYReturns the last inserted identity value for this session for the current scope.SCOPE_IDENTITY()
SESSION_IDReturns the unique session id number for the current database connection.SESSION_ID()
SETUpdates a variable with the given value.SET(@variableName, value)
TABLEReturns the result set.{ TABLE | TABLE_DISTINCT } ( { name dataType = expression } [,...] )
TRANSACTION_IDReturns the current transaction id for this session.TRANSACTION_ID()
USERReturns the name of the current user of this session.{ USER | CURRENT_USER } ()Select User();

SQL basics- complete reference guide - part7 - Date Time Functions

Part7: SQL Date Time Functions Reference

TOPICTEXTSYNTAXExample
CURRENT_DATEReturns the current date.{ CURRENT_DATE [ () ] | CURDATE() | SYSDATE | TODAY }
CURRENT_TIMEReturns the current time.{ CURRENT_TIME [ () ] | CURTIME() }
CURRENT_TIMESTAMPReturns the current timestamp.{ CURRENT_TIMESTAMP [ ( [ int ] ) ] | NOW( [ int ] ) }
DATEADDAdds units to a timestamp.DATEADD(unitString, addInt, timestamp)
DATEDIFFReturns the the number of crossed unit boundaries between two timestamps.{ DATEDIFF | TIMESTAMPDIFF } (unitString, aTimestamp, bTimestamp)
DAYNAMEReturns the name of the day (in English).DAYNAME(date)
DAY_OF_MONTHReturns the day of the month (1-31).DAY_OF_MONTH(date)
DAY_OF_WEEKReturns the day of the week (1 means Sunday).DAY_OF_WEEK(date)
DAY_OF_YEARReturns the day of the year (1-366).DAY_OF_YEAR(date)
EXTRACTReturns a specific value from a timestamps.EXTRACT ( { YEAR | YY | MONTH | MM | DAY | DD | DAY_OF_YEAR
    | DOY | HOUR | HH | MINUTE | MI | SECOND | SS | MILLISECOND | MS }
    FROM timestamp )
FORMATDATETIMEFormats a date, time or timestamp as a string.FORMATDATETIME ( timestamp, formatString
[ , localeString [ , timeZoneString ] ] )
HOURReturns the hour (0-23) from a timestamp.HOUR(timestamp)
MINUTEReturns the minute (0-59) from a timestamp.MINUTE(timestamp)
MONTHReturns the month (1-12) from a timestamp.MONTH(timestamp)
MONTHNAMEReturns the name of the month (in English).MONTHNAME(date)
PARSEDATETIMEParses a string and returns a timestamp.PARSEDATETIME(string, formatString
[, localeString [, timeZoneString]])
QUARTERReturns the quarter (1-4) from a timestamp.QUARTER(timestamp)
SECONDReturns the second (0-59) from a timestamp.SECOND(timestamp)
WEEKReturns the week (1-53) from a timestamp.WEEK(timestamp)
YEARReturns the year from a timestamp.YEAR(timestamp)

Java Capture/save image from swing Component eg : JFrame JPanel ..

Capture image from any swing Component and save to file.
Capture  :
BufferedImage image = new BufferedImage(component.getWidth(),
                                     component.getHeight(), BufferedImage.TYPE_INT_RGB);
// paints into image's Graphics
component.paint(image.getGraphics());
Save Image :

SQL basics- complete reference guide - part6 - String functions

Part6: SQL String Functions Complete Reference

TOPICTEXTSYNTAXExample
ASCIIReturns the ASCII value of the first character in the string.ASCII(string)
BIT_LENGTHReturns the number of bits in a string.BIT_LENGTH(string)
LENGTHReturns the number of characters in a string.{ LENGTH | CHAR_LENGTH | CHARACTER_LENGTH } ( string )
OCTET_LENGTHReturns the number of bytes in a string.OCTET_LENGTH(string)
CHARReturns the character that represents the ASCII value.{ CHAR | CHR } ( int )
CONCATCombines strings.CONCAT(string, string [,...])
DIFFERENCEReturns the difference between the sounds of two strings.DIFFERENCE(string, string)
HEXTORAWConverts a hex representation of a string to a string.HEXTORAW(string)
RAWTOHEXConverts a string to the hex representation.RAWTOHEX(string)
INSTRReturns the location of a search string in a string.INSTR(string, searchString, [, startInt])
INSERT FunctionInserts a additional string into the original string at a specified start position.INSERT(originalString, startInt, lengthInt, addString)
LOWERConverts a string to lowercase.{ LOWER | LCASE } ( string )
UPPERConverts a string to uppercase.{ UPPER | UCASE } ( string )
LEFTReturns the leftmost number of characters.LEFT(string, int)
RIGHTReturns the rightmost number of characters.RIGHT(string, int)
LOCATEReturns the location of a search string in a string.LOCATE(searchString, string [, startInt])
POSITIONReturns the location of a search string in a string.POSITION(searchString, string)
LPADLeft pad the string to the specified length.LPAD(string, int[, paddingString])
RPADRight pad the string to the specified length.RPAD(string, int[, paddingString])
LTRIMRemoves all leading spaces from a string.LTRIM(string)
RTRIMRemoves all trailing spaces from a string.RTRIM(string)
TRIMRemoves all leading spaces, trailing spaces, or spaces at both ends, from a string.TRIM ( [ { LEADING | TRAILING | BOTH } [ string ] FROM ] string )
REGEXP_REPLACEReplaces each substring that matches a regular expression.REGEXP_REPLACE(inputString, regexString, replacementString)
REPEATReturns a string repeated some number of times.REPEAT(string, int)
REPLACEReplaces all occurrences of a search string in a text with another string.REPLACE(string, searchString [, replacementString])
SOUNDEXReturns a four character code representing the sound of a string.SOUNDEX(string)
SPACEReturns a string consisting of a number of spaces.SPACE(int)
STRINGDECODEConverts a encoded string using the Java string literal encoding format.STRINGDECODE(string)
STRINGENCODEEncodes special characters in a string using the Java string literal encoding format.STRINGENCODE(string)
STRINGTOUTF8Encodes a string to a byte array using the UTF8 encoding format.STRINGTOUTF8(string)
SUBSTRINGReturns a substring of a string starting at a position.{ SUBSTRING | SUBSTR } ( string, startInt [, lengthInt ] )
UTF8TOSTRINGDecodes a byte array in the UTF8 format to a string.UTF8TOSTRING(bytes)
XMLATTRCreates an XML attribute element of the form "name=value".XMLATTR(nameString, valueString)
XMLNODECreate an XML node element.XMLNODE(elementString [, attributesString [, contentString]])
XMLCOMMENTCreates an XML comment.XMLCOMMENT(commentString)
XMLCDATACreates an XML CDATA element.XMLCDATA(valueString)
XMLSTARTDOCThe string "XMLSTARTDOC()
XMLTEXTCreates an XML text element.XMLTEXT(valueString)

java pad string left right - String.format() method


String.format() can be used to left/right pad a given string.
public static String padRight(String s, int n) {
     return String.format("%1$-" + n + "s", s);  }
public static String padLeft(String s, int n) {
    return String.format("%1$#" + n + "s", s);  }
...
public static void main(String args[]) throws Exception {
 System.out.println(padRight("Howto", 20) + "*");
 System.out.println(padLeft("Howto", 25) + "*");
}

Top Java Interview Question : reverse a string using recursion

Best Answer using Recursion :

  public String reverse(String str) {
     if ((null == str) || (str.length()  <= 1)) {
        return str;
      }
    return reverse(str.substring(1)) + str.charAt(0);
   }


Less Best Answer :
public class JdkReverser implements Reverser {
  public String reverse(String str) {
     if ((null == str) || (str.length() <= 1)) {
         return str;
      }
     return new StringBuffer(str).reverse().toString();
  }
}