Tuesday, June 01, 2010

Whats new in JDK 7

Below are some new features in JDK 7


  • NIO 2.0 The java.nio.file package and its related package, java.nio.file.attribute, provide comprehensive support for file I/O and for accessing the file system.
  • Sockets Direct Protocol Sockets Direct Protocol (SDP) is a wire protocol developed to support stream connections over InfiniBand fabric.
  • Compressed 64-bit object pointers. A technique for compressing 64-bit pointers to fit into 32 bits, which decreases memory and memory-bandwidth consumption and thereby improves performance
  • VM support for non-Java languages. VM extensions to support the implementation of non-Java languages at performance levels near to that of the Java language itself.
  • Garbage-First GC. A new garbage collector that promises to achieve lower pause times and better predictability than the current CMS collector

Labels: ,

Tuesday, November 24, 2009

Using regular expressions in Java

Below is an example of using Java's regular expression functionality to replace the spaces inside of a parenthesis with a underscore:

String inputStr = "1 (2 3) 4 (5 6) 7 8 9";
String thePatternStr = "\\([\\w\\d\\s]*\\)";
Pattern pattern = Pattern.compile(thePatternStr);
Matcher matcher = pattern.matcher(inputStr);
StringBuffer sb = new StringBuffer();
while(matcher.find())
{
String match = matcher.group();
String matchWithUnderscore = match.replace(' ', '_');
matcher.appendReplacement(sb, matchWithUnderscore);
}
matcher.appendTail(sb);
System.out.println("Input string: " + inputStr);
System.out.println("Modified string: " + sb.toString());

This should give the following output:

Input string: 1 (2 3) 4 (5 6) 7 8 9
Modified string: 1 (2_3) 4 (5_6) 7 8 9

Labels:

Using regular expressions in Java

Below is an example of using Java's regular expression functionality to replace the spaces inside of a parenthesis with a underscore:

String inputStr = "1 (2 3) 4 (5 6) 7 8 9";
String thePatternStr = "\\([\\w\\d\\s]*\\)";
Pattern pattern = Pattern.compile(thePatternStr);
Matcher matcher = pattern.matcher(inputStr);
StringBuffer sb = new StringBuffer();
while(matcher.find())
{
String match = matcher.group();
String matchWithUnderscore = match.replace(' ', '_');
matcher.appendReplacement(sb, matchWithUnderscore);
}
matcher.appendTail(sb);
System.out.println("Input string: " + inputStr);
System.out.println("Modified string: " + sb.toString());

This should give the following output:

Input string: 1 (2 3) 4 (5 6) 7 8 9
Modified string: 1 (2_3) 4 (5_6) 7 8 9

Labels: ,

Thursday, May 08, 2008

Determine files that are modified

find . -mtime -1 -print

Labels:

Wednesday, September 19, 2007

Using Awk to rename multiple files

The following awk script will rename files named like:

_TEST.ABC.123.XML.1231123

to the following

TEST.ABC.123.XML


for f in `ls _TEST*`
do
newfile=`echo $f | grep -o TEST.[A-Z]*.[0-9]*.XML`
mv $f $newfile
done

Labels:

Monday, August 20, 2007

Utility for determining which files a program is using

The Process Explorer for Windows is a utility for determining which files an application is currently using. This can come in handy especially when you are trying to delete a file but cannot because some process is still using it. I highly recommend it. Below is the URL:


http://www.microsoft.com/technet/sysinternals/Utilities/ProcessExplorer.mspx

Friday, August 17, 2007

JVM parameters to use a debugger for Java

Below are the JVM arguements that can be used to allow a debugger to connect to your Java application

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=port

Labels:

Monday, October 23, 2006

Drop all tables for Microsoft SQL Server

Resource: John's Blog

WHILE EXISTS(SELECT [name] FROM sys.tables WHERE [type] = 'U')
BEGIN
DECLARE @table_name varchar(50)
DECLARE table_cursor CURSOR FOR SELECT [name] FROM sys.tables WHERE [type] = 'U'
OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @table_name
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
EXEC ('DROP TABLE [' + @table_name + ']')
PRINT 'Dropped Table ' + @table_name
END TRY
BEGIN CATCH END CATCH
FETCH NEXT FROM table_cursor INTO @table_name
END
CLOSE table_cursor
DEALLOCATE table_cursor
END