Archive for April, 2004

MySQL Connector for JDBC

When you want to use MySQL with JDBC, you will need to download mysql-connector-java-3.0.11-stable-bin.jar when developing servlets and JSP and install it in WEB-INF/lib.

And that mysql-connector-java-3.0.11 is JDBC type 4 driver so it’s sort of guranteed to perform really well.

When you use JDBC DriverManager, use “com.mysql.jdbc.Driver” as the class that implements java.sql.Driver.

Class.forName(“com.mysql.jdbc.Driver”).newInstance();

And here is the precedure for using Database with Java

1. Load a JDBC Database Driver
2. Create a Connection
3. Create a Statement
4. Create a ResultSet

Java Documentation Comments

When documenting in Java, there are certain rules that you wanna follow since that will leave you a form of HTML documentation of what you just wrote down. The first rule is as following:

1. Documentation comment begins with /** and ends with */

2. @author tag for author of the code

3. @deprecated tag for library classes and methods to indicate that they have been superseded and generally should not be used in new applications.

4. @exception tag for exceptions

5. {@link} tag for generating a link to another part of documentation

6. @param tag for parameters for a method

7. @return tag for the value returned from a method

8. @see tag for cross references (another class/method/ or URL)

9. @throws tag for a synonym for @exception

10. @version tag for current version of the code

With propery documentation, you can use javadoc to generate your own library documentation in html format.

I wish there was one for ActionScript 2. I know there is a commercial version of ASdoc; however, Macromedia should have come up with one too when they released flash mx 2004. How shameful they are!

characteristics of StringBuffer

Here is the characteristics of StringBuffer class in Java.

  • String buffers are safe for use by multiple threads.
  • Unlike String object, append method doesn’t create an additional String object so String buffers object can save memory.

Because of the second characteristic mentioned right above, when dealing with lots of characters, StringBuffer will come in handy instead of String.

Standard writing java program

I always seem interested in standard java program writing called “Code Convention”. It’s because that makes all developers communicate better by looking at the convention and understand it easily.

http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

That link’s providing official code convention for Java Programming Laungage and I’m pretty sure that will help you organize your code in a right way.

Multi-Threaded Servlet

When you serve servlet, you would end up having to make your own servlet multi-threaded. How? Simply implement SingleThreadModel to your class.

What that does is that it will let first request from a user finish and the seond request wait for the first to finish. How cool is that! However, note that this interface is there when you need to access to external resources such as a text file.

precedure of servlet & best practice

Sometimes you would need to summarize knowledge that you’ve leant in order to organize it in your brain. That’s why it’s a good idea to write it down so that you know that you organized knowledge you earned.

Anyways, lately I’ve been studying JavaServlet and have to because web content management system has been implemented in my client’s company and this giant web content management called “Documentum” utilizes most technologies given ever such as .Net and Java. I’ve decided to use Java Servlet and JSP to learn some business logic aspect in development.

In servlet class the precedure is as following:
1. Once servlet class is instantiated init method is called and its signature is as following:

public void init(ServletConfig config) throws ServletException

2. After servlet’s init method, service method is called by the servlet container. It has following signature:

public void service(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException

And then the best practice to deploy dynamic web pages seems to be Servlet-Beans-JSP combination.

I can set up servlet to do the database work and put the results into beans. And the JSP gets the beans from the servlet and displays it as HTML. How does it sound like? I just got to know about it today.

So many things to learn in java… sigh :^@