Native JDBC Java Programming Steps Sunday, Oct 8 2006 

  1. Class.forName(“com.mysql.jdbc.Driver”);
  2. Connection con = DriverManager.getConnection( “jdbc:mysql://localhost/nepatalk”, “root”, “password”);
  3. Statement st = con.createStatement();
  4. ResultSet rs = st.executeQuery(“SELECT …sql query”);
    if (rs.next())
    System.out.println(“ok”);
  5. st.close();
    con.close();

Singleton in Java Sunday, Oct 8 2006 

A singleton is a class that can be instantiated once and only once. But, why do you need them? If you are creating a class for a set up configuration and use the old fashioned class constrution, you may end up creating numerous configuration objects while you need only one copy. This singleton design pattern comes handy in this situation. You should also use Singleton when creating RMI lookup and creating JDBC connection.

How to create Singleton object?
1. Block off accessing to all constructors by making access modifier of default construtor as private.
2. Provide static method for getting an instance of the singleton.
3. Prevent cloning (usually developers forget to do; as every object inherits clone() method)

Implementation:
public class SingletonObject {

  private static SingletonObject ref;

  private SingletonObject() {
  }

  public static SingletonObject getSingletonObject() {
    if (ref == null)
      ref = new SingletonObject();
    return ref;
  }

  public Object clone() throws CloneNotSupportedException {
    throw new CloneNotSupportedException();
  }

}

Reference: http://www.javacoffeebreak.com/articles/designpatterns/index.html

Study Guide for SCJP 5.0 (Tiger) Certification Friday, Sep 15 2006 

http://java.boot.by/scjp-tiger/index.html

Precedence and Associativity Rules for Operators Wednesday, Mar 29 2006 

Precedence and associativity rules are necessary for deterministic evaluation of expressions. The operators, together with their precedence and associativity are summarized below.

The following remarks apply to below list:

  • The operators are shown with decreasing precedence from the top of the list
  • Operators within the same row have the same precedence.
  • Parentheses, (), can be used to override precedence and associativity.
  • The unary postfix operators and all binary operators, except for the assignment operators, associate from left to right.
  • All urary operators (except for unary postfix operators), all assignment operators, and the ternary conditional operator (including object creation and cast) associate from right to left.

Postfix Operators [], . (para), exp++, exp–

Prefix Unary Operators ++exp, –exp, +exp, -exp, ~, !

Object creation & cast new (type)

Multiplication *, /, %

Addition +, –

Shift <<, >>, >>>

Relational Operators <, <= ,>, >=, instanceof

Equality Operators ==, !=

bitwise/boolean AND &

bitwise/boolean XOR ^

bitwise/boolean OR |

logical AND &&

logical OR ||

Conditional Operator ?:

Assignment =, +=, -=, *=. /=, %=, <<=, >>=, >>>=, &=, ^=, |=