Tuesday, June 19, 2007

Add Java Exception breakpoint in Eclipse

1. Switch to debug perspective
2. Run
3. Java Exception breakpoint

Thursday, June 14, 2007

Java and Final

final is one of the most under-used features of Java. Whenever you compute a value and you know it will never be changed subsequently put a final on it. Why?
final lets other programmers (or you reviewing your code years later) know they don't have to worry about the value being changed anywhere else.
final won't let you or someone else inadvertently change the value somewhere else in the code, often by setting it to null. final helps prevent or flush out bugs. You can always remove it later.
final helps the compiler generate faster code.

Thursday, June 07, 2007

Arbeitsstation per Mausklick sperren

Um Ihre Arbeitsstation mit einem Mausklick zu sperren, erstellen Sie eine neue Verknüpfung, und geben Sie im Textfeld "Speicherort des Elements" folgenden Befehl ein:

rundll32.exe user32.dll,LockWorkStation

Wednesday, June 06, 2007

Check wether a String is a number

private boolean isNumber(String s) {
 for (int j = 0;j < s.length();j++) {
  if (!Character.isDigit(s.charAt(j))) {
   return false;
  }
 }
 return true;
}

Singleton pattern in Java

What is the Singleton Pattern, and when is it used?
The singleton design pattern is used when only one instance of an object is needed throughout the lifetime of an application. The singleton class is instantiated at the time of first access and the same instance is used thereafter till the application quits. To ensure that the user can create only one instance of this class, the following things have to be taken care of.

1. Make sure the user cannot explicitly create an instance of this object.
2. Provide access to this object from all areas of the application so that the need to create another instance never arises.

Uses:
The Singleton class can be used in various places where one would need a common repository of information that can be accessed from all objects in an application. A common example could be Preferences for the user. The preferences can be loaded from a file into memory into a singleton class which all objects in the application can then access to get preferences information.

See also: http://www.javareference.com/jrexamples/viewexample.jsp?id=25

Example:

public class Singleton{

private Singleton(){}

private static Singleton instance;

public static Singleton getInstance(){
if (instance == null)
instance = new Singleton();
return instance;
}