Archive for the 'Java' Category

Java code for connecting MS SQL Server by using SQL Server Authentication

First of all, You will need to add a jar file to your project library as SQL Server 2000 Driver for JDBC Service. My target is SQL Server 2000, it will require the jar file called “sqljdbc4.jar”. This is not supported on Microsoft website now, you can download it here. For other versions of SQL Server, here is the link of SQL Server 2000 Driver for JDBC Service.

The following is the code for connection MS SQL Server and select some records from a testing table.

Continue »

Java Class Instance Initializers

public class Foo {
    public Foo() { System.out.println("constructor called"); }
 
    static { System.out.println("static initializer called"); }
 
    { System.out.println("instance initializer called"); }
}

What do you think this will output?

new Foo();
new Foo();

Before I got SCJP, I was quite surprised with this.

static initializer called
instance initializer called
constructor called
instance initializer called
constructor called

The correct way to deploy Java web project

I developed a Java Web Service project on my local box. It has been working fine with my testing. Now I need to deploy this project to a remote server, which will be assigned a static domain name for our department. I searched everywhere, and finally find the following ways to deploy a web project.

Continue »

Does SCWCD help in job?

I saw a lot of people asking this question. I don’t know exactly how much useful it is in job, but I can use my experience to let you get the idea.

Ever since I got SCJP and SCWCD, and put my resume on monster and yahoo hotjob, I got emails everyday about offering me a job and also get calls from time to time. Some of the consulting service directly tell me that they see I have SCWCD certificate.So you see the point, it brings you more opportunities.

Also it is a terrific way to learn Java Web development. It is true that some of the people who owe the certificate can not write even a very simple web app. So it can not prove that you are an expert of Web development, but it does show that you have a lot of knowledge in this area.

It is a great thing you should get if you have time.

Access ServletContext from within a JAX-WS Web Service

In a typical J2EE project, we put the application level initial parameter in context-param tag in web.xml, such as database configuration, administrator’s email address, etc.

The values within the element can be accessed like so:

String value = 
getServletContext().getInitParameter("name_of_context_initialization_parameter");

When dealing with Web Service, the same problem comes up.

Continue »

My little suggestions about SCWCD preparation

From the report, the Session Management is very hard for me. But we may have different background, so you may be good at that part. I read HFSJ three times, and spent more time on Custom Tag Library, and less time on all other topics. It turns out that Session Management and Standard Actions are the most difficult sections in my test.

My suggestion is reading HFSJ 3 times at least, and there is no need to buy Enthuware’s JWeb or any other questions. It really misleads you to somewhere else. Just READ THE BOOK!

Here is how I made an MVC simple java web application, when you see this you will get the idea about how good I am with J2EE. So you will know if you are on the same level with me.

Free online screen recorder

How to override jspInit() method

I made a video tutorial of how to override jspInit() method using screentoast.com. It looks really cool.

Screencasts and videos online

Cheating questions for SCWCD (1)

While preparing SCWCD, I got a list of hard questions that are easy to make mistakes.
1. Which of the following statements regarding action are correct?

  • It must have an ‘id’ attribute.
  • If ‘beanName’ attribute is present, ‘type’ must also be present.
  • It must have a ‘scope’ attribute.
  • If ‘class’ attribute is present, ‘type’ must also be present.

1,2 are correct.
Explanation:
Here are the rules:

  1. id is mandatory.
  2. scope is optional.
  3. The three attributes: class, type and beanName can occur only as one of the following four combination and at least one of these four combinations must be there in a useBaen tag:
  • a. class
  • b. type
  • c. class and type
  • d. beanName and type

Continue »