Quick Table of Contents

  1. Java
  2. Profilers
  3. JDBC
  4. Links
  5. System Properties
  6. JSR
  7. Patterns and Regular Expressions

Java

1. Java

Java is a powerful programming language that lets you write programs that run virtually anywhere!

2. Profilers

I've tried both YourKit and JProfiler. Both were sufficient for my needs and integrate well into IntelliJ.

YourKit costs $499 (389 EUR) for a single user license. Upgrades from previous versions are at a 50% discount.

JProfiler costs $499 (409 EUR). With 1 year support/upgrades is $698 (599 EUR). Further upgrades for a single license are $179 (159 EUR).

3. JDBC

MySQL

Troubleshooting

Address already in use: connect
          ** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.BindException: Address already in use: connect

STACKTRACE:

java.net.SocketException: java.net.BindException: Address already in use: connect
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2555)
	at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
          

It isn't saying that its trying to listen on a local socket, but can't create a socket. Check that an excessive amount of TCP sockets aren't already open using netstat.

5. System Properties

The JVM takes arguments on the command line -Dname=value

e.g. To specify the default timezone, java -Duser.timezone=GMT

To specify an endorsed directory, where jars will take precendence over the default JRE classes, use -Djava.endorsed.dirs

6. JSR

JSR 310: Date time calendar API

We're using Joda Time as a replacement date time API in our code.

7. Patterns and Regular Expressions

Non-Greedy matching

Add the '?' character to the expression to indicate a non-greedy search.

String greedy = "fish<br>cakes<i>penguin".replaceAll("<.*>","");
String nonGreedy = "fish<br>cakes<i>penguin".replaceAll("<.*?>","");
System.out.println("greedy: " + greedy);
System.out.println("nonGreedy: " + nonGreedy);
      

The above will output

greedy: fishpenguin
nonGreedy: fishcakespenguin
      

Group matching and back references

To use back references (i.e. referring to a portion of the pattern that was matched), create your pattern, and also add round brackets to surround the groups you are interested in.

An as example, consider the following program snippet:

Pattern compile = Pattern.compile("Your balance is (.*) dollars");
String message = "Your balance is 123 dollars";
Matcher matcher = compile.matcher(message);
if (matcher.matches()) {
    // matched
    String wholePattern = matcher.group(0);
    String group1 = matcher.group(1);
    System.out.println("wholePattern: " + wholePattern);
    System.out.println("group1: " + group1);
}

and output:

wholePattern: Your balance is 123 dollars
group1: 123

Note the round brackets that where used in the pattern. This is a group and that can be back referenced.

A matcher is created, and the 'matches' method is called to test whether a match was found.

If a match was found, you can call the 'group' method with '0' to see the whole match, and if you used round brackets or groups, you can refer to specific groups that were matched starting from '1'.

More Articles (showing 20 below)
2011-12-10
2011-05-07
2011-03-31
2011-03-06
2011-03-06
2010-11-13
2010-07-26
2010-06-13
2008-09-05
2007-01-20 2008-09-04
2007-01-14
2006-08-06
2005-11-02
2005-03-16
2004-09-21
2004-08-15
2004-08-11
2004-04-06
2004-04-06