JAVA

You are currently browsing the archive for the JAVA category.

HashMap in JSTL

To use a HashMap and get the contained data by key in JSTL, we can use the following expression, provided that list is the user-defined HashMap and id is the user-defined key for the list:

${list[id]}

For a map, we should use the bracket [] to find the content by key. In JSTL, there is another similar expression:

${list.id}

This kind of expression cannot be used by HashMap, but it will be valid for a Javabean, having id as one of the attributes inside.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • Technorati
  • YahooMyWeb

SCJP Reference Summary

Thanks to messages from the classmates of AJAX Work Shop, I have gathered some very good references which can help me to better prepare my SCJP exam in the coming future.

Web Resources:

“Thinking in Java”. Although it’s not intended exactly for scjp students but there are many related topics discussed - http://forums.theajaxworkshop.com/viewtopic.php?t=148&highlight=

Chock-full of Java exams resources -
http://www.javaranch.com/

Dan Chisholm Certified Java Programmer Mock Exam -
http://www.danchisholm.net/

Books:

A Programmer’s Guide to Java Certification by Khalid A. Mughal / Rolf
W. Rasmussen
Sun Certified Programmer & Developer for Java 2 Study Guide (Exam
310-035 & 310-027) (Paperback) by Kathy Sierra, Bert Bates

Both of these books can be borrowed from Hong Kong Public Library.

My Choice:

For myself, I finally picked a Chinese book which I will enjoy reading Chinese technical book rather than an English one, which calls:

JAVA 認證 - SCJP 5.0 猛虎出閘 published by GOTOP from Taiwan

I bought this book since it contains many questions which I can focus on whether I know the SCJP level questions.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • Technorati
  • YahooMyWeb

To talk about internationalization, there is an interesting joke on its acronym “i18n”. You know why it is called i18n?

The answer is simple, just because there are 18 characters in between its first and last letter. :)

Last week, my colleague discussed with me on how to make the i18n possible since he was unable to do so. At that time, I couldn’t really answer on why, but I can say, it must be possible, as my old company did that.

After then, I did some researches, and finally solved the problem. It can be divided into several parts. (Mainly focus on how to show Simplified Chinese)

  1. Include Chinese directly in the JAVA class
  2. Show a Chinese String which is retrieved from database
  3. Send the Chinese String from the client to server side

The solutions or methods to each case are as follow:

1. Include Chinese directly in the JAVA class

This one is so simple. Just type the chinese in the JAVA class should be ok. If you’re not ok, it should be just your computer’s problem. Try reinstalling the JDK, it’s no matter to the stable release of JDK version.

2. Show a Chinese String which is retrieved from database

This is one is not difficult either. For the database retrieving part, just like other cases, use the very simple SQL statement is ok, since the JDBC connector will take the content as usual Strings. After retrieving the contents to the Action / Servlet, you should send the content to the JSP, in this step, you should set the character set to UTF-8, so that the string is encoded in Unicode(UTF-8) like the following:

response.setContentType(”text/html; charset=UTF-8″);

3. Send the Chinese String from the client to server side

For this one, there are more to do.
Firstly, as we’re using JBoss which Tomcat is embedded as the web container. We should do some tricks to let Tomcat knows the characters are chinese.

The first thing to do is to make use of the tomcatEncoding-1-0.jar, put this into the /WEB-INF/lib/ folder.
Then we need to add some elements to the /WEB-INF/web.xml, like the following:

<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.apache.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Actually, we just put a filter into Tomcat, so that for every request made to Tomcat, the parameters will pass through this filter and be encoded to UTF-8 Strings. As a resul, we can pass chinese characters into the servlet

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • Technorati
  • YahooMyWeb

Useful Links

Links for preparation on SCJP:

ExamsGuide.com - http://www.examsguide.com/scjp/freequestions.html

Someone’s experience - http://www.mihaiu.name/2004/sun_java_scjp_310_035/

TestKing - http://www.testking.com/

Another site - http://home.tiscali.nl/~bmc88/java/javacert/

China IT Lab - http://download.chinaitlab.com/

PassBible - http://www.passbible.com/testking.htm

Study Guide:

ePlanetLabs - http://eplanetlabs.com/scjp.html

SCJP Tiger Study Guide - http://java.boot.by/scjp-tiger/

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • Technorati
  • YahooMyWeb

« Older entries § Newer entries »

 

January 2009
S M T W T F S
« May    
 123
45678910
11121314151617
18192021222324
25262728293031

Categories