public class ChessGUI extends JFrame {
private Board board;
private ChessGUI() {
board = new Board();
setLayout(new FlowLayout());
add(board);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
pack();
}
Drawing Chess Game Board in Java - Source Code
Source code for Chess Game Board in Java :
java read content of web page
The following example use easier method to read String from InputStream in Java. It uses java.util.Scanner. It will be easy/efficient to read shorter content by using this method.
Reading content of web URL:
Reading content of web URL:
System.out.println("Google\n" + new Scanner(new URL("http://google.com").openStream())
.useDelimiter("\\A").next());
Reading a text file :System.out.println("TextFile\n"+new Scanner(new File("inputFile.txt"))
.useDelimiter("\\A").next());
The regex "\\A" here matches the beginning of input source. Scanner can work not only with an InputStream source, but with anything that implements the new (JDK version >= 1.5) java.lang.Readable interface.Deploying .war file to Apache Tomcat Server : Working way
Here i am going to describe the [MANUAL]working way to deploy your .war(web application archive) file to the Apache Tomcat Server.
Suppose you have your web application's war file ,say MyProject.war exported from Eclipse Netbeans or similar IDE.
Steps:
1.Copy this .war file to webapps folder TOMCAT_HOME directory e.g, C:\apache-tomcat\webapps\
2.Restart the server, >> run the startup.bat in folder C:\apache-tomcat\bin
3.If the error message such as
JAVA_HOME not defined or CATALINA_HOME not defined
Then follow these steps to setup these environment variables:
5.If everything is ok, the Home page of your app will be loaded into browser
6.Enjoy :)
Suppose you have your web application's war file ,say MyProject.war exported from Eclipse Netbeans or similar IDE.
Steps:
1.Copy this .war file to webapps folder TOMCAT_HOME directory e.g, C:\apache-tomcat\webapps\
2.Restart the server, >> run the startup.bat in folder C:\apache-tomcat\bin
3.If the error message such as
JAVA_HOME not defined or CATALINA_HOME not defined
Then follow these steps to setup these environment variables:
- Right-click the My Computer icon on your desktop and select 'Properties'.
- Click the 'Advanced' tab (Windows XP), click on Advance System Settings on Windows7.
- Click the 'Environment Variables' button.
- Under 'System Variables', click 'New'.
- Enter the variable name as JAVA_HOME.
- Enter the variable value as the installation path for the Java Development Kit. eg. C:\Program Files (x86)\Java\jdk1.6.0_20
- Repeat the process for CATALINA_HOME variable and enter installation path for Tomcat Server, eg. C:\apache-tomcat\webapps\
- Click 'OK'.
- Click 'Apply Changes'.
- Restart the Server >> run the startup.bat in folder C:\apache-tomcat\bin
5.If everything is ok, the Home page of your app will be loaded into browser
6.Enjoy :)
hibernate show sql & parameter to console
You need to configure it 2 places :
1) Configuration in log4j logger : add following lines in - log4j.properties file :
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
The first is equivalent to
hibernate.show_sql=true
, the second prints the bound parameters among other things.
2)Configuration in hibernate.cfg.xml :
<property name="show_sql">true</property>
TO Show Formatted SQL :<property name="format_sql">true</property>
java escape html string - code
1) StringEscapeUtils from Apache Commons Lang:
OR
2) Use Spring's
import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
// ...
String source = "The less than sign (<) and ampersand (&) must be escaped before using them in HTML";
String escaped = escapeHtml(source);
OR
2) Use Spring's
HtmlUtils.htmlEscape(String input)
method.
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
The solution uses map.keySet(), map.values(), and map.entrySet().
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.
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.
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 |
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
TOPIC | TEXT | SYNTAX | Example |
---|---|---|---|
ARRAY_GET | Returns one element of an array. | ARRAY_GET(arrayExpression, indexExpression) | |
ARRAY_LENGTH | Returns the length of an array. | ARRAY_GET(arrayExpression) | |
AUTOCOMMIT | Returns true if auto commit is switched on for this session. | AUTOCOMMIT() | |
CANCEL_SESSION | Cancels the currently executing statement of another session. | CANCEL_SESSION(sessionInt) | |
CASEWHEN Function | Returns 'a' if the boolean expression is true, otherwise 'b'. | CASEWHEN(boolean, aValue, bValue) | |
CAST | Converts a value to another data type. | CAST(value AS dataType) | |
COALESCE | Returns the first value that is not null. | COALESCE(aValue, bValue [,...]) | |
CONVERT | Converts a value to another data type. | CONVERT(value, dataType) | |
CURRVAL | Returns the current (last) value of the sequence, independent of the session. | CURRVAL( [ schemaName, ] sequenceString ) | |
CSVREAD | Returns the result set of reading the CSV (comma separated values) file. | CSVREAD(fileNameString [, columnsString [, csvOptions ] ] ) | |
CSVWRITE | Writes a CSV (comma separated values). | CSVWRITE ( fileNameString, queryString [, csvOptions [, lineSepString] ] ) | |
DATABASE | Returns the name of the database. | DATABASE() | |
DATABASE_PATH | Returns the directory of the database files and the database name, if it is file based. | DATABASE_PATH() | |
FILE_READ | Returns the contents of a file. | FILE_READ(fileNameString [,encodingString]) | |
GREATEST | Returns the largest value that is not NULL, or NULL if all values are NULL. | GREATEST(aValue, bValue [,...]) | |
IDENTITY | Returns the last inserted identity value for this session. | IDENTITY() | |
IFNULL | Returns the value of 'a' if it is not null, otherwise 'b'. | IFNULL(aValue, bValue) | |
LEAST | Returns the smallest value that is not NULL, or NULL if all values are NULL. | LEAST(aValue, bValue [,...]) | |
LOCK_MODE | Returns the current lock mode. | LOCK_MODE() | |
LOCK_TIMEOUT | Returns the lock timeout of the current session (in milliseconds). | LOCK_TIMEOUT() | |
LINK_SCHEMA | Creates table links for all tables in a schema. | LINK_SCHEMA(targetSchemaString, driverString, urlString, userString, passwordString, sourceSchemaString) | |
MEMORY_FREE | Returns the free memory in KB (where 1024 bytes is a KB). | MEMORY_FREE() | |
MEMORY_USED | Returns the used memory in KB (where 1024 bytes is a KB). | MEMORY_USED() | |
NEXTVAL | Returns the next value of the sequence. | NEXTVAL ( [ schemaName, ] sequenceString ) | |
NULLIF | Returns NULL if 'a' is equals to 'b', otherwise 'a'. | NULLIF(aValue, bValue) | |
READONLY | Returns true if the database is read-only. | READONLY() | |
ROWNUM | Returns the number of the current row. | ROWNUM() | |
SCHEMA | Returns the name of the default schema for this session. | SCHEMA() | |
SCOPE_IDENTITY | Returns the last inserted identity value for this session for the current scope. | SCOPE_IDENTITY() | |
SESSION_ID | Returns the unique session id number for the current database connection. | SESSION_ID() | |
SET | Updates a variable with the given value. | SET(@variableName, value) | |
TABLE | Returns the result set. | { TABLE | TABLE_DISTINCT } ( { name dataType = expression } [,...] ) | |
TRANSACTION_ID | Returns the current transaction id for this session. | TRANSACTION_ID() | |
USER | Returns the name of the current user of this session. | { USER | CURRENT_USER } () | Select User(); |
Subscribe to:
Posts
(
Atom
)